diff -up ypbind-mt-1.36/configure.in.sdnotify ypbind-mt-1.36/configure.in --- ypbind-mt-1.36/configure.in.sdnotify 2012-07-09 16:41:36.000000000 +0200 +++ ypbind-mt-1.36/configure.in 2012-07-12 13:28:25.221031367 +0200 @@ -103,6 +103,18 @@ JH_CHECK_XML_CATALOG([http://docbook.sou [DocBook XSL Stylesheets], [], enable_man=no) AM_CONDITIONAL(ENABLE_REGENERATE_MAN, test x$enable_man != xno) +USE_SD_NOTIFY=0 +AC_SUBST(USE_SD_NOTIFY) +AC_CHECK_LIB(systemd-daemon,sd_notify,LIBSYSTEMD_DAEMON="-lsystemd-daemon", + LIBSYSTEMD_DAEMON="") +if test -n "$LIBSYSTEMD_DAEMON" ; then + AC_CHECK_HEADERS(systemd/sd-daemon.h) + if test "$ac_cv_header_systemd_sd_notify_h" = yes; then + USE_SD_NOTIFY=1 + fi +fi +AC_SUBST(USE_SD_NOTIFY) +AC_SUBST(LIBSYSTEMD_DAEMON) dnl internationalization macros AM_GNU_GETTEXT_VERSION diff -up ypbind-mt-1.36/src/Makefile.am.sdnotify ypbind-mt-1.36/src/Makefile.am --- ypbind-mt-1.36/src/Makefile.am.sdnotify 2009-06-15 16:30:45.000000000 +0200 +++ ypbind-mt-1.36/src/Makefile.am 2012-07-12 13:28:25.288029189 +0200 @@ -8,8 +8,9 @@ localedir = $(datadir)/locale WARNFLAGS = @WARNFLAGS@ AM_CFLAGS = -D_REENTRANT=1 $(WARNFLAGS) -DUSE_BROADCAST=@USE_BROADCAST@ \ - -DLOCALEDIR=\"$(localedir)\" @DBUS_CFLAGS@ @GLIB_CFLAGS@ -ypbind_LDADD = ../lib/libcompat.a @LIBINTL@ @SLP_LIBS@ @DBUS_LIBS@ @GLIB_LIBS@ + -DLOCALEDIR=\"$(localedir)\" @DBUS_CFLAGS@ @GLIB_CFLAGS@ -DUSE_SD_NOTIFY=@USE_SD_NOTIFY@ +ypbind_LDADD = ../lib/libcompat.a @LIBINTL@ @SLP_LIBS@ @DBUS_LIBS@ @GLIB_LIBS@ \ + $(LIBSYSTEMD_DAEMON) CLEANFILES = *~ diff -up ypbind-mt-1.36/src/ypbind-mt.c.sdnotify ypbind-mt-1.36/src/ypbind-mt.c --- ypbind-mt-1.36/src/ypbind-mt.c.sdnotify 2012-07-11 14:02:46.000000000 +0200 +++ ypbind-mt-1.36/src/ypbind-mt.c 2012-07-12 13:57:52.479549892 +0200 @@ -49,6 +49,9 @@ #if defined(HAVE_NSS_H) #include #endif +#if defined(HAVE_SYSTEMD_SD_DAEMON_H) +#include +#endif #include "ypbind.h" #include "log_msg.h" @@ -952,6 +955,30 @@ main (int argc, char **argv) pthread_create (&ping_thread, NULL, &test_bindings, NULL); +#ifdef USE_SD_NOTIFY + { + /* + * If we use systemd as an init process we may want to give it + * a message, that ypbind daemon is ready to accept connections. + * At this time, sockets for receiving connections are already + * created, so we can say we're ready now. + */ + int result; + result = sd_notifyf(0, "READY=1\n" + "STATUS=Processing requests...\n" + "MAINPID=%lu", (unsigned long) getpid()); + + /* + * Return code from sd_notifyf can be ignored, as per sd_notifyf(3). + * However, if we use systemd's native unit file, we need to send + * this message to let systemd know that daemon is ready. + * Thus, we want to know that the call had some issues. + */ + if (result < 0) + log_msg ("sd_notifyf failed: %s\n", strerror(-result)); + } +#endif + svc_run (); log_msg (LOG_ERR, _("svc_run returned.")); unlink (_YPBIND_PIDFILE);