From 6f45a2bf852a2267c9291d52b3a474427b3d570f Mon Sep 17 00:00:00 2001 From: Tim Wickberg <tim@schedmd.com> Date: Sun, 21 May 2017 23:27:56 -0600 Subject: [PATCH] Remove local refinition of daemon(). While not POSIX compliant, BSD and Linux platforms have shipped this function for a long time, and slurmctld/slurmdbd/slurmd have actually been using the version from libc instead of this local redefinition. --- src/common/daemonize.c | 58 ------------------------------------------ src/common/daemonize.h | 9 ------- 2 files changed, 67 deletions(-) diff --git a/src/common/daemonize.c b/src/common/daemonize.c index dc6379ac9a3..9e933ade9a0 100644 --- a/src/common/daemonize.c +++ b/src/common/daemonize.c @@ -50,64 +50,6 @@ #include "src/common/macros.h" #include "src/common/xassert.h" -/* detach and go into background. - * caller is responsible for umasks - * - * if nochdir == 0, will do a chdir to / - * if noclose == 0, will close all FDs - */ -int -daemon(int nochdir, int noclose) -{ - switch (fork()) { - case 0 : break; /* child */ - case -1 : return -1; - default : _exit(0); /* exit parent */ - } - - if (setsid() < 0) - return -1; - - switch (fork()) { - case 0 : break; /* child */ - case -1: return -1; - default: _exit(0); /* exit parent */ - } - - if (!nochdir && chdir("/") < 0) { - error("chdir(/): %m"); - return -1; - } - - /* Close all file descriptors if requested - */ - if (!noclose) { - closeall(0); - if (open("/dev/null", O_RDWR) != 0) - error("Unable to open /dev/null on stdin: %m"); - dup2(0, STDOUT_FILENO); - dup2(0, STDERR_FILENO); - } else { - /* - * Otherwise, dup stdin, stdout, and stderr onto /dev/null - */ - int devnull = open("/dev/null", O_RDWR); - if (devnull < 0) - error("Unable to open /dev/null: %m"); - if (dup2(devnull, STDIN_FILENO) < 0) - error("Unable to dup /dev/null onto stdin: %m"); - if (dup2(devnull, STDOUT_FILENO) < 0) - error("Unable to dup /dev/null onto stdout: %m"); - if (dup2(devnull, STDERR_FILENO) < 0) - error("Unable to dup /dev/null onto stderr: %m"); - if (close(devnull) < 0) - error("Unable to close /dev/null: %m"); - } - - return 0; - -} - /* * Read and return pid stored in pidfile. * Returns 0 if file doesn't exist or pid cannot be read. diff --git a/src/common/daemonize.h b/src/common/daemonize.h index d7b4cc4a9a6..93dd8813c31 100644 --- a/src/common/daemonize.h +++ b/src/common/daemonize.h @@ -36,18 +36,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. \*****************************************************************************/ - #ifndef _HAVE_DAEMONIZE_H #define _HAVE_DAEMONIZE_H -/* fork process into background and inherit new session - * if nochdir is 0, performs a chdir("/") - * if noclose is 0, closes all fds and dups stdout/err of daemon onto /dev/null - * - * returns -1 on error. - */ -extern int daemon(int nochdir, int noclose); - /* Write pid into file pidfile if uid is not 0 change the owner of the * pidfile to that user. */ -- GitLab