From: Christian Hesse <m...@eworm.de> We have voices that do not want to "litter ENABLE_SYSTEMD all over the code". So move the systemd specific bits to platform_notify() in platform.c.
Signed-off-by: Christian Hesse <m...@eworm.de> --- src/openvpn/init.c | 23 +++++------------------ src/openvpn/platform.c | 13 +++++++++++++ src/openvpn/platform.h | 2 ++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 9a3e29d..46df8ca 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -30,10 +30,6 @@ #include "syshead.h" -#ifdef ENABLE_SYSTEMD -#include <systemd/sd-daemon.h> -#endif - #include "win32.h" #include "init.h" #include "sig.h" @@ -983,13 +979,11 @@ possibly_become_daemon(const struct options *options) { bool ret = false; -#ifdef ENABLE_SYSTEMD /* return without forking if we are running from systemd */ - if (sd_notify(0, "READY=0") > 0) + if (platform_notify("READY=0", "STATUS=Possibly become daemon") > 0) { return ret; } -#endif if (options->daemon) { @@ -1026,7 +1020,6 @@ do_uid_gid_chroot(struct context *c, bool no_delay) { if (no_delay) { -#ifdef ENABLE_SYSTEMD /* If OpenVPN is started by systemd, the OpenVPN process needs * to provide a preliminary status report to systemd. This is * needed as $NOTIFY_SOCKET will not be available inside the @@ -1040,10 +1033,8 @@ do_uid_gid_chroot(struct context *c, bool no_delay) * have a sane way to know if OpenVPN will chroot or not and to * which subdirectory it will chroot into. */ - sd_notifyf(0, "READY=1\n" - "STATUS=Entering chroot, most of the init completed successfully\n" - "MAINPID=%lu", (unsigned long) getpid()); -#endif + platform_notify("READY=1", + "STATUS=Entering chroot, most of the init completed successfully"); platform_chroot(c->options.chroot_dir); } else if (c->first_time) @@ -1384,17 +1375,13 @@ initialization_sequence_completed(struct context *c, const unsigned int flags) show_adapters(M_INFO|M_NOPREFIX); msg(M_INFO, "%s With Errors ( see http://openvpn.net/faq.html#dhcpclientserv )", message); #else -#ifdef ENABLE_SYSTEMD - sd_notifyf(0, "STATUS=Failed to start up: %s With Errors\nERRNO=1", message); -#endif /* HAVE_SYSTEMD_SD_DAEMON_H */ + platform_notify("READY=0", "STATUS=Failed to start up"); msg(M_INFO, "%s With Errors", message); #endif } else { -#ifdef ENABLE_SYSTEMD - sd_notifyf(0, "READY=1\nSTATUS=%s\nMAINPID=%lu", message, (unsigned long) getpid()); -#endif + platform_notify("READY=1", "STATUS=Initialization Sequence Completed"); msg(M_INFO, "%s", message); } diff --git a/src/openvpn/platform.c b/src/openvpn/platform.c index 952d633..55a25b0 100644 --- a/src/openvpn/platform.c +++ b/src/openvpn/platform.c @@ -30,6 +30,10 @@ #include "syshead.h" +#ifdef ENABLE_SYSTEMD +#include <systemd/sd-daemon.h> +#endif + #include "buffer.h" #include "error.h" #include "win32.h" @@ -336,3 +340,12 @@ platform_stat(const char *path, platform_stat_t *buf) #endif } +int +platform_notify(const char *status, const char *message) +{ +#ifdef ENABLE_SYSTEMD + return sd_notifyf(0, "%s\n%s", status, message); +#endif + + return 0; +} diff --git a/src/openvpn/platform.h b/src/openvpn/platform.h index 62396a9..94c92e4 100644 --- a/src/openvpn/platform.h +++ b/src/openvpn/platform.h @@ -144,4 +144,6 @@ typedef struct stat platform_stat_t; #endif int platform_stat(const char *path, platform_stat_t *buf); +int platform_notify(const char *status, const char *message); + #endif /* ifndef PLATFORM_H */ -- 2.11.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel