To keep control+C and other signals in the initiating session from killing
the monitor process, we need to put the monitor process into its own
session. However, until this point, we've only done that for the daemon
processes that the monitor started, which means that control+C would kill
the monitor but not the daemons that it launched.
I don't know of a benefit to putting the monitor and daemon processes in
different sessions, as opposed to one new session for both of them, so
this change does the latter.
daemonize_post_detach() is called from one additional context where we'd
want to be in a new session, the worker_start() function, but that function
is documented as to be called after daemonize_start(), in which case we
will (after this commit) already have called setsid(), so no additional
change is required there.
Bug #14280.
Reported-by: Gordon Good <ggood@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
/* Running in parent process. */
exit(0);
}
+
/* Running in daemon or monitor process. */
+ setsid();
}
if (monitor) {
daemonize_post_detach(void)
{
if (detach) {
- setsid();
if (chdir_) {
ignore(chdir("/"));
}
-# Copyright (c) 2010, 2011 Nicira, Inc.
+# Copyright (c) 2010, 2011, 2012 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
if _fork_and_wait_for_startup() > 0:
# Running in parent process.
sys.exit(0)
+
# Running in daemon or monitor process.
+ os.setsid()
if _monitor:
saved_daemonize_fd = _daemonize_fd
_fork_notify_startup(_daemonize_fd)
if _detach:
- os.setsid()
if _chdir:
os.chdir("/")
_close_standard_fds()