Skip to content

Commit

Permalink
add option to disable setsid
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed May 25, 2024
1 parent 935252f commit 58f425b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/daemon-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ VLOG_DEFINE_THIS_MODULE(daemon_unix);
bool detach; /* Was --detach specified? */
static bool detached; /* Have we already detached? */

bool no_setsid = false;

/* --pidfile: Name of pidfile (null if none). */
char *pidfile;

Expand Down Expand Up @@ -129,6 +131,12 @@ set_detach(void)
detach = true;
}

void
set_no_setsid(void)
{
no_setsid = true;
}

/* Sets up a following call to daemonize() to fork a supervisory process to
* monitor the daemon and restart it if it dies due to an error signal. */
void
Expand Down Expand Up @@ -465,7 +473,9 @@ daemonize_start(bool access_datapath)
}

/* Running in daemon or monitor process. */
setsid();
if (!no_setsid) {
setsid();
}
}

if (monitor) {
Expand Down Expand Up @@ -542,6 +552,8 @@ daemon_usage(void)
printf(
"\nDaemon options:\n"
" --detach run in background as daemon\n"
" --no-setsid do not create a session nor set the "
"process group ID\n"
" --monitor creates a process to monitor this daemon\n"
" --user=username[:group] changes the effective daemon user:group\n"
" --no-chdir do not chdir to '/'\n"
Expand Down
7 changes: 7 additions & 0 deletions lib/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#ifndef _WIN32
#define DAEMON_OPTION_ENUMS \
OPT_DETACH, \
OPT_NO_SETSID, \
OPT_NO_SELF_CONFINEMENT, \
OPT_NO_CHDIR, \
OPT_OVERWRITE_PIDFILE, \
Expand All @@ -48,6 +49,7 @@

#define DAEMON_LONG_OPTIONS \
{"detach", no_argument, NULL, OPT_DETACH}, \
{"no-setsid", no_argument, NULL, OPT_NO_SETSID}, \
{"no-self-confinement", no_argument, NULL, OPT_NO_SELF_CONFINEMENT}, \
{"no-chdir", no_argument, NULL, OPT_NO_CHDIR}, \
{"pidfile", optional_argument, NULL, OPT_PIDFILE}, \
Expand All @@ -60,6 +62,10 @@
set_detach(); \
break; \
\
case OPT_NO_SETSID: \
set_no_setsid(); \
break; \
\
case OPT_NO_SELF_CONFINEMENT: \
daemon_disable_self_confinement(); \
break; \
Expand Down Expand Up @@ -94,6 +100,7 @@
case OPT_USER_GROUP:

void set_detach(void);
void set_no_setsid(void);
void daemon_set_monitor(void);
void set_no_chdir(void);
void ignore_existing_pidfile(void);
Expand Down
4 changes: 4 additions & 0 deletions utilities/ovs-ctl.in
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ do_start_ovsdb () {
if test X"$SELF_CONFINEMENT" = Xno; then
set "$@" --no-self-confinement
fi
if test X"$SETSID" = Xno; then
set "$@" --no-setsid
fi
set "$@" -vconsole:emer -vsyslog:err -vfile:info
set "$@" --remote=punix:"$DB_SOCK"
set "$@" --private-key=db:Open_vSwitch,SSL,private_key
Expand Down Expand Up @@ -339,6 +342,7 @@ set_defaults () {
MLOCKALL=yes
SELF_CONFINEMENT=yes
MONITOR=yes
SETSID=yes
OVS_USER=
OVSDB_SERVER=yes
OVS_VSWITCHD=yes
Expand Down

0 comments on commit 58f425b

Please sign in to comment.