Skip to content
Snippets Groups Projects
Commit a35c8669 authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

Merge - deprecated daemon() call

Reimplementing the daemon() call for OSX targets and to support older
setups. Daemonization today is deprecated altogether since the init
system (systemd,rc,upstart,...) should take care of process
daemonization themselves. This just mutes the warning.
parents 714920a0 afeb9057
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,59 @@ static void init_signal_started(void)
#endif
}
static int make_daemon(int nochdir, int noclose)
{
int fd, ret;
switch (fork()) {
case -1:
/* Error */
return -1;
case 0:
/* Forked */
break;
default:
/* Exit the main process */
_exit(0);
}
if (setsid() == -1) {
return -1;
}
if (!nochdir) {
ret = chdir("/");
if (ret == -1)
return errno;
}
if (!noclose) {
ret = close(STDIN_FILENO);
ret += close(STDOUT_FILENO);
ret += close(STDERR_FILENO);
if (ret < 0) {
return errno;
}
fd = open("/dev/null", O_RDWR);
if (fd == -1) {
return errno;
}
if (dup2(fd, STDIN_FILENO) < 0) {
return errno;
}
if (dup2(fd, STDOUT_FILENO) < 0) {
return errno;
}
if (dup2(fd, STDERR_FILENO) < 0) {
return errno;
}
}
return 0;
}
/*! \brief PID file cleanup handler. */
static void pid_cleanup(char *pidfile)
{
......@@ -256,7 +309,7 @@ int main(int argc, char **argv)
/* Now check if we want to daemonize. */
if (daemonize) {
if (daemon(1, 0) != 0) {
if (make_daemon(1, 0) != 0) {
fprintf(stderr, "Daemonization failed, shutting down...\n");
return EXIT_FAILURE;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment