[PATCH 1/3] PATCH FLX: Add command line option for specifying the pid file

Exceliance (author: D. Ducolombier) contact at exceliance.fr
Wed Aug 28 14:57:14 CEST 2013


---
 sysdep/unix/main.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index bd80ba2..c0b2b22 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -548,16 +548,17 @@ signal_init(void)
  *	Parsing of command-line arguments
  */
 
-static char *opt_list = "c:dD:ps:u:g:";
+static char *opt_list = "c:dD:ps:u:g:P:";
 static int parse_and_exit;
 char *bird_name;
 static char *use_user;
 static char *use_group;
+static char *pid_file;
 
 static void
 usage(void)
 {
-  fprintf(stderr, "Usage: %s [-c <config-file>] [-d] [-D <debug-file>] [-p] [-s <control-socket>] [-u <user>] [-g <group>]\n", bird_name);
+  fprintf(stderr, "Usage: %s [-c <config-file>] [-d] [-D <debug-file>] [-p] [-s <control-socket>] [-u <user>] [-g <group>] [-P <pid-file>]\n", bird_name);
   exit(1);
 }
 
@@ -621,6 +622,28 @@ get_gid(const char *s)
   return gr->gr_gid;
 }
 
+static inline void
+set_pid(const char *s)
+{
+  int fd;
+  char pid[6];
+
+  if (!s)
+    return;
+
+  memset(pid, 0, sizeof(pid));
+
+  if((fd=open(s, O_WRONLY|O_CREAT, 0664)) == -1)
+    die("Cannot open pid file '%s'", s);
+
+  snprintf(pid, sizeof(pid), "%u", getpid());
+
+  if(write(fd, pid, sizeof(pid)) == -1)
+    die("Cannot write pid file '%s'", s);
+
+  return;
+}
+
 static void
 parse_args(int argc, char **argv)
 {
@@ -662,6 +685,9 @@ parse_args(int argc, char **argv)
       case 'g':
 	use_group = optarg;
 	break;
+      case 'P':
+	pid_file = optarg;
+	break;
       default:
 	usage();
       }
@@ -733,6 +759,7 @@ main(int argc, char **argv)
       dup2(0, 2);
     }
 
+  set_pid(pid_file);
   signal_init();
 
 #ifdef LOCAL_DEBUG
-- 
1.8.1.1


--Multipart=_Tue__24_Sep_2013_16_35_48_+0200_AMU0Imo+Flc+Ayzu
Content-Type: text/x-diff;
 name="0003-FEAT-Add-protocol-volatile.patch"
Content-Disposition: attachment;
 filename="0003-FEAT-Add-protocol-volatile.patch"
Content-Transfer-Encoding: 7bit



More information about the Bird-users mailing list