samba-util: add exit_daemon() to support reporting to systemd from smbd
authorAlexander Bokovoy <ab@samba.org>
Wed, 26 Mar 2014 08:56:12 +0000 (10:56 +0200)
committerAlexander Bokovoy <ab@samba.org>
Wed, 26 Mar 2014 10:05:22 +0000 (12:05 +0200)
lib/util/become_daemon.c
lib/util/samba_util.h

index c4691f6d4c3b32112461fd4c30f0f25d061240ad..a8abe2d0033abe0318a53db70244a86c6d8f489d 100644 (file)
@@ -105,3 +105,19 @@ _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout
         * never close stderr (but debug might dup it onto a log file) */
        close_low_fds(do_fork, !log_stdout, false);
 }
+
+_PUBLIC_ void exit_daemon(const char *msg, int error)
+{
+#ifdef HAVE_SYSTEMD
+       if (msg == NULL) {
+               msg = strerror(error);
+       }
+
+       sd_notifyf(0, "STATUS=daemon failed to start: %s\n"
+                                 "ERRNO=%i",
+                                 msg,
+                                 error);
+#endif
+       DEBUG(0, ("STATUS=daemon failed to start: %s, error code %d\n", msg, error));
+       exit(1);
+}
index 21bc9aad6f348787c66379af2783108f76b4e889..b1d520b022daf02600a409d7659a2f063cf1215b 100644 (file)
@@ -845,6 +845,12 @@ _PUBLIC_ void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too);
 **/
 _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout);
 
+/**
+ Exit daemon and print error message to the log at level 0
+ Optionally report failure to systemd if systemd integration is enabled
+**/
+_PUBLIC_ void exit_daemon(const char *msg, int error);
+
 /**
  * @brief Get a password from the console.
  *