summaryrefslogtreecommitdiff
path: root/os_compat.c
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2017-01-22 01:44:19 -0800
committerFred Wright <fw@fwright.net>2017-01-22 14:02:55 -0800
commit2cb17f91607bdfd9cd7ad80f7232db8b1bd23d34 (patch)
tree452241687896ffdf45d2a002478bf970d67ec7a0 /os_compat.c
parentcb1403d842a2fdbe6109eaf48acb7a494f30784d (diff)
downloadgpsd-2cb17f91607bdfd9cd7ad80f7232db8b1bd23d34.tar.gz
Centralizes daemon() calls.
This defines a new function os_daemon() (in os_compat.c), which is either the old replacement daemon() renamed, or a wrapper around the actual daemon() call. This allows any issues related to daemon() (which exist on some platforms) to be dealt with in one place. No such changes are present yet, so platforms giving warnings for the use of daemon() continue to do so, but now only in the compilation of os_compat.c. Unfortunately, the current build procedure typically compiles os_compat.c multiple times, so the warnings still appear multiple times. TESTED: Ran "scons build-all check" on OSX 10.9, OSX 10.12, Ubuntu 14, and FreeBSD 10.3.
Diffstat (limited to 'os_compat.c')
-rw-r--r--os_compat.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/os_compat.c b/os_compat.c
index 4ffefb08..b110f4ba 100644
--- a/os_compat.c
+++ b/os_compat.c
@@ -62,7 +62,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *ts)
#endif
#endif
-int daemon(int nochdir, int noclose)
+int os_daemon(int nochdir, int noclose)
/* compatible with the daemon(3) found on Linuxes and BSDs */
{
int fd;
@@ -91,6 +91,26 @@ int daemon(int nochdir, int noclose)
return 0;
}
+#else /* HAVE_DAEMON */
+
+#ifdef __linux__
+
+/* daemon() needs _DEFAULT_SOURCE */
+#undef _DEFAULT_SOURCE
+#define _DEFAULT_SOURCE
+#include <unistd.h>
+
+#else /* !__linux__ */
+
+#include <stdlib.h>
+
+#endif /* !__linux__ */
+
+int os_daemon(int nochdir, int noclose)
+{
+ return daemon(nochdir, noclose);
+}
+
#endif /* HAVE_DAEMON */
/* End of daemon section */
@@ -175,7 +195,7 @@ size_t strlcat(char *dst, const char *src, size_t siz)
return (dlen + (s - src)); /* count does not include NUL */
}
#endif /* __UNUSED__ */
-#endif /* HAVE_STRLCAT */
+#endif /* !HAVE_STRLCAT */
#ifndef HAVE_STRLCPY
@@ -242,6 +262,6 @@ size_t strlcpy(char *dst, const char *src, size_t siz)
return ((size_t) (s - src - 1)); /* count does not include NUL */
}
#endif /* __UNUSED__ */
-#endif /* HAVE_STRLCPY */
+#endif /* !HAVE_STRLCPY */
/* End of strlcat()/strlcpy() section */