Skip to contentSkip to conversation

cleanup: Move write_pid() to where it is being used

PATCH In review David Sommerseth 2 participants 3 messages Jul 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cleanup: Move write_pid() to where it is being used

The write_pid() function is only used in openvpn.c, so no need to have that in the misc.[ch] mixed bag.

---
 src/openvpn/misc.c    | 21 ---------------------
 src/openvpn/misc.h    |  2 --
 src/openvpn/openvpn.c | 21 +++++++++++++++++++++
 3 files changed, 21 insertions(+), 23 deletions(-)
src/openvpn/misc.c +0 -21
index ae96aa69..8a76bba8 100644
@@ -142,27 +142,6 @@ run_up_down(const char *command,
     gc_free(&gc);
 }
 
-/* Write our PID to a file */
-void
-write_pid(const char *filename)
-{
-    if (filename)
-    {
-        unsigned int pid = 0;
-        FILE *fp = platform_fopen(filename, "w");
-        if (!fp)
-        {
-            msg(M_ERR, "Open error on pid file %s", filename);
-        }
-
-        pid = platform_getpid();
-        fprintf(fp, "%u\n", pid);
-        if (fclose(fp))
-        {
-            msg(M_ERR, "Close error on pid file %s", filename);
-        }
-    }
-}
 
 /*
  * Set standard file descriptors to /dev/null
src/openvpn/misc.h +0 -2
index 32b64e8b..734e679c 100644
@@ -68,8 +68,6 @@ void run_up_down(const char *command,
                  const char *script_type,
                  struct env_set *es);
 
-void write_pid(const char *filename);
-
 /* system flags */
 #define S_SCRIPT (1<<0)
 #define S_FATAL  (1<<1)
src/openvpn/openvpn.c +21 -0
index 08c09e6b..794de1a8 100644
@@ -47,6 +47,27 @@ process_signal_p2p(struct context *c)
     return process_signal(c);
 }
 
+/* Write our PID to a file */
+static void
+write_pid(const char *filename)
+{
+    if (filename)
+    {
+        unsigned int pid = 0;
+        FILE *fp = platform_fopen(filename, "w");
+        if (!fp)
+        {
+            msg(M_ERR, "Open error on pid file %s", filename);
+        }
+
+        pid = platform_getpid();
+        fprintf(fp, "%u\n", pid);
+        if (fclose(fp))
+        {
+            msg(M_ERR, "Close error on pid file %s", filename);
+        }
+    }
+}
 
 
 /**************************************************************************/
Signature · 1 line
2.11.0
#1 lore raw

Hi,

Quoted 78 lines · David Sommerseth

The write_pid() function is only used in openvpn.c, so no need to have that in the misc.[ch] mixed bag.

---
 src/openvpn/misc.c    | 21 ---------------------
 src/openvpn/misc.h    |  2 --
 src/openvpn/openvpn.c | 21 +++++++++++++++++++++
 3 files changed, 21 insertions(+), 23 deletions(-)
src/openvpn/misc.c +0 -21
index ae96aa69..8a76bba8 100644
@@ -142,27 +142,6 @@ run_up_down(const char *command,
     gc_free(&gc);
 }
 
-/* Write our PID to a file */
-void
-write_pid(const char *filename)
-{
-    if (filename)
-    {
-        unsigned int pid = 0;
-        FILE *fp = platform_fopen(filename, "w");
-        if (!fp)
-        {
-            msg(M_ERR, "Open error on pid file %s", filename);
-        }
-
-        pid = platform_getpid();
-        fprintf(fp, "%u\n", pid);
-        if (fclose(fp))
-        {
-            msg(M_ERR, "Close error on pid file %s", filename);
-        }
-    }
-}
 
 /*
  * Set standard file descriptors to /dev/null
src/openvpn/misc.h +0 -2
index 32b64e8b..734e679c 100644
@@ -68,8 +68,6 @@ void run_up_down(const char *command,
                  const char *script_type,
                  struct env_set *es);
 
-void write_pid(const char *filename);
-
 /* system flags */
 #define S_SCRIPT (1<<0)
 #define S_FATAL  (1<<1)
src/openvpn/openvpn.c +14 -0
index 08c09e6b..794de1a8 100644
@@ -47,6 +47,27 @@ process_signal_p2p(struct context *c)
     return process_signal(c);
 }
 
+/* Write our PID to a file */
+static void
+write_pid(const char *filename)
+{
+    if (filename)
+    {
+        unsigned int pid = 0;
+        FILE *fp = platform_fopen(filename, "w");
+        if (!fp)
+        {
+            msg(M_ERR, "Open error on pid file %s", filename);
+        }
+
+        pid = platform_getpid();

src/openvpn/openvpn.c process_signal_p2p(struct context *c) · line 73

Quoted 10 lines
src/openvpn/openvpn.c +7 -0
+        fprintf(fp, "%u\n", pid);
+        if (fclose(fp))
+        {
+            msg(M_ERR, "Close error on pid file %s", filename);
+        }
+    }
+}
 
 
 /**************************************************************************/

Looks good, but let's make the (new?) dependency of openvpn.c to platforum.h/c explicit by adding an #include "platform.h".

Trivial enough to do when applying, so ACK.

-Steffan

#2 lore raw
In reply to David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Your patch has been applied to the following branches

commit c5b12817c9aa3ae97fbdd2c2a9a9ab605087dff1 (master) commit cb438b513223744949e0958d9f14870880cfc407 (release/2.4)

Author: David Sommerseth
Date:   Tue Jul 25 16:57:18 2017 +0200
     cleanup: Move write_pid() to where it is being used

     Signed-off-by: David Sommerseth <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: David Sommerseth <[email protected]...>

- --
kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJZd2U/AAoJEIbPlEyWcf3yu/MP/jo74puMyZVUVTqtw/PlS7WA rrp5/x7hGPT634urKbqwZ60tvPCCn+uDs4lCy6XDZ5FTWgHDnpmNwaAOC8IZ5W1o HgBef2J8fiyloqGwE8C99OYAe04KdbCkQoxbKc1A6AWPXlP5wSd+vpGZtitM1HIa O4Pvj6mp0jf8+2JUj+nHebEfS8XcH9Tvv+xCivvPD4V4c3IoohYiTpO7whe88lGD oGr5fA3iK6X3xkkO5jrTTaP6qAnjKXqdB+3Ng83s1zKb01w3zquhXom46fBgiY/o QIn0MjRHiye01OLSrK0xo+ly0DGihTiAJpRc52+b83DcVSUB+nWbQr6xR/xw6xMg EK/paWg/mPvwFbUwUw74cMqThboWpJQtK6zlbCDqf7boOgEjdSCcMGMTeMxUAEYs fzBYPVAq/uxRlow02Ex/6z6QWv6YePRsFFr4AjXSCcvkHVJzCPuoKnJKmqvE115e +8Qv8kh7U/tXIzEd6nwkPwS5JqeJ9AaVom3Wx/Ithbc4dJIvW0CRCV6HNqqjeKOV jVvjDtQxYk05eRd0ASnCSA9MzrBwwfmpMVytNeVkoA4i13L+nFNHlV+1vsYfsaVP eBKULUuRHFd2dPLgS5mXpmhMadsCG/BNOZkZRFyJSqGFqSGuvBYiT2U+nKumrKtI GW46gViLXkoAWn5LEqTL
=gDou
-----END PGP SIGNATURE-----