summaryrefslogtreecommitdiff
path: root/os_compat.c
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2019-03-21 19:13:14 -0700
committerFred Wright <fw@fwright.net>2019-03-21 20:04:46 -0700
commit3d1b7493c58f80a93b9bbec33717fd3055841ae1 (patch)
tree66d3c5d56c9230c5b7b9637f2d10c99e60b4da8f /os_compat.c
parentd7a1c8986331dc934af319249d32dfc8a0b024be (diff)
downloadgpsd-3d1b7493c58f80a93b9bbec33717fd3055841ae1.tar.gz
os_compat: OSX daemon() warning fix.
OSX considers the daemon() call deprecated. This is mainly because real OSX daemons are expected to run as launchd children, but since some programs here daemonize for convenience, and since self-daemonization is sometimes useful for testing, we can't really get rid of it. Previous work consolidated daemon() calls into os_compat, reducing the number of warnings, and this change gets rid of them altogether. There doesn't seem to be any easy way to avoid the warnings except by avoiding the normal declaration of daemon(), which is what we do here by duplicating it locally. If daemon() ever actually disappears, it could be reintroduced via the usual double-fork approach. TESTED: Ran "build-all check" as well as testing daemonization on a Mac Pro 10.9 and 10.14, MacBook Pro 10.9, PowerBook 10.5, and VMs for OSX 10.5-10.13, Ubuntu 14.04, CentOS 7, Fedora 25, FreeBSD 10.3, OpenBSD 5.6 (64- and 32-bit), and NetBSD 6.1.5.
Diffstat (limited to 'os_compat.c')
-rw-r--r--os_compat.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/os_compat.c b/os_compat.c
index b6531872..bf204158 100644
--- a/os_compat.c
+++ b/os_compat.c
@@ -113,11 +113,36 @@ int os_daemon(int nochdir, int noclose)
#define _DEFAULT_SOURCE
#include <unistd.h>
-#else /* !__linux__ */
+#elif defined(__APPLE__) /* !__linux__ */
+
+/*
+ * Avoid the OSX deprecation warning.
+ *
+ * Note that on OSX, real daemons like gpsd should run via launchd rather than
+ * self-daemonizing, but we use daemon() for other tools as well.
+ *
+ * There doesn't seem to be an easy way to avoid the warning other than by
+ * providing our own declaration to override the deprecation-flagged version.
+ * Fortunately, the function signature is pretty well frozen at this point.
+ *
+ * Until we fix the kludge where all this code has to be additionally compiled
+ * as C++ for the Qt library, we need this to be compilable as C++ as well.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int daemon(int nochdir, int noclose);
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* !__linux__ && !__APPLE__ */
#include <stdlib.h>
-#endif /* !__linux__ */
+#endif /* !__linux__ && !__APPLE__ */
int os_daemon(int nochdir, int noclose)
{