[Openvpn-devel] Ignore deprecation warning for daemon on macOS

Message ID 20201005091805.17260-1-arne@rfc2549.org
State Accepted
Headers show
Series [Openvpn-devel] Ignore deprecation warning for daemon on macOS | expand

Commit Message

Arne Schwabe Oct. 4, 2020, 10:18 p.m. UTC
macOS warns that we should posix_spawn instead. However posix_spawn
would require a major redesign of code to daemonise or drop the --daemon
feature on macOS. Ignore the clang warning in order to allow -Werror
compile on macOS.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/init.c                | 8 ++++++++
 src/plugins/down-root/down-root.c | 7 +++++++
 2 files changed, 15 insertions(+)

Comments

Gert Doering Oct. 11, 2020, 5:02 a.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

"unavoidable warnings are less useful than no warnings at all" -
so as a temporary measure, this makes sense.  Longterm, one could
see whether a "platform_daemon()" call makes sense...  

(From how I read the posix_spawn(3) manpage, it latter is more intended 
to replace fork()/exec() combos... not sure how that would help with
daemonizing [controlling tty and that]... daemon(3) suggests that Apple 
does not want people to start daemons by hand at all, using launchd(8)
instead...  and I agree that *that* would need a totally different
approach to "start openvpn")

Tested on Mojave: fixes the warnings in init.c and down-root.c.

Your patch has been applied to the master branch.

commit a480eaae1d32a6c3970911a561a64c1019944f92
Author: Arne Schwabe
Date:   Mon Oct 5 11:18:05 2020 +0200

     Ignore deprecation warning for daemon on macOS

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20201005091805.17260-1-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21171.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 31ecadcc..61d9cd75 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -1237,10 +1237,18 @@  possibly_become_daemon(const struct options *options)
     {
         ASSERT(!options->inetd);
         /* Don't chdir immediately, but the end of the init sequence, if needed */
+
+#if defined(__APPLE__) && defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
         if (daemon(1, options->log) < 0)
         {
             msg(M_ERR, "daemon() failed or unsupported");
         }
+#if defined(__APPLE__) && defined(__clang__)
+#pragma clang diagnostic pop
+#endif
         restore_signal_state();
         if (options->log)
         {
diff --git a/src/plugins/down-root/down-root.c b/src/plugins/down-root/down-root.c
index c5e5023e..da445c61 100644
--- a/src/plugins/down-root/down-root.c
+++ b/src/plugins/down-root/down-root.c
@@ -173,10 +173,17 @@  daemonize(const char *envp[])
         {
             fd = dup(2);
         }
+#if defined(__APPLE__) && defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
         if (daemon(0, 0) < 0)
         {
             warn("DOWN-ROOT: daemonization failed");
         }
+#if defined(__APPLE__) && defined(__clang__)
+#pragma clang diagnostic pop
+#endif
         else if (fd >= 3)
         {
             dup2(fd, 2);