1Based on http://ftp.free.org/mirrors/rsync.frugalware.org/frugalware-testing/source/apps-extra/sysklogd/sysklogd-1.5-systemd.diff
2
3diff -ruN -x '*~' sysklogd-1.5-old/Makefile sysklogd-1.5/Makefile
4--- sysklogd-1.5-old/Makefile 2007-05-30 17:28:48.000000000 +0200
5+++ sysklogd-1.5/Makefile 2013-05-09 16:01:14.428638113 +0200
6@@ -20,7 +20,7 @@
7 CC= gcc
8 #SKFLAGS= -g -DSYSV -Wall
9 #LDFLAGS= -g
10-SKFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce
11+SKFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce -I.
12 # -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
13 # -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
14 # $(shell getconf LFS_SKFLAGS)
15@@ -79,8 +79,8 @@
16
17 install: install_man install_exec
18
19-syslogd: syslogd.o pidfile.o
20- ${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o ${LIBS}
21+syslogd: syslogd.o pidfile.o sd-daemon.o
22+ ${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o sd-daemon.o ${LIBS}
23
24 klogd: klogd.o syslog.o pidfile.o ksym.o ksym_mod.o
25 ${CC} ${LDFLAGS} -o klogd klogd.o syslog.o pidfile.o ksym.o \
26@@ -101,6 +101,9 @@
27 syslog.o: syslog.c
28 ${CC} ${SKFLAGS} ${SYSLOG_FLAGS} -c syslog.c
29
30+sd-daemon.o: sd-daemon.c sd-daemon.h
31+ ${CC} ${SKFLAGS} ${SYSLOG_FLAGS} -c sd-daemon.c
32+
33 klogd.o: klogd.c klogd.h version.h
34 ${CC} ${SKFLAGS} ${KLOGD_FLAGS} $(DEB) -c klogd.c
35
36diff -ruN -x '*~' sysklogd-1.5-old/sd-daemon.c sysklogd-1.5/sd-daemon.c
37--- sysklogd-1.5-old/sd-daemon.c 1970-01-01 01:00:00.000000000 +0100
38+++ sysklogd-1.5/sd-daemon.c 2013-05-09 16:01:14.429638107 +0200
39@@ -0,0 +1,436 @@
40+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
41+
42+/***
43+ Copyright 2010 Lennart Poettering
44+
45+ Permission is hereby granted, free of charge, to any person
46+ obtaining a copy of this software and associated documentation files
47+ (the "Software"), to deal in the Software without restriction,
48+ including without limitation the rights to use, copy, modify, merge,
49+ publish, distribute, sublicense, and/or sell copies of the Software,
50+ and to permit persons to whom the Software is furnished to do so,
51+ subject to the following conditions:
52+
53+ The above copyright notice and this permission notice shall be
54+ included in all copies or substantial portions of the Software.
55+
56+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
57+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
58+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
59+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
60+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
61+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
62+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
63+ SOFTWARE.
64+***/
65+
66+#ifndef _GNU_SOURCE
67+#define _GNU_SOURCE
68+#endif
69+
70+#include <sys/types.h>
71+#include <sys/stat.h>
72+#include <sys/socket.h>
73+#include <sys/un.h>
74+#include <netinet/in.h>
75+#include <stdlib.h>
76+#include <fcntl.h>
77+#include <errno.h>
78+#include <unistd.h>
79+#include <string.h>
80+#include <stdarg.h>
81+#include <stdio.h>
82+#include <stddef.h>
83+
84+#include "sd-daemon.h"
85+
86+int sd_listen_fds(int unset_environment) {
87+
88+#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
89+ return 0;
90+#else
91+ int r, fd;
92+ const char *e;
93+ char *p = NULL;
94+ unsigned long l;
95+
96+ if (!(e = getenv("LISTEN_PID"))) {
97+ r = 0;
98+ goto finish;
99+ }
100+
101+ errno = 0;
102+ l = strtoul(e, &p, 10);
103+
104+ if (errno != 0) {
105+ r = -errno;
106+ goto finish;
107+ }
108+
109+ if (!p || *p || l <= 0) {
110+ r = -EINVAL;
111+ goto finish;
112+ }
113+
114+ /* Is this for us? */
115+ if (getpid() != (pid_t) l) {
116+ r = 0;
117+ goto finish;
118+ }
119+
120+ if (!(e = getenv("LISTEN_FDS"))) {
121+ r = 0;
122+ goto finish;
123+ }
124+
125+ errno = 0;
126+ l = strtoul(e, &p, 10);
127+
128+ if (errno != 0) {
129+ r = -errno;
130+ goto finish;
131+ }
132+
133+ if (!p || *p) {
134+ r = -EINVAL;
135+ goto finish;
136+ }
137+
138+ for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
139+ int flags;
140+
141+ if ((flags = fcntl(fd, F_GETFD)) < 0) {
142+ r = -errno;
143+ goto finish;
144+ }
145+
146+ if (flags & FD_CLOEXEC)
147+ continue;
148+
149+ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
150+ r = -errno;
151+ goto finish;
152+ }
153+ }
154+
155+ r = (int) l;
156+
157+finish:
158+ if (unset_environment) {
159+ unsetenv("LISTEN_PID");
160+ unsetenv("LISTEN_FDS");
161+ }
162+
163+ return r;
164+#endif
165+}
166+
167+int sd_is_fifo(int fd, const char *path) {
168+ struct stat st_fd;
169+
170+ if (fd < 0)
171+ return -EINVAL;
172+
173+ memset(&st_fd, 0, sizeof(st_fd));
174+ if (fstat(fd, &st_fd) < 0)
175+ return -errno;
176+
177+ if (!S_ISFIFO(st_fd.st_mode))
178+ return 0;
179+
180+ if (path) {
181+ struct stat st_path;
182+
183+ memset(&st_path, 0, sizeof(st_path));
184+ if (stat(path, &st_path) < 0) {
185+
186+ if (errno == ENOENT || errno == ENOTDIR)
187+ return 0;
188+
189+ return -errno;
190+ }
191+
192+ return
193+ st_path.st_dev == st_fd.st_dev &&
194+ st_path.st_ino == st_fd.st_ino;
195+ }
196+
197+ return 1;
198+}
199+
200+static int sd_is_socket_internal(int fd, int type, int listening) {
201+ struct stat st_fd;
202+
203+ if (fd < 0 || type < 0)
204+ return -EINVAL;
205+
206+ if (fstat(fd, &st_fd) < 0)
207+ return -errno;
208+
209+ if (!S_ISSOCK(st_fd.st_mode))
210+ return 0;
211+
212+ if (type != 0) {
213+ int other_type = 0;
214+ socklen_t l = sizeof(other_type);
215+
216+ if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0)
217+ return -errno;
218+
219+ if (l != sizeof(other_type))
220+ return -EINVAL;
221+
222+ if (other_type != type)
223+ return 0;
224+ }
225+
226+ if (listening >= 0) {
227+ int accepting = 0;
228+ socklen_t l = sizeof(accepting);
229+
230+ if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0)
231+ return -errno;
232+
233+ if (l != sizeof(accepting))
234+ return -EINVAL;
235+
236+ if (!accepting != !listening)
237+ return 0;
238+ }
239+
240+ return 1;
241+}
242+
243+union sockaddr_union {
244+ struct sockaddr sa;
245+ struct sockaddr_in in4;
246+ struct sockaddr_in6 in6;
247+ struct sockaddr_un un;
248+ struct sockaddr_storage storage;
249+};
250+
251+int sd_is_socket(int fd, int family, int type, int listening) {
252+ int r;
253+
254+ if (family < 0)
255+ return -EINVAL;
256+
257+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
258+ return r;
259+
260+ if (family > 0) {
261+ union sockaddr_union sockaddr;
262+ socklen_t l;
263+
264+ memset(&sockaddr, 0, sizeof(sockaddr));
265+ l = sizeof(sockaddr);
266+
267+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
268+ return -errno;
269+
270+ if (l < sizeof(sa_family_t))
271+ return -EINVAL;
272+
273+ return sockaddr.sa.sa_family == family;
274+ }
275+
276+ return 1;
277+}
278+
279+int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) {
280+ union sockaddr_union sockaddr;
281+ socklen_t l;
282+ int r;
283+
284+ if (family != 0 && family != AF_INET && family != AF_INET6)
285+ return -EINVAL;
286+
287+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
288+ return r;
289+
290+ memset(&sockaddr, 0, sizeof(sockaddr));
291+ l = sizeof(sockaddr);
292+
293+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
294+ return -errno;
295+
296+ if (l < sizeof(sa_family_t))
297+ return -EINVAL;
298+
299+ if (sockaddr.sa.sa_family != AF_INET &&
300+ sockaddr.sa.sa_family != AF_INET6)
301+ return 0;
302+
303+ if (family > 0)
304+ if (sockaddr.sa.sa_family != family)
305+ return 0;
306+
307+ if (port > 0) {
308+ if (sockaddr.sa.sa_family == AF_INET) {
309+ if (l < sizeof(struct sockaddr_in))
310+ return -EINVAL;
311+
312+ return htons(port) == sockaddr.in4.sin_port;
313+ } else {
314+ if (l < sizeof(struct sockaddr_in6))
315+ return -EINVAL;
316+
317+ return htons(port) == sockaddr.in6.sin6_port;
318+ }
319+ }
320+
321+ return 1;
322+}
323+
324+int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) {
325+ union sockaddr_union sockaddr;
326+ socklen_t l;
327+ int r;
328+
329+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
330+ return r;
331+
332+ memset(&sockaddr, 0, sizeof(sockaddr));
333+ l = sizeof(sockaddr);
334+
335+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
336+ return -errno;
337+
338+ if (l < sizeof(sa_family_t))
339+ return -EINVAL;
340+
341+ if (sockaddr.sa.sa_family != AF_UNIX)
342+ return 0;
343+
344+ if (path) {
345+ if (length <= 0)
346+ length = strlen(path);
347+
348+ if (length <= 0)
349+ /* Unnamed socket */
350+ return l == offsetof(struct sockaddr_un, sun_path);
351+
352+ if (path[0])
353+ /* Normal path socket */
354+ return
355+ (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) &&
356+ memcmp(path, sockaddr.un.sun_path, length+1) == 0;
357+ else
358+ /* Abstract namespace socket */
359+ return
360+ (l == offsetof(struct sockaddr_un, sun_path) + length) &&
361+ memcmp(path, sockaddr.un.sun_path, length) == 0;
362+ }
363+
364+ return 1;
365+}
366+
367+int sd_notify(int unset_environment, const char *state) {
368+#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC)
369+ return 0;
370+#else
371+ int fd = -1, r;
372+ struct msghdr msghdr;
373+ struct iovec iovec;
374+ union sockaddr_union sockaddr;
375+ const char *e;
376+
377+ if (!state) {
378+ r = -EINVAL;
379+ goto finish;
380+ }
381+
382+ if (!(e = getenv("NOTIFY_SOCKET")))
383+ return 0;
384+
385+ /* Must be an abstract socket, or an absolute path */
386+ if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
387+ r = -EINVAL;
388+ goto finish;
389+ }
390+
391+ if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
392+ r = -errno;
393+ goto finish;
394+ }
395+
396+ memset(&sockaddr, 0, sizeof(sockaddr));
397+ sockaddr.sa.sa_family = AF_UNIX;
398+ strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
399+
400+ if (sockaddr.un.sun_path[0] == '@')
401+ sockaddr.un.sun_path[0] = 0;
402+
403+ memset(&iovec, 0, sizeof(iovec));
404+ iovec.iov_base = (char*) state;
405+ iovec.iov_len = strlen(state);
406+
407+ memset(&msghdr, 0, sizeof(msghdr));
408+ msghdr.msg_name = &sockaddr;
409+ msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
410+
411+ if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
412+ msghdr.msg_namelen = sizeof(struct sockaddr_un);
413+
414+ msghdr.msg_iov = &iovec;
415+ msghdr.msg_iovlen = 1;
416+
417+ if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
418+ r = -errno;
419+ goto finish;
420+ }
421+
422+ r = 1;
423+
424+finish:
425+ if (unset_environment)
426+ unsetenv("NOTIFY_SOCKET");
427+
428+ if (fd >= 0)
429+ close(fd);
430+
431+ return r;
432+#endif
433+}
434+
435+int sd_notifyf(int unset_environment, const char *format, ...) {
436+#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
437+ return 0;
438+#else
439+ va_list ap;
440+ char *p = NULL;
441+ int r;
442+
443+ va_start(ap, format);
444+ r = vasprintf(&p, format, ap);
445+ va_end(ap);
446+
447+ if (r < 0 || !p)
448+ return -ENOMEM;
449+
450+ r = sd_notify(unset_environment, p);
451+ free(p);
452+
453+ return r;
454+#endif
455+}
456+
457+int sd_booted(void) {
458+#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
459+ return 0;
460+#else
461+
462+ struct stat a, b;
463+
464+ /* We simply test whether the systemd cgroup hierarchy is
465+ * mounted */
466+
467+ if (lstat("/sys/fs/cgroup", &a) < 0)
468+ return 0;
469+
470+ if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
471+ return 0;
472+
473+ return a.st_dev != b.st_dev;
474+#endif
475+}
476diff -ruN -x '*~' sysklogd-1.5-old/sd-daemon.h sysklogd-1.5/sd-daemon.h
477--- sysklogd-1.5-old/sd-daemon.h 1970-01-01 01:00:00.000000000 +0100
478+++ sysklogd-1.5/sd-daemon.h 2013-05-09 16:01:14.429638107 +0200
479@@ -0,0 +1,265 @@
480+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
481+
482+#ifndef foosddaemonhfoo
483+#define foosddaemonhfoo
484+
485+/***
486+ Copyright 2010 Lennart Poettering
487+
488+ Permission is hereby granted, free of charge, to any person
489+ obtaining a copy of this software and associated documentation files
490+ (the "Software"), to deal in the Software without restriction,
491+ including without limitation the rights to use, copy, modify, merge,
492+ publish, distribute, sublicense, and/or sell copies of the Software,
493+ and to permit persons to whom the Software is furnished to do so,
494+ subject to the following conditions:
495+
496+ The above copyright notice and this permission notice shall be
497+ included in all copies or substantial portions of the Software.
498+
499+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
500+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
501+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
502+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
503+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
504+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
505+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
506+ SOFTWARE.
507+***/
508+
509+#include <sys/types.h>
510+#include <inttypes.h>
511+
512+#ifdef __cplusplus
513+extern "C" {
514+#endif
515+
516+/*
517+ Reference implementation of a few systemd related interfaces for
518+ writing daemons. These interfaces are trivial to implement. To
519+ simplify porting we provide this reference implementation.
520+ Applications are welcome to reimplement the algorithms described
521+ here if they do not want to include these two source files.
522+
523+ The following functionality is provided:
524+
525+ - Support for logging with log levels on stderr
526+ - File descriptor passing for socket-based activation
527+ - Daemon startup and status notification
528+ - Detection of systemd boots
529+
530+ You may compile this with -DDISABLE_SYSTEMD to disable systemd
531+ support. This makes all those calls NOPs that are directly related to
532+ systemd (i.e. only sd_is_xxx() will stay useful).
533+
534+ Since this is drop-in code we don't want any of our symbols to be
535+ exported in any case. Hence we declare hidden visibility for all of
536+ them.
537+
538+ You may find an up-to-date version of these source files online:
539+
540+ http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h
541+ http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c
542+
543+ This should compile on non-Linux systems, too, but with the
544+ exception of the sd_is_xxx() calls all functions will become NOPs.
545+
546+ See sd-daemon(7) for more information.
547+*/
548+
549+#ifndef _sd_printf_attr_
550+#if __GNUC__ >= 4
551+#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
552+#else
553+#define _sd_printf_attr_(a,b)
554+#endif
555+#endif
556+
557+#ifndef _sd_hidden_
558+#if (__GNUC__ >= 4) && !defined(SD_EXPORT_SYMBOLS)
559+#define _sd_hidden_ __attribute__ ((visibility("hidden")))
560+#else
561+#define _sd_hidden_
562+#endif
563+#endif
564+
565+/*
566+ Log levels for usage on stderr:
567+
568+ fprintf(stderr, SD_NOTICE "Hello World!\n");
569+
570+ This is similar to printk() usage in the kernel.
571+*/
572+#define SD_EMERG "<0>" /* system is unusable */
573+#define SD_ALERT "<1>" /* action must be taken immediately */
574+#define SD_CRIT "<2>" /* critical conditions */
575+#define SD_ERR "<3>" /* error conditions */
576+#define SD_WARNING "<4>" /* warning conditions */
577+#define SD_NOTICE "<5>" /* normal but significant condition */
578+#define SD_INFO "<6>" /* informational */
579+#define SD_DEBUG "<7>" /* debug-level messages */
580+
581+/* The first passed file descriptor is fd 3 */
582+#define SD_LISTEN_FDS_START 3
583+
584+/*
585+ Returns how many file descriptors have been passed, or a negative
586+ errno code on failure. Optionally, removes the $LISTEN_FDS and
587+ $LISTEN_PID file descriptors from the environment (recommended, but
588+ problematic in threaded environments). If r is the return value of
589+ this function you'll find the file descriptors passed as fds
590+ SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
591+ errno style error code on failure. This function call ensures that
592+ the FD_CLOEXEC flag is set for the passed file descriptors, to make
593+ sure they are not passed on to child processes. If FD_CLOEXEC shall
594+ not be set, the caller needs to unset it after this call for all file
595+ descriptors that are used.
596+
597+ See sd_listen_fds(3) for more information.
598+*/
599+int sd_listen_fds(int unset_environment) _sd_hidden_;
600+
601+/*
602+ Helper call for identifying a passed file descriptor. Returns 1 if
603+ the file descriptor is a FIFO in the file system stored under the
604+ specified path, 0 otherwise. If path is NULL a path name check will
605+ not be done and the call only verifies if the file descriptor
606+ refers to a FIFO. Returns a negative errno style error code on
607+ failure.
608+
609+ See sd_is_fifo(3) for more information.
610+*/
611+int sd_is_fifo(int fd, const char *path) _sd_hidden_;
612+
613+/*
614+ Helper call for identifying a passed file descriptor. Returns 1 if
615+ the file descriptor is a socket of the specified family (AF_INET,
616+ ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
617+ family is 0 a socket family check will not be done. If type is 0 a
618+ socket type check will not be done and the call only verifies if
619+ the file descriptor refers to a socket. If listening is > 0 it is
620+ verified that the socket is in listening mode. (i.e. listen() has
621+ been called) If listening is == 0 it is verified that the socket is
622+ not in listening mode. If listening is < 0 no listening mode check
623+ is done. Returns a negative errno style error code on failure.
624+
625+ See sd_is_socket(3) for more information.
626+*/
627+int sd_is_socket(int fd, int family, int type, int listening) _sd_hidden_;
628+
629+/*
630+ Helper call for identifying a passed file descriptor. Returns 1 if
631+ the file descriptor is an Internet socket, of the specified family
632+ (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
633+ SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
634+ check is not done. If type is 0 a socket type check will not be
635+ done. If port is 0 a socket port check will not be done. The
636+ listening flag is used the same way as in sd_is_socket(). Returns a
637+ negative errno style error code on failure.
638+
639+ See sd_is_socket_inet(3) for more information.
640+*/
641+int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) _sd_hidden_;
642+
643+/*
644+ Helper call for identifying a passed file descriptor. Returns 1 if
645+ the file descriptor is an AF_UNIX socket of the specified type
646+ (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
647+ a socket type check will not be done. If path is NULL a socket path
648+ check will not be done. For normal AF_UNIX sockets set length to
649+ 0. For abstract namespace sockets set length to the length of the
650+ socket name (including the initial 0 byte), and pass the full
651+ socket path in path (including the initial 0 byte). The listening
652+ flag is used the same way as in sd_is_socket(). Returns a negative
653+ errno style error code on failure.
654+
655+ See sd_is_socket_unix(3) for more information.
656+*/
657+int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) _sd_hidden_;
658+
659+/*
660+ Informs systemd about changed daemon state. This takes a number of
661+ newline separated environment-style variable assignments in a
662+ string. The following variables are known:
663+
664+ READY=1 Tells systemd that daemon startup is finished (only
665+ relevant for services of Type=notify). The passed
666+ argument is a boolean "1" or "0". Since there is
667+ little value in signalling non-readiness the only
668+ value daemons should send is "READY=1".
669+
670+ STATUS=... Passes a single-line status string back to systemd
671+ that describes the daemon state. This is free-from
672+ and can be used for various purposes: general state
673+ feedback, fsck-like programs could pass completion
674+ percentages and failing programs could pass a human
675+ readable error message. Example: "STATUS=Completed
676+ 66% of file system check..."
677+
678+ ERRNO=... If a daemon fails, the errno-style error code,
679+ formatted as string. Example: "ERRNO=2" for ENOENT.
680+
681+ BUSERROR=... If a daemon fails, the D-Bus error-style error
682+ code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut"
683+
684+ MAINPID=... The main pid of a daemon, in case systemd did not
685+ fork off the process itself. Example: "MAINPID=4711"
686+
687+ Daemons can choose to send additional variables. However, it is
688+ recommened to prefix variable names not listed above with X_.
689+
690+ Returns a negative errno-style error code on failure. Returns > 0
691+ if systemd could be notified, 0 if it couldn't possibly because
692+ systemd is not running.
693+
694+ Example: When a daemon finished starting up, it could issue this
695+ call to notify systemd about it:
696+
697+ sd_notify(0, "READY=1");
698+
699+ See sd_notifyf() for more complete examples.
700+
701+ See sd_notify(3) for more information.
702+*/
703+int sd_notify(int unset_environment, const char *state) _sd_hidden_;
704+
705+/*
706+ Similar to sd_notify() but takes a format string.
707+
708+ Example 1: A daemon could send the following after initialization:
709+
710+ sd_notifyf(0, "READY=1\n"
711+ "STATUS=Processing requests...\n"
712+ "MAINPID=%lu",
713+ (unsigned long) getpid());
714+
715+ Example 2: A daemon could send the following shortly before
716+ exiting, on failure:
717+
718+ sd_notifyf(0, "STATUS=Failed to start up: %s\n"
719+ "ERRNO=%i",
720+ strerror(errno),
721+ errno);
722+
723+ See sd_notifyf(3) for more information.
724+*/
725+int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3) _sd_hidden_;
726+
727+/*
728+ Returns > 0 if the system was booted with systemd. Returns < 0 on
729+ error. Returns 0 if the system was not booted with systemd. Note
730+ that all of the functions above handle non-systemd boots just
731+ fine. You should NOT protect them with a call to this function. Also
732+ note that this function checks whether the system, not the user
733+ session is controlled by systemd. However the functions above work
734+ for both user and system services.
735+
736+ See sd_booted(3) for more information.
737+*/
738+int sd_booted(void) _sd_hidden_;
739+
740+#ifdef __cplusplus
741+}
742+#endif
743+
744+#endif
745diff -ruN -x '*~' sysklogd-1.5-old/syslogd.c sysklogd-1.5/syslogd.c
746--- sysklogd-1.5-old/syslogd.c 2007-07-04 21:04:01.000000000 +0200
747+++ sysklogd-1.5/syslogd.c 2013-05-09 16:04:32.106602589 +0200
748@@ -551,6 +551,7 @@
749
750 #if defined(__linux__)
751 #include <paths.h>
752+#include <sd-daemon.h>
753 #endif
754
755 #ifndef UTMP_FILE
756@@ -965,8 +966,11 @@
757 }
758 signal (SIGTERM, SIG_DFL);
759 num_fds = getdtablesize();
760- for (i= 0; i < num_fds; i++)
761- (void) close(i);
762+#if defined(__linux__)
763+ if (sd_listen_fds(0) <= 0)
764+#endif
765+ for (i = 0; i < num_fds; i++)
766+ (void) close(i);
767 untty();
768 }
769 else
770@@ -1253,6 +1257,60 @@
771 if (path[0] == '\0')
772 return -1;
773
774+#if defined(__linux__)
775+ if (strcmp(path, _PATH_LOG) == 0) {
776+ int r;
777+
778+ /* Check whether an FD was passed in from systemd. If
779+ * so, it's the /dev/log socket, so use it. */
780+
781+ r = sd_listen_fds(0);
782+ if (r < 0) {
783+ logerror("Failed to acquire systemd socket");
784+#ifndef SYSV
785+ dienow();
786+#else
787+ return -1;
788+#endif
789+ }
790+
791+
792+ if (r > 1) {
793+ logerror("Wrong number of systemd sockets passed");
794+#ifndef SYSV
795+ dienow();
796+#else
797+ return -1;
798+#endif
799+ }
800+
801+ if (r == 1) {
802+ fd = SD_LISTEN_FDS_START;
803+ r = sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/syslog", 0);
804+ if (r < 0) {
805+ logerror("Failed to verify systemd socket type");
806+#ifndef SYSV
807+ dienow();
808+#else
809+ return -1;
810+#endif
811+ }
812+
813+ if (!r) {
814+ logerror("Passed systemd socket of wrong type");
815+#ifndef SYSV
816+ dienow();
817+#else
818+ return -1;
819+#endif
820+ }
821+
822+ dprintf("Using systemd socket (%d).\n", fd);
823+ return fd;
824+ }
825+ }
826+#endif
827+
828 (void) unlink(path);
829
830 memset(&sunx, 0, sizeof(sunx));
831@@ -2254,9 +2312,11 @@
832 if (InetInuse) close(inetm);
833
834 /* Clean-up files. */
835- for (i = 0; i < nfunix; i++)
836- if (funixn[i] && funix[i] != -1)
837- (void)unlink(funixn[i]);
838+ i = 0;
839+#if defined(__linux__)
840+ if (sd_listen_fds(0) > 0)
841+ i = 1;
842+#endif
843 #ifndef TESTING
844 (void) remove_pid(PidFile);
845 #endif