diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c index bedd3b239..ef0b96491 100644 --- a/libdaemon/server/daemon-server.c +++ b/libdaemon/server/daemon-server.c @@ -604,6 +604,12 @@ void daemon_start(daemon_state s) if (!s.foreground) kill(getppid(), SIGTERM); + if (s.daemon_main) { + if (!s.daemon_main(&s)) + failed = 1; + goto out; + } + if (s.daemon_init) if (!s.daemon_init(&s)) failed = 1; @@ -635,7 +641,7 @@ void daemon_start(daemon_state s) INFO(&s, "%s waiting for client threads to finish", s.name); reap(s, 1); - +out: /* If activated by systemd, do not unlink the socket - systemd takes care of that! */ if (!_systemd_activation && s.socket_fd >= 0) if (unlink(s.socket_path)) diff --git a/libdaemon/server/daemon-server.h b/libdaemon/server/daemon-server.h index 820e5e042..b235edce6 100644 --- a/libdaemon/server/daemon-server.h +++ b/libdaemon/server/daemon-server.h @@ -107,6 +107,7 @@ typedef struct daemon_state { handle_request handler; int (*daemon_init)(struct daemon_state *st); int (*daemon_fini)(struct daemon_state *st); + int (*daemon_main)(struct daemon_state *st); /* Global runtime info maintained by the framework. */ int socket_fd;