[rwho] Use sdnotify message to inform systemd the daemon is ready

Honza Horak hhorak at fedoraproject.org
Thu Oct 4 12:34:38 UTC 2012


commit 4698c0ddbc66bb4ba61de7c3b833a23887bfc1f5
Author: Honza HorĂ¡k <hhorak at redhat.com>
Date:   Thu Oct 4 14:34:25 2012 +0200

    Use sdnotify message to inform systemd the daemon is ready

 rwho-0.17-sdnotify.patch |   38 ++++++++++++++++++++++++++++++++++++++
 rwho.spec                |   12 ++++++++++--
 rwhod.service            |    3 ++-
 3 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/rwho-0.17-sdnotify.patch b/rwho-0.17-sdnotify.patch
new file mode 100644
index 0000000..28c28ad
--- /dev/null
+++ b/rwho-0.17-sdnotify.patch
@@ -0,0 +1,38 @@
+diff -up netkit-rwho-0.17/rwhod/rwhod.c.sdnotify netkit-rwho-0.17/rwhod/rwhod.c
+--- netkit-rwho-0.17/rwhod/rwhod.c.sdnotify	2012-10-04 14:20:59.684274929 +0200
++++ netkit-rwho-0.17/rwhod/rwhod.c	2012-10-04 14:23:34.659195688 +0200
+@@ -70,6 +70,7 @@ char rcsid[] =
+ #include <pwd.h>
+ #include <grp.h>
+ #include <time.h>
++#include <systemd/sd-daemon.h>
+ 
+ #include "daemon.h"
+ 
+@@ -250,6 +251,26 @@ main(int argc, char *argv[])
+ 		}
+ 	}
+ 
++	/* If we use systemd as an init system, we may want to give it 
++	    a message, that this daemon is ready to accept connections.
++	    At this time, sockets for receiving connections are already 
++	    created, so we can say we're ready now. It is a nop if we 
++	    don't use systemd. */
++	{
++		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)
++			syslog(LOG_ERR, "sd_notifyf failed: %s\n", strerror(-result));
++	}
++
+ 	for (;;) {
+ 		struct whod wd;
+ 		ssize_t cc;
diff --git a/rwho.spec b/rwho.spec
index b2ea5f3..758efa9 100644
--- a/rwho.spec
+++ b/rwho.spec
@@ -1,7 +1,7 @@
 Summary: Displays who is logged in to local network machines
 Name: rwho
 Version: 0.17
-Release: 43%{?dist}
+Release: 44%{?dist}
 # part of rwhod is under GPL+, other parts are under BSD
 License: BSD and GPL+
 Group: System Environment/Daemons
@@ -19,11 +19,13 @@ Patch8: rwho-0.17-gcc4.patch
 Patch9: rwho-0.17-waitchild.patch
 Patch10: rwho-0.17-neighbours.patch
 Patch11: rwho-0.17-hostnamelen.patch
+Patch12: rwho-0.17-sdnotify.patch
 Requires(post): systemd-units
 Requires(preun): systemd-units
 Requires(postun): systemd-units
 Requires(post): systemd-sysv
 BuildRequires: systemd-units
+BuildRequires: systemd-devel
 
 %description
 The rwho command displays output similar to the output of the who
@@ -47,6 +49,7 @@ are logged in to your local network.
 %patch9 -p1 -b .waitchild
 %patch10 -p1 -b .neighbours
 %patch11 -p1 -b .hostnamelen
+%patch12 -p1 -b .sdnotify
 
 %build
 sh configure --with-c-compiler=gcc
@@ -58,6 +61,7 @@ sh configure --with-c-compiler=gcc
     s,^BINDIR=.*$,BINDIR=%{_bindir},;
     s,^MANDIR=.*$,MANDIR=%{_mandir},;
     s,^SBINDIR=.*$,SBINDIR=%{_sbindir},;
+    s,^LIBS=,LIBS=-lsystemd-daemon ,;
     ' MCONFIG
 %else
 %{__perl} -pi -e '
@@ -67,9 +71,10 @@ sh configure --with-c-compiler=gcc
     s,^BINDIR=.*$,BINDIR=%{_bindir},;
     s,^MANDIR=.*$,MANDIR=%{_mandir},;
     s,^SBINDIR=.*$,SBINDIR=%{_sbindir},;
+    s,^LIBS=,LIBS=-lsystemd-daemon ,;
     ' MCONFIG
 %endif
-make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
+LIBS="-lsystemd-daemon $LIBS" make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
 
 %install
 mkdir -p ${RPM_BUILD_ROOT}%{_bindir}
@@ -112,6 +117,9 @@ install -m 644 %SOURCE1 ${RPM_BUILD_ROOT}%{_unitdir}/rwhod.service
 %{_unitdir}/*
 
 %changelog
+* Thu Oct 04 2012 Honza Horak <hhorak at redhat.com> - 0.17-44
+- Use sdnotify message to inform systemd the daemon is ready
+
 * Thu Oct 04 2012 Honza Horak <hhorak at redhat.com> - 0.17-43
 - Run %%triggerun regardless of systemd_post variable definition
 
diff --git a/rwhod.service b/rwhod.service
index d5e166e..2fc6c58 100644
--- a/rwhod.service
+++ b/rwhod.service
@@ -3,7 +3,8 @@ Description=Remote Machine Logged In User Lister
 Requires=syslog.target network.target
 
 [Service]
-Type=forking
+Type=notify
+NotifyAccess=all
 ExecStart=/usr/sbin/rwhod
 StandardError=syslog
 


More information about the scm-commits mailing list