ripasso-cursive: cosmetic changes (#361736)
[NixPkgs.git] / pkgs / by-name / sy / sysklogd / systemd.patch
bloba170f67cadbb04d8d5b7924891acee3b17e385f0
1 Based on http://ftp.free.org/mirrors/rsync.frugalware.org/frugalware-testing/source/apps-extra/sysklogd/sysklogd-1.5-systemd.diff
3 diff -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 @@
17 install: install_man install_exec
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}
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
30 +sd-daemon.o: sd-daemon.c sd-daemon.h
31 + ${CC} ${SKFLAGS} ${SYSLOG_FLAGS} -c sd-daemon.c
33 klogd.o: klogd.c klogd.h version.h
34 ${CC} ${SKFLAGS} ${KLOGD_FLAGS} $(DEB) -c klogd.c
36 diff -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 -*-*/
42 +/***
43 + Copyright 2010 Lennart Poettering
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:
53 + The above copyright notice and this permission notice shall be
54 + included in all copies or substantial portions of the Software.
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 +***/
66 +#ifndef _GNU_SOURCE
67 +#define _GNU_SOURCE
68 +#endif
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>
84 +#include "sd-daemon.h"
86 +int sd_listen_fds(int unset_environment) {
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;
96 + if (!(e = getenv("LISTEN_PID"))) {
97 + r = 0;
98 + goto finish;
99 + }
101 + errno = 0;
102 + l = strtoul(e, &p, 10);
104 + if (errno != 0) {
105 + r = -errno;
106 + goto finish;
109 + if (!p || *p || l <= 0) {
110 + r = -EINVAL;
111 + goto finish;
114 + /* Is this for us? */
115 + if (getpid() != (pid_t) l) {
116 + r = 0;
117 + goto finish;
120 + if (!(e = getenv("LISTEN_FDS"))) {
121 + r = 0;
122 + goto finish;
125 + errno = 0;
126 + l = strtoul(e, &p, 10);
128 + if (errno != 0) {
129 + r = -errno;
130 + goto finish;
133 + if (!p || *p) {
134 + r = -EINVAL;
135 + goto finish;
138 + for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
139 + int flags;
141 + if ((flags = fcntl(fd, F_GETFD)) < 0) {
142 + r = -errno;
143 + goto finish;
146 + if (flags & FD_CLOEXEC)
147 + continue;
149 + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
150 + r = -errno;
151 + goto finish;
155 + r = (int) l;
157 +finish:
158 + if (unset_environment) {
159 + unsetenv("LISTEN_PID");
160 + unsetenv("LISTEN_FDS");
163 + return r;
164 +#endif
167 +int sd_is_fifo(int fd, const char *path) {
168 + struct stat st_fd;
170 + if (fd < 0)
171 + return -EINVAL;
173 + memset(&st_fd, 0, sizeof(st_fd));
174 + if (fstat(fd, &st_fd) < 0)
175 + return -errno;
177 + if (!S_ISFIFO(st_fd.st_mode))
178 + return 0;
180 + if (path) {
181 + struct stat st_path;
183 + memset(&st_path, 0, sizeof(st_path));
184 + if (stat(path, &st_path) < 0) {
186 + if (errno == ENOENT || errno == ENOTDIR)
187 + return 0;
189 + return -errno;
192 + return
193 + st_path.st_dev == st_fd.st_dev &&
194 + st_path.st_ino == st_fd.st_ino;
197 + return 1;
200 +static int sd_is_socket_internal(int fd, int type, int listening) {
201 + struct stat st_fd;
203 + if (fd < 0 || type < 0)
204 + return -EINVAL;
206 + if (fstat(fd, &st_fd) < 0)
207 + return -errno;
209 + if (!S_ISSOCK(st_fd.st_mode))
210 + return 0;
212 + if (type != 0) {
213 + int other_type = 0;
214 + socklen_t l = sizeof(other_type);
216 + if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0)
217 + return -errno;
219 + if (l != sizeof(other_type))
220 + return -EINVAL;
222 + if (other_type != type)
223 + return 0;
226 + if (listening >= 0) {
227 + int accepting = 0;
228 + socklen_t l = sizeof(accepting);
230 + if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0)
231 + return -errno;
233 + if (l != sizeof(accepting))
234 + return -EINVAL;
236 + if (!accepting != !listening)
237 + return 0;
240 + return 1;
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;
251 +int sd_is_socket(int fd, int family, int type, int listening) {
252 + int r;
254 + if (family < 0)
255 + return -EINVAL;
257 + if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
258 + return r;
260 + if (family > 0) {
261 + union sockaddr_union sockaddr;
262 + socklen_t l;
264 + memset(&sockaddr, 0, sizeof(sockaddr));
265 + l = sizeof(sockaddr);
267 + if (getsockname(fd, &sockaddr.sa, &l) < 0)
268 + return -errno;
270 + if (l < sizeof(sa_family_t))
271 + return -EINVAL;
273 + return sockaddr.sa.sa_family == family;
276 + return 1;
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;
284 + if (family != 0 && family != AF_INET && family != AF_INET6)
285 + return -EINVAL;
287 + if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
288 + return r;
290 + memset(&sockaddr, 0, sizeof(sockaddr));
291 + l = sizeof(sockaddr);
293 + if (getsockname(fd, &sockaddr.sa, &l) < 0)
294 + return -errno;
296 + if (l < sizeof(sa_family_t))
297 + return -EINVAL;
299 + if (sockaddr.sa.sa_family != AF_INET &&
300 + sockaddr.sa.sa_family != AF_INET6)
301 + return 0;
303 + if (family > 0)
304 + if (sockaddr.sa.sa_family != family)
305 + return 0;
307 + if (port > 0) {
308 + if (sockaddr.sa.sa_family == AF_INET) {
309 + if (l < sizeof(struct sockaddr_in))
310 + return -EINVAL;
312 + return htons(port) == sockaddr.in4.sin_port;
313 + } else {
314 + if (l < sizeof(struct sockaddr_in6))
315 + return -EINVAL;
317 + return htons(port) == sockaddr.in6.sin6_port;
321 + return 1;
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;
329 + if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
330 + return r;
332 + memset(&sockaddr, 0, sizeof(sockaddr));
333 + l = sizeof(sockaddr);
335 + if (getsockname(fd, &sockaddr.sa, &l) < 0)
336 + return -errno;
338 + if (l < sizeof(sa_family_t))
339 + return -EINVAL;
341 + if (sockaddr.sa.sa_family != AF_UNIX)
342 + return 0;
344 + if (path) {
345 + if (length <= 0)
346 + length = strlen(path);
348 + if (length <= 0)
349 + /* Unnamed socket */
350 + return l == offsetof(struct sockaddr_un, sun_path);
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;
364 + return 1;
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;
377 + if (!state) {
378 + r = -EINVAL;
379 + goto finish;
382 + if (!(e = getenv("NOTIFY_SOCKET")))
383 + return 0;
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;
391 + if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
392 + r = -errno;
393 + goto finish;
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));
400 + if (sockaddr.un.sun_path[0] == '@')
401 + sockaddr.un.sun_path[0] = 0;
403 + memset(&iovec, 0, sizeof(iovec));
404 + iovec.iov_base = (char*) state;
405 + iovec.iov_len = strlen(state);
407 + memset(&msghdr, 0, sizeof(msghdr));
408 + msghdr.msg_name = &sockaddr;
409 + msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
411 + if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
412 + msghdr.msg_namelen = sizeof(struct sockaddr_un);
414 + msghdr.msg_iov = &iovec;
415 + msghdr.msg_iovlen = 1;
417 + if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
418 + r = -errno;
419 + goto finish;
422 + r = 1;
424 +finish:
425 + if (unset_environment)
426 + unsetenv("NOTIFY_SOCKET");
428 + if (fd >= 0)
429 + close(fd);
431 + return r;
432 +#endif
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;
443 + va_start(ap, format);
444 + r = vasprintf(&p, format, ap);
445 + va_end(ap);
447 + if (r < 0 || !p)
448 + return -ENOMEM;
450 + r = sd_notify(unset_environment, p);
451 + free(p);
453 + return r;
454 +#endif
457 +int sd_booted(void) {
458 +#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
459 + return 0;
460 +#else
462 + struct stat a, b;
464 + /* We simply test whether the systemd cgroup hierarchy is
465 + * mounted */
467 + if (lstat("/sys/fs/cgroup", &a) < 0)
468 + return 0;
470 + if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
471 + return 0;
473 + return a.st_dev != b.st_dev;
474 +#endif
476 diff -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 -*-*/
482 +#ifndef foosddaemonhfoo
483 +#define foosddaemonhfoo
485 +/***
486 + Copyright 2010 Lennart Poettering
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:
496 + The above copyright notice and this permission notice shall be
497 + included in all copies or substantial portions of the Software.
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 +***/
509 +#include <sys/types.h>
510 +#include <inttypes.h>
512 +#ifdef __cplusplus
513 +extern "C" {
514 +#endif
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.
523 + The following functionality is provided:
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
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).
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.
538 + You may find an up-to-date version of these source files online:
540 + http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h
541 + http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c
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.
546 + See sd-daemon(7) for more information.
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
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
566 + Log levels for usage on stderr:
568 + fprintf(stderr, SD_NOTICE "Hello World!\n");
570 + This is similar to printk() usage in the kernel.
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 */
581 +/* The first passed file descriptor is fd 3 */
582 +#define SD_LISTEN_FDS_START 3
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.
597 + See sd_listen_fds(3) for more information.
599 +int sd_listen_fds(int unset_environment) _sd_hidden_;
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.
609 + See sd_is_fifo(3) for more information.
611 +int sd_is_fifo(int fd, const char *path) _sd_hidden_;
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.
625 + See sd_is_socket(3) for more information.
627 +int sd_is_socket(int fd, int family, int type, int listening) _sd_hidden_;
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.
639 + See sd_is_socket_inet(3) for more information.
641 +int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) _sd_hidden_;
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.
655 + See sd_is_socket_unix(3) for more information.
657 +int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) _sd_hidden_;
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:
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".
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..."
678 + ERRNO=... If a daemon fails, the errno-style error code,
679 + formatted as string. Example: "ERRNO=2" for ENOENT.
681 + BUSERROR=... If a daemon fails, the D-Bus error-style error
682 + code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut"
684 + MAINPID=... The main pid of a daemon, in case systemd did not
685 + fork off the process itself. Example: "MAINPID=4711"
687 + Daemons can choose to send additional variables. However, it is
688 + recommened to prefix variable names not listed above with X_.
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.
694 + Example: When a daemon finished starting up, it could issue this
695 + call to notify systemd about it:
697 + sd_notify(0, "READY=1");
699 + See sd_notifyf() for more complete examples.
701 + See sd_notify(3) for more information.
703 +int sd_notify(int unset_environment, const char *state) _sd_hidden_;
706 + Similar to sd_notify() but takes a format string.
708 + Example 1: A daemon could send the following after initialization:
710 + sd_notifyf(0, "READY=1\n"
711 + "STATUS=Processing requests...\n"
712 + "MAINPID=%lu",
713 + (unsigned long) getpid());
715 + Example 2: A daemon could send the following shortly before
716 + exiting, on failure:
718 + sd_notifyf(0, "STATUS=Failed to start up: %s\n"
719 + "ERRNO=%i",
720 + strerror(errno),
721 + errno);
723 + See sd_notifyf(3) for more information.
725 +int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3) _sd_hidden_;
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.
736 + See sd_booted(3) for more information.
738 +int sd_booted(void) _sd_hidden_;
740 +#ifdef __cplusplus
742 +#endif
744 +#endif
745 diff -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 @@
750 #if defined(__linux__)
751 #include <paths.h>
752 +#include <sd-daemon.h>
753 #endif
755 #ifndef UTMP_FILE
756 @@ -965,8 +966,11 @@
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();
769 else
770 @@ -1253,6 +1257,60 @@
771 if (path[0] == '\0')
772 return -1;
774 +#if defined(__linux__)
775 + if (strcmp(path, _PATH_LOG) == 0) {
776 + int r;
778 + /* Check whether an FD was passed in from systemd. If
779 + * so, it's the /dev/log socket, so use it. */
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
792 + if (r > 1) {
793 + logerror("Wrong number of systemd sockets passed");
794 +#ifndef SYSV
795 + dienow();
796 +#else
797 + return -1;
798 +#endif
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
813 + if (!r) {
814 + logerror("Passed systemd socket of wrong type");
815 +#ifndef SYSV
816 + dienow();
817 +#else
818 + return -1;
819 +#endif
822 + dprintf("Using systemd socket (%d).\n", fd);
823 + return fd;
826 +#endif
828 (void) unlink(path);
830 memset(&sunx, 0, sizeof(sunx));
831 @@ -2254,9 +2312,11 @@
832 if (InetInuse) close(inetm);
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