Skip to content

Commit

Permalink
Cleans up os_daemon() in Windows case.
Browse files Browse the repository at this point in the history
This provides an always-failing os_daemon() for platforms (e.g.,
Windows) that can't provide a real daemon() call.  This is more
consistent than simply omitting the function.

It also bases the condition on the lack of fork(), rather than the
presence of winsock2.h.

TESTED:
Ran "scons build-all check" on OSX, Linux, FreeBSD, OpenBSD, and
NetBSD.  Verified that HAVE_FORK is set in all cases.
  • Loading branch information
fhgwright committed Feb 20, 2017
1 parent bb66fc3 commit 9d126a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ else:

# check function after libraries, because some function require libraries
# for example clock_gettime() require librt on Linux glibc < 2.17
for f in ("daemon", "strlcpy", "strlcat", "clock_gettime", "strptime", "gmtime_r", "inet_ntop", "fcntl"):
for f in ("daemon", "strlcpy", "strlcat", "clock_gettime", "strptime", "gmtime_r", "inet_ntop", "fcntl", "fork"):
if config.CheckFunc(f):
confdefs.append("#define HAVE_%s 1\n" % f.upper())
else:
Expand Down
18 changes: 15 additions & 3 deletions os_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ int clock_gettime(clockid_t clk_id, struct timespec *ts)
/* End of clock_gettime section */

#ifndef HAVE_DAEMON
#ifndef HAVE_WINSOCK2_H
/* No daemon() provided for Windows as not currently needed */
/* Simulate Linux/BSD daemon() on platforms that don't have it */

#ifdef HAVE_FORK

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -91,7 +91,19 @@ int os_daemon(int nochdir, int noclose)
/* coverity[leaked_handle] Intentional handle duplication */
return 0;
}
#endif /* HAVE_WINSOCK2_H */
#else /* !HAVE_FORK */

#include <errno.h>

int os_daemon(int nochdir, int noclose)
{
(void) nochdir; (void) noclose;
errno = EINVAL;
return -1;
}

#endif /* !HAVE_FORK */

#else /* HAVE_DAEMON */

#ifdef __linux__
Expand Down

0 comments on commit 9d126a4

Please sign in to comment.