mirror of
https://github.com/openvswitch/ovs
synced 2025-09-03 15:55:19 +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:
13
lib/daemon.c
13
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);
|
||||
}
|
||||
|
||||
|
21
lib/daemon.h
21
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;
|
||||
|
||||
|
@@ -1,28 +1,27 @@
|
||||
.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@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.
|
||||
|
||||
.TP
|
||||
\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
|
||||
detaches. Otherwise, invoking \fB\*(PN\fR from a carelessly chosen
|
||||
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
|
||||
is not a good directory to use.
|
||||
.IP
|
||||
This option has no effect when neither \fB-D\fR nor \fB--detach\fR is
|
||||
specified.
|
||||
This option has no effect when \fB--detach\fR is not specified.
|
||||
|
@@ -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.
|
||||
\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-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.
|
||||
|
||||
.so lib/vlog.man
|
||||
.so lib/common.man
|
||||
|
@@ -282,7 +282,7 @@ parse_options(int argc, char *argv[])
|
||||
OPT_ACCEPT_VCONN = UCHAR_MAX + 1,
|
||||
OPT_EXIT_WITHOUT_BIND,
|
||||
OPT_EXIT_AFTER_BIND,
|
||||
OPT_NO_DETACH,
|
||||
OPT_NO_DETACH
|
||||
};
|
||||
static struct option long_options[] = {
|
||||
{"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},
|
||||
{"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 +328,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 +396,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);
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user