[ovs-discuss] [PATCH 5/6] daemon: Remove short options from daemon library

Justin Pettit jpettit at nicira.com
Wed Aug 5 23:48:58 UTC 2009


The daemon library provides a few short options, but these then take
away their availability from programs that wish to use the library.
Since the daemon options are generally going to be called from a script
(which doesn't care how much typing is involved), we'll only provide
long options.
---
 lib/daemon.c                 |   13 +++++++------
 lib/daemon.h                 |   21 ++++++++++++---------
 lib/daemon.man               |   17 ++++++++---------
 utilities/ovs-discover.8.in  |   17 ++++++++---------
 utilities/ovs-discover.c     |   15 +++++++++------
 xenserver/etc_init.d_vswitch |    8 ++++----
 6 files changed, 48 insertions(+), 43 deletions(-)

diff --git a/lib/daemon.c b/lib/daemon.c
index a011d37..1e3f002 100644
--- a/lib/daemon.c
+++ b/lib/daemon.c
@@ -35,7 +35,7 @@ static bool detach;
 static char *pidfile;
 
 /* Create pidfile even if one already exists and is locked? */
-static bool force;
+static bool overwrite_pidfile;
 
 /* Should we chdir to "/". */
 static bool chdir_ = true;
@@ -85,7 +85,7 @@ set_no_chdir(void)
 void
 ignore_existing_pidfile(void)
 {
-    force = true;
+    overwrite_pidfile = true;
 }
 
 /* Sets up a following call to daemonize() to detach from the foreground
@@ -127,7 +127,7 @@ die_if_already_running(void)
 {
     pid_t pid = already_running();
     if (pid) {
-        if (!force) {
+        if (!overwrite_pidfile) {
             ovs_fatal(0, "%s: already running as pid %ld",
                       get_pidfile(), (long int) pid);
         } else {
@@ -239,10 +239,11 @@ daemon_usage(void)
 {
     printf(
         "\nDaemon options:\n"
-        "  -D, --detach            run in background as daemon\n"
+        "  --detach                run in background as daemon\n"
         "  --no-chdir              do not chdir to '/'\n"
-        "  -P, --pidfile[=FILE]    create pidfile (default: %s/%s.pid)\n"
-        "  -f, --force             with -P, start even if already running\n",
+        "  --pidfile[=FILE]        create pidfile (default: %s/%s.pid)\n"
+        "  --overwrite-pidfile     with --pidfile, start even if already "
+                                   "running\n",
         ovs_rundir, program_name);
 }
 
diff --git a/lib/daemon.h b/lib/daemon.h
index d62dd4f..d0c324c 100644
--- a/lib/daemon.h
+++ b/lib/daemon.h
@@ -22,17 +22,20 @@
 #include <sys/types.h>
 
 enum {
-    OPT_NO_CHDIR = UCHAR_MAX + 2048
+    OPT_DETACH = UCHAR_MAX + 2048,
+    OPT_NO_CHDIR,
+    OPT_OVERWRITE_PIDFILE,
+    OPT_PIDFILE,
 };
 
-#define DAEMON_LONG_OPTIONS                             \
-        {"detach",      no_argument, 0, 'D'},           \
-        {"no-chdir",    no_argument, 0, OPT_NO_CHDIR},  \
-        {"force",       no_argument, 0, 'f'},           \
-        {"pidfile",     optional_argument, 0, 'P'}
+#define DAEMON_LONG_OPTIONS                                          \
+        {"detach",            no_argument, 0, OPT_DETACH},           \
+        {"no-chdir",          no_argument, 0, OPT_NO_CHDIR},         \
+        {"pidfile",           optional_argument, 0, OPT_PIDFILE},    \
+        {"overwrite-pidfile", no_argument, 0, OPT_OVERWRITE_PIDFILE}
 
 #define DAEMON_OPTION_HANDLERS                  \
-        case 'D':                               \
+        case OPT_DETACH:                        \
             set_detach();                       \
             break;                              \
                                                 \
@@ -40,11 +43,11 @@ enum {
             set_no_chdir();                     \
             break;                              \
                                                 \
-        case 'P':                               \
+        case OPT_PIDFILE:                       \
             set_pidfile(optarg);                \
             break;                              \
                                                 \
-        case 'f':                               \
+        case OPT_OVERWRITE_PIDFILE:             \
             ignore_existing_pidfile();          \
             break;
 
diff --git a/lib/daemon.man b/lib/daemon.man
index 386977a..dcf111e 100644
--- a/lib/daemon.man
+++ b/lib/daemon.man
@@ -1,22 +1,21 @@
 .TP
-\fB-P\fR[\fIpidfile\fR], \fB--pidfile\fR[\fB=\fIpidfile\fR]
+\fB--pidfile\fR[\fB=\fIpidfile\fR]
 Causes a file (by default, \fB\*(PN.pid\fR) to be created indicating
 the PID of the running process.  If \fIpidfile\fR is not specified, or
 if it does not begin with \fB/\fR, then it is created in
 \fB at RUNDIR@\fR.
 
 .TP
-\fB-f\fR, \fB--force\fR
-By default, when \fB-P\fR or \fB--pidfile\fR is specified and the
-specified pidfile already exists and is locked by a running process,
-\fB\*(PN\fR refuses to start.  Specify \fB-f\fR or \fB--force\fR
-to cause it to instead overwrite the pidfile.
+\fB--overwrite-pidfile\fR
+By default, when \fB--pidfile\fR is specified and the specified pidfile 
+already exists and is locked by a running process, \fB\*(PN\fR refuses 
+to start.  Specify \fB--overwrite-pidfile\fR to cause it to instead 
+overwrite the pidfile.
 
-When \fB-P\fR or \fB--pidfile\fR is not specified, this option has no
-effect.
+When \fB--pidfile\fR is not specified, this option has no effect.
 
 .TP
-\fB-D\fR, \fB--detach\fR
+\fB--detach\fR
 Causes \fB\*(PN\fR to detach itself from the foreground session and
 run as a background process.
 
diff --git a/utilities/ovs-discover.8.in b/utilities/ovs-discover.8.in
index d38ce9e..e9685d9 100644
--- a/utilities/ovs-discover.8.in
+++ b/utilities/ovs-discover.8.in
@@ -74,7 +74,7 @@ This option is mutually exclusive with \fB--exit-without-bind\fR and
 \fB--exit-after-bind\fR.
 
 .TP
-\fB-P\fR[\fIpidfile\fR], \fB--pidfile\fR[\fB=\fIpidfile\fR]
+\fB--pidfile\fR[\fB=\fIpidfile\fR]
 Causes a file (by default, \fBovs\-discover.pid\fR) to be created indicating
 the PID of the running process.  If \fIpidfile\fR is not specified, or
 if it does not begin with \fB/\fR, then it is created in
@@ -85,14 +85,13 @@ this this option has no effect when one of \fB--exit-without-bind\fR,
 \fB--exit-after-bind\fR, or \fB--no-detach\fR is also given.
 
 .TP
-\fB-f\fR, \fB--force\fR
-By default, when \fB-P\fR or \fB--pidfile\fR is specified and the
-specified pidfile already exists and is locked by a running process,
-\fBcontroller\fR refuses to start.  Specify \fB-f\fR or \fB--force\fR
-to cause it to instead overwrite the pidfile.
-
-When \fB-P\fR or \fB--pidfile\fR is not specified, this option has no
-effect.
+\fB--overwrite-pidfile\fR
+By default, when \fB--pidfile\fR is specified and the specified pidfile 
+already exists and is locked by a running process, \fBcontroller\fR refuses 
+to start.  Specify \fB--overwrite-pidfile\fR to cause it to instead 
+overwrite the pidfile.
+
+When \fB--pidfile\fR is not specified, this option has no effect.
 
 .so lib/vlog.man
 .so lib/common.man
diff --git a/utilities/ovs-discover.c b/utilities/ovs-discover.c
index 0474105..841b6b6 100644
--- a/utilities/ovs-discover.c
+++ b/utilities/ovs-discover.c
@@ -283,6 +283,8 @@ parse_options(int argc, char *argv[])
         OPT_EXIT_WITHOUT_BIND,
         OPT_EXIT_AFTER_BIND,
         OPT_NO_DETACH,
+        OPT_PIDFILE,
+        OPT_OVERWRITE_PIDFILE
     };
     static struct option long_options[] = {
         {"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN},
@@ -290,8 +292,8 @@ parse_options(int argc, char *argv[])
         {"exit-after-bind", no_argument, 0, OPT_EXIT_AFTER_BIND},
         {"no-detach",   no_argument, 0, OPT_NO_DETACH},
         {"timeout",     required_argument, 0, 't'},
-        {"pidfile",     optional_argument, 0, 'P'},
-        {"force",       no_argument, 0, 'f'},
+        {"pidfile",     optional_argument, 0, OPT_PIDFILE},
+        {"overwrite-pidfile", no_argument, 0, OPT_OVERWRITE_PIDFILE},
         {"verbose",     optional_argument, 0, 'v'},
         {"help",        no_argument, 0, 'h'},
         {"version",     no_argument, 0, 'V'},
@@ -328,11 +330,11 @@ parse_options(int argc, char *argv[])
             detach_after_bind = false;
             break;
 
-        case 'P':
+        case OPT_PIDFILE:
             set_pidfile(optarg);
             break;
 
-        case 'f':
+        case OPT_OVERWRITE_PIDFILE:
             ignore_existing_pidfile();
             break;
 
@@ -396,8 +398,9 @@ usage(void)
     vlog_usage();
     printf("\nOther options:\n"
            "  -t, --timeout=SECS      give up discovery after SECS seconds\n"
-           "  -P, --pidfile[=FILE]    create pidfile (default: %s/%s.pid)\n"
-           "  -f, --force             with -P, start even if already running\n"
+           "  --pidfile[=FILE]        create pidfile (default: %s/%s.pid)\n"
+           "  --overwrite-pidfile     with --pidfile, start even if already "
+                                      "running\n"
            "  -h, --help              display this help message\n"
            "  -V, --version           display version information\n",
            ovs_rundir, program_name);
diff --git a/xenserver/etc_init.d_vswitch b/xenserver/etc_init.d_vswitch
index eba4baf..3927223 100755
--- a/xenserver/etc_init.d_vswitch
+++ b/xenserver/etc_init.d_vswitch
@@ -152,9 +152,9 @@ function start_vswitchd {
     if [ "$daemonize" != "y" ]; then
         # Start in background and force a "success" message
         action "Starting ovs-vswitchd ($strace_opt$valgrind_opt)" true
-        (nice -n "$VSWITCHD_PRIORITY" $strace_opt $valgrind_opt "$vswitchd" -P"$VSWITCHD_PIDFILE" -D $fake_proc_net_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF") &
+        (nice -n "$VSWITCHD_PRIORITY" $strace_opt $valgrind_opt "$vswitchd" --pidfile="$VSWITCHD_PIDFILE" --detach $fake_proc_net_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF") &
     else
-        action "Starting ovs-vswitchd" nice -n "$VSWITCHD_PRIORITY" "$vswitchd" -P"$VSWITCHD_PIDFILE" -D $fake_proc_net_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF"
+        action "Starting ovs-vswitchd" nice -n "$VSWITCHD_PRIORITY" "$vswitchd" --pidfile="$VSWITCHD_PIDFILE" --detach $fake_proc_net_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF"
     fi
 }
 
@@ -191,9 +191,9 @@ function start_brcompatd {
     if [ "$daemonize" != "y" ]; then
         # Start in background and force a "success" message
         action "Starting ovs-brcompatd ($strace_opt$valgrind_opt)" true
-        (nice -n "$VSWITCHD_PRIORITY" $strace_opt $valgrind_opt "$brcompatd" --appctl-command="$appctl_cmd" -P$BRCOMPATD_PIDFILE -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF") &
+        (nice -n "$VSWITCHD_PRIORITY" $strace_opt $valgrind_opt "$brcompatd" --appctl-command="$appctl_cmd" --pidfile=$BRCOMPATD_PIDFILE -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF") &
     else
-        action "Starting ovs-brcompatd" nice -n "$BRCOMPATD_PRIORITY" $strace_opt $valgrind_opt "$brcompatd" --appctl-command="$appctl_cmd" -P$BRCOMPATD_PIDFILE -D -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF"
+        action "Starting ovs-brcompatd" nice -n "$BRCOMPATD_PRIORITY" $strace_opt $valgrind_opt "$brcompatd" --appctl-command="$appctl_cmd" --pidfile=$BRCOMPATD_PIDFILE --detach -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF"
     fi
 }
 
-- 
1.5.5





More information about the discuss mailing list