WIP
This commit is contained in:
@@ -9,7 +9,7 @@ CLEANFILES = roken.h make-roken.c $(XHEADERS)
|
||||
lib_LTLIBRARIES = libroken.la
|
||||
|
||||
libroken_la_LDFLAGS = -version-info 20:0:1
|
||||
libroken_la_CPPFLAGS = -DBUILD_ROKEN_LIB
|
||||
libroken_la_CPPFLAGS = -DBUILD_ROKEN_LIB $(SYSTEMD_CFLAGS)
|
||||
|
||||
if versionscript
|
||||
libroken_la_LDFLAGS += $(LDFLAGS_VERSION_SCRIPT)$(srcdir)/version-script.map
|
||||
@@ -199,7 +199,7 @@ EXTRA_libroken_la_SOURCES = \
|
||||
search.hin \
|
||||
vis.hin
|
||||
|
||||
libroken_la_LIBADD = @LTLIBOBJS@ $(LIB_crypt) $(LIB_pidfile)
|
||||
libroken_la_LIBADD = @LTLIBOBJS@ $(LIB_crypt) $(LIB_pidfile) $(SYSTEMD_LIBS)
|
||||
if SUNOS
|
||||
libroken_la_LIBADD += -lnsl -lsocket
|
||||
endif
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
#endif
|
||||
#include "roken.h"
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
#include <systemd/sd-daemon.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define dup2 _dup2
|
||||
#endif
|
||||
@@ -171,6 +175,24 @@ roken_detach_prep(int argc, char **argv, const char *special_arg)
|
||||
#define dup2 _dup2
|
||||
#endif
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
roken_sd_notify(const char *state)
|
||||
{
|
||||
#ifdef HAVE_SYSTEMD
|
||||
int r;
|
||||
|
||||
if (state == NULL)
|
||||
return -1;
|
||||
r = sd_notify(0, state);
|
||||
if (r > 0)
|
||||
return 0;
|
||||
return -1;
|
||||
#else
|
||||
(void)state;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
roken_detach_finish(const char *dir, int daemon_child_fd)
|
||||
{
|
||||
@@ -203,6 +225,13 @@ roken_detach_finish(const char *dir, int daemon_child_fd)
|
||||
err(1, "failed to chdir to /");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Notify systemd that we are ready (if built with systemd support).
|
||||
* Do this after setsid/chdir and after pidfiles are written so that
|
||||
* systemd sees the process in its final state.
|
||||
*/
|
||||
(void) roken_sd_notify("READY=1");
|
||||
|
||||
do {
|
||||
bytes = write(pipefds[1], buf, sizeof(buf));
|
||||
} while (bytes == -1 && errno == EINTR);
|
||||
|
||||
@@ -939,6 +939,7 @@ ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_detach_prep(int, char **, const char *);
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL roken_detach_finish(const char *, int);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_sd_notify(const char *);
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_write (rk_socket_t, const void *, size_t);
|
||||
|
||||
Reference in New Issue
Block a user