Log failure and exit if fork() or setsid() fails.
Leave the logic in the non-setsid() code as it is. This is probably
meant to fall through on failure of either opening /dev/tty or
ioctl(). Documentation for the ioctl() failure case is far from
clear.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Aug 17 11:48:32 CEST 2017 on sn-devel-144
pid_t newpid;
if (do_fork) {
newpid = fork();
+ if (newpid == -1) {
+ exit_daemon("Fork failed", errno);
+ }
if (newpid) {
#if defined(HAVE_LIBSYSTEMD_DAEMON) || defined(HAVE_LIBSYSTEMD)
sd_notifyf(0,
/* detach from the terminal */
#ifdef HAVE_SETSID
- if (!no_session) setsid();
+ if (!no_session) {
+ int ret = setsid();
+ if (ret == -1) {
+ exit_daemon("Failed to create session", errno);
+ }
+ }
#elif defined(TIOCNOTTY)
if (!no_session) {
int i = open("/dev/tty", O_RDWR, 0);