2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-04 00:05:15 +00:00

daemon: Remove short options from daemon library

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.
This commit is contained in:
Justin Pettit
2009-08-05 14:20:24 -07:00
parent 8093d640ac
commit e7bd7d78b1
6 changed files with 48 additions and 46 deletions

View File

@@ -35,7 +35,7 @@ static bool detach;
static char *pidfile; static char *pidfile;
/* Create pidfile even if one already exists and is locked? */ /* Create pidfile even if one already exists and is locked? */
static bool force; static bool overwrite_pidfile;
/* Should we chdir to "/". */ /* Should we chdir to "/". */
static bool chdir_ = true; static bool chdir_ = true;
@@ -85,7 +85,7 @@ set_no_chdir(void)
void void
ignore_existing_pidfile(void) ignore_existing_pidfile(void)
{ {
force = true; overwrite_pidfile = true;
} }
/* Sets up a following call to daemonize() to detach from the foreground /* 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(); pid_t pid = already_running();
if (pid) { if (pid) {
if (!force) { if (!overwrite_pidfile) {
ovs_fatal(0, "%s: already running as pid %ld", ovs_fatal(0, "%s: already running as pid %ld",
get_pidfile(), (long int) pid); get_pidfile(), (long int) pid);
} else { } else {
@@ -239,10 +239,11 @@ daemon_usage(void)
{ {
printf( printf(
"\nDaemon options:\n" "\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" " --no-chdir do not chdir to '/'\n"
" -P, --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n" " --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n"
" -f, --force with -P, start even if already running\n", " --overwrite-pidfile with --pidfile, start even if already "
"running\n",
ovs_rundir, program_name); ovs_rundir, program_name);
} }

View File

@@ -22,17 +22,20 @@
#include <sys/types.h> #include <sys/types.h>
enum { enum {
OPT_NO_CHDIR = UCHAR_MAX + 2048 OPT_DETACH = UCHAR_MAX + 2048,
OPT_NO_CHDIR,
OPT_OVERWRITE_PIDFILE,
OPT_PIDFILE,
}; };
#define DAEMON_LONG_OPTIONS \ #define DAEMON_LONG_OPTIONS \
{"detach", no_argument, 0, 'D'}, \ {"detach", no_argument, 0, OPT_DETACH}, \
{"no-chdir", no_argument, 0, OPT_NO_CHDIR}, \ {"no-chdir", no_argument, 0, OPT_NO_CHDIR}, \
{"force", no_argument, 0, 'f'}, \ {"pidfile", optional_argument, 0, OPT_PIDFILE}, \
{"pidfile", optional_argument, 0, 'P'} {"overwrite-pidfile", no_argument, 0, OPT_OVERWRITE_PIDFILE}
#define DAEMON_OPTION_HANDLERS \ #define DAEMON_OPTION_HANDLERS \
case 'D': \ case OPT_DETACH: \
set_detach(); \ set_detach(); \
break; \ break; \
\ \
@@ -40,11 +43,11 @@ enum {
set_no_chdir(); \ set_no_chdir(); \
break; \ break; \
\ \
case 'P': \ case OPT_PIDFILE: \
set_pidfile(optarg); \ set_pidfile(optarg); \
break; \ break; \
\ \
case 'f': \ case OPT_OVERWRITE_PIDFILE: \
ignore_existing_pidfile(); \ ignore_existing_pidfile(); \
break; break;

View File

@@ -1,28 +1,27 @@
.TP .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 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 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 if it does not begin with \fB/\fR, then it is created in
\fB@RUNDIR@\fR. \fB@RUNDIR@\fR.
.TP .TP
\fB-f\fR, \fB--force\fR \fB--overwrite-pidfile\fR
By default, when \fB-P\fR or \fB--pidfile\fR is specified and the By default, when \fB--pidfile\fR is specified and the specified pidfile
specified pidfile already exists and is locked by a running process, already exists and is locked by a running process, \fB\*(PN\fR refuses
\fB\*(PN\fR refuses to start. Specify \fB-f\fR or \fB--force\fR to start. Specify \fB--overwrite-pidfile\fR to cause it to instead
to cause it to instead overwrite the pidfile. overwrite the pidfile.
When \fB-P\fR or \fB--pidfile\fR is not specified, this option has no When \fB--pidfile\fR is not specified, this option has no effect.
effect.
.TP .TP
\fB-D\fR, \fB--detach\fR \fB--detach\fR
Causes \fB\*(PN\fR to detach itself from the foreground session and Causes \fB\*(PN\fR to detach itself from the foreground session and
run as a background process. run as a background process.
.TP .TP
\fB--no-chdir\fR \fB--no-chdir\fR
By default, when \fB-D\fR or \fB--detach\fR is specified, \fB\*(PN\fR By default, when \fB--detach\fR is specified, \fB\*(PN\fR
changes its current working directory to the root directory after it changes its current working directory to the root directory after it
detaches. Otherwise, invoking \fB\*(PN\fR from a carelessly chosen detaches. Otherwise, invoking \fB\*(PN\fR from a carelessly chosen
directory would prevent the administrator from unmounting the file directory would prevent the administrator from unmounting the file
@@ -34,5 +33,4 @@ useful for collecting core files, since it is common behavior to write
core dumps into the current working directory and the root directory core dumps into the current working directory and the root directory
is not a good directory to use. is not a good directory to use.
.IP .IP
This option has no effect when neither \fB-D\fR nor \fB--detach\fR is This option has no effect when \fB--detach\fR is not specified.
specified.

View File

@@ -74,7 +74,7 @@ This option is mutually exclusive with \fB--exit-without-bind\fR and
\fB--exit-after-bind\fR. \fB--exit-after-bind\fR.
.TP .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 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 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 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. \fB--exit-after-bind\fR, or \fB--no-detach\fR is also given.
.TP .TP
\fB-f\fR, \fB--force\fR \fB--overwrite-pidfile\fR
By default, when \fB-P\fR or \fB--pidfile\fR is specified and the By default, when \fB--pidfile\fR is specified and the specified pidfile
specified pidfile already exists and is locked by a running process, already exists and is locked by a running process, \fBcontroller\fR refuses
\fBcontroller\fR refuses to start. Specify \fB-f\fR or \fB--force\fR to start. Specify \fB--overwrite-pidfile\fR to cause it to instead
to cause it to instead overwrite the pidfile. overwrite the pidfile.
When \fB-P\fR or \fB--pidfile\fR is not specified, this option has no When \fB--pidfile\fR is not specified, this option has no effect.
effect.
.so lib/vlog.man .so lib/vlog.man
.so lib/common.man .so lib/common.man

View File

@@ -282,7 +282,7 @@ parse_options(int argc, char *argv[])
OPT_ACCEPT_VCONN = UCHAR_MAX + 1, OPT_ACCEPT_VCONN = UCHAR_MAX + 1,
OPT_EXIT_WITHOUT_BIND, OPT_EXIT_WITHOUT_BIND,
OPT_EXIT_AFTER_BIND, OPT_EXIT_AFTER_BIND,
OPT_NO_DETACH, OPT_NO_DETACH
}; };
static struct option long_options[] = { static struct option long_options[] = {
{"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN}, {"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN},
@@ -290,8 +290,8 @@ parse_options(int argc, char *argv[])
{"exit-after-bind", no_argument, 0, OPT_EXIT_AFTER_BIND}, {"exit-after-bind", no_argument, 0, OPT_EXIT_AFTER_BIND},
{"no-detach", no_argument, 0, OPT_NO_DETACH}, {"no-detach", no_argument, 0, OPT_NO_DETACH},
{"timeout", required_argument, 0, 't'}, {"timeout", required_argument, 0, 't'},
{"pidfile", optional_argument, 0, 'P'}, {"pidfile", optional_argument, 0, OPT_PIDFILE},
{"force", no_argument, 0, 'f'}, {"overwrite-pidfile", no_argument, 0, OPT_OVERWRITE_PIDFILE},
{"verbose", optional_argument, 0, 'v'}, {"verbose", optional_argument, 0, 'v'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'}, {"version", no_argument, 0, 'V'},
@@ -328,11 +328,11 @@ parse_options(int argc, char *argv[])
detach_after_bind = false; detach_after_bind = false;
break; break;
case 'P': case OPT_PIDFILE:
set_pidfile(optarg); set_pidfile(optarg);
break; break;
case 'f': case OPT_OVERWRITE_PIDFILE:
ignore_existing_pidfile(); ignore_existing_pidfile();
break; break;
@@ -396,8 +396,9 @@ usage(void)
vlog_usage(); vlog_usage();
printf("\nOther options:\n" printf("\nOther options:\n"
" -t, --timeout=SECS give up discovery after SECS seconds\n" " -t, --timeout=SECS give up discovery after SECS seconds\n"
" -P, --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n" " --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n"
" -f, --force with -P, start even if already running\n" " --overwrite-pidfile with --pidfile, start even if already "
"running\n"
" -h, --help display this help message\n" " -h, --help display this help message\n"
" -V, --version display version information\n", " -V, --version display version information\n",
ovs_rundir, program_name); ovs_rundir, program_name);

View File

@@ -152,9 +152,9 @@ function start_vswitchd {
if [ "$daemonize" != "y" ]; then if [ "$daemonize" != "y" ]; then
# Start in background and force a "success" message # Start in background and force a "success" message
action "Starting ovs-vswitchd ($strace_opt$valgrind_opt)" true 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 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 fi
} }
@@ -191,9 +191,9 @@ function start_brcompatd {
if [ "$daemonize" != "y" ]; then if [ "$daemonize" != "y" ]; then
# Start in background and force a "success" message # Start in background and force a "success" message
action "Starting ovs-brcompatd ($strace_opt$valgrind_opt)" true 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 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 fi
} }