Blame SOURCES/0002-Remove-bundled-copy-of-sd-daemon.-ch.patch

c8b730
From f5c88312c3fc5b7dc944eb36c2b8c62a44b78798 Mon Sep 17 00:00:00 2001
c8b730
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
c8b730
Date: Sun, 24 Jan 2021 21:19:51 +0100
c8b730
Subject: [PATCH 2/2] Remove bundled copy of sd-daemon.[ch]
c8b730
c8b730
Let's just use the system version.
c8b730
---
c8b730
 Makefile.am    |  10 +-
c8b730
 rtkit-daemon.c |   2 +-
c8b730
 sd-daemon.c    | 520 -------------------------------------------------
c8b730
 sd-daemon.h    | 282 ---------------------------
c8b730
 4 files changed, 4 insertions(+), 810 deletions(-)
c8b730
 delete mode 100644 sd-daemon.c
c8b730
 delete mode 100644 sd-daemon.h
c8b730
c8b730
diff --git a/Makefile.am b/Makefile.am
c8b730
index febc35535d..2217a80b3c 100644
c8b730
--- a/Makefile.am
c8b730
+++ b/Makefile.am
c8b730
@@ -56,10 +56,10 @@ systemdsystemunit_DATA = \
c8b730
 endif
c8b730
 
c8b730
 rtkit_daemon_SOURCES = \
c8b730
-	rtkit-daemon.c rtkit.h \
c8b730
-	sd-daemon.c sd-daemon.h
c8b730
+	rtkit-daemon.c rtkit.h
c8b730
 rtkit_daemon_LDADD = \
c8b730
-	$(DBUS_LIBS)
c8b730
+	$(DBUS_LIBS) \
c8b730
+        -lsystemd
c8b730
 rtkit_daemon_CFLAGS = \
c8b730
 	$(AM_CFLAGS) \
c8b730
 	$(DBUS_CFLAGS)
c8b730
@@ -93,7 +93,3 @@ EXTRA_DIST += \
c8b730
 
c8b730
 DISTCHECK_CONFIGURE_FLAGS = \
c8b730
 	--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
c8b730
-
c8b730
-update-systemd:
c8b730
-	curl http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c > sd-daemon.c
c8b730
-	curl http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h > sd-daemon.h
c8b730
diff --git a/rtkit-daemon.c b/rtkit-daemon.c
c8b730
index a15e84f8f5..fdff7f63dc 100644
c8b730
--- a/rtkit-daemon.c
c8b730
+++ b/rtkit-daemon.c
c8b730
@@ -50,9 +50,9 @@
c8b730
 #include <dirent.h>
c8b730
 #include <syslog.h>
c8b730
 #include <grp.h>
c8b730
+#include <systemd/sd-daemon.h>
c8b730
 
c8b730
 #include "rtkit.h"
c8b730
-#include "sd-daemon.h"
c8b730
 
c8b730
 #ifndef __linux__
c8b730
 #error "This stuff only works on Linux!"
c8b730
diff --git a/sd-daemon.c b/sd-daemon.c
c8b730
deleted file mode 100644
c8b730
index 485b301023..0000000000
c8b730
--- a/sd-daemon.c
c8b730
+++ /dev/null
c8b730
@@ -1,520 +0,0 @@
c8b730
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
c8b730
-
c8b730
-/***
c8b730
-  Copyright 2010 Lennart Poettering
c8b730
-
c8b730
-  Permission is hereby granted, free of charge, to any person
c8b730
-  obtaining a copy of this software and associated documentation files
c8b730
-  (the "Software"), to deal in the Software without restriction,
c8b730
-  including without limitation the rights to use, copy, modify, merge,
c8b730
-  publish, distribute, sublicense, and/or sell copies of the Software,
c8b730
-  and to permit persons to whom the Software is furnished to do so,
c8b730
-  subject to the following conditions:
c8b730
-
c8b730
-  The above copyright notice and this permission notice shall be
c8b730
-  included in all copies or substantial portions of the Software.
c8b730
-
c8b730
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c8b730
-  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c8b730
-  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c8b730
-  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
c8b730
-  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
c8b730
-  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
c8b730
-  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c8b730
-  SOFTWARE.
c8b730
-***/
c8b730
-
c8b730
-#ifndef _GNU_SOURCE
c8b730
-#  define _GNU_SOURCE
c8b730
-#endif
c8b730
-
c8b730
-#include <sys/types.h>
c8b730
-#include <sys/stat.h>
c8b730
-#include <sys/socket.h>
c8b730
-#include <sys/un.h>
c8b730
-#include <fcntl.h>
c8b730
-#include <netinet/in.h>
c8b730
-#include <stdlib.h>
c8b730
-#include <errno.h>
c8b730
-#include <unistd.h>
c8b730
-#include <string.h>
c8b730
-#include <stdarg.h>
c8b730
-#include <stdio.h>
c8b730
-#include <stddef.h>
c8b730
-#include <limits.h>
c8b730
-
c8b730
-#if defined(__linux__) && !defined(SD_DAEMON_DISABLE_MQ)
c8b730
-#  include <mqueue.h>
c8b730
-#endif
c8b730
-
c8b730
-#include "sd-daemon.h"
c8b730
-
c8b730
-#if (__GNUC__ >= 4)
c8b730
-#  ifdef SD_EXPORT_SYMBOLS
c8b730
-/* Export symbols */
c8b730
-#    define _sd_export_ __attribute__ ((visibility("default")))
c8b730
-#  else
c8b730
-/* Don't export the symbols */
c8b730
-#    define _sd_export_ __attribute__ ((visibility("hidden")))
c8b730
-#  endif
c8b730
-#else
c8b730
-#  define _sd_export_
c8b730
-#endif
c8b730
-
c8b730
-_sd_export_ int sd_listen_fds(int unset_environment) {
c8b730
-
c8b730
-#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
c8b730
-        return 0;
c8b730
-#else
c8b730
-        int r, fd;
c8b730
-        const char *e;
c8b730
-        char *p = NULL;
c8b730
-        unsigned long l;
c8b730
-
c8b730
-        e = getenv("LISTEN_PID");
c8b730
-        if (!e) {
c8b730
-                r = 0;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        errno = 0;
c8b730
-        l = strtoul(e, &p, 10);
c8b730
-
c8b730
-        if (errno > 0) {
c8b730
-                r = -errno;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        if (!p || p == e || *p || l <= 0) {
c8b730
-                r = -EINVAL;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        /* Is this for us? */
c8b730
-        if (getpid() != (pid_t) l) {
c8b730
-                r = 0;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        e = getenv("LISTEN_FDS");
c8b730
-        if (!e) {
c8b730
-                r = 0;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        errno = 0;
c8b730
-        l = strtoul(e, &p, 10);
c8b730
-
c8b730
-        if (errno > 0) {
c8b730
-                r = -errno;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        if (!p || p == e || *p) {
c8b730
-                r = -EINVAL;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
c8b730
-                int flags;
c8b730
-
c8b730
-                flags = fcntl(fd, F_GETFD);
c8b730
-                if (flags < 0) {
c8b730
-                        r = -errno;
c8b730
-                        goto finish;
c8b730
-                }
c8b730
-
c8b730
-                if (flags & FD_CLOEXEC)
c8b730
-                        continue;
c8b730
-
c8b730
-                if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
c8b730
-                        r = -errno;
c8b730
-                        goto finish;
c8b730
-                }
c8b730
-        }
c8b730
-
c8b730
-        r = (int) l;
c8b730
-
c8b730
-finish:
c8b730
-        if (unset_environment) {
c8b730
-                unsetenv("LISTEN_PID");
c8b730
-                unsetenv("LISTEN_FDS");
c8b730
-        }
c8b730
-
c8b730
-        return r;
c8b730
-#endif
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_is_fifo(int fd, const char *path) {
c8b730
-        struct stat st_fd;
c8b730
-
c8b730
-        if (fd < 0)
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        if (fstat(fd, &st_fd) < 0)
c8b730
-                return -errno;
c8b730
-
c8b730
-        if (!S_ISFIFO(st_fd.st_mode))
c8b730
-                return 0;
c8b730
-
c8b730
-        if (path) {
c8b730
-                struct stat st_path;
c8b730
-
c8b730
-                if (stat(path, &st_path) < 0) {
c8b730
-
c8b730
-                        if (errno == ENOENT || errno == ENOTDIR)
c8b730
-                                return 0;
c8b730
-
c8b730
-                        return -errno;
c8b730
-                }
c8b730
-
c8b730
-                return
c8b730
-                        st_path.st_dev == st_fd.st_dev &&
c8b730
-                        st_path.st_ino == st_fd.st_ino;
c8b730
-        }
c8b730
-
c8b730
-        return 1;
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_is_special(int fd, const char *path) {
c8b730
-        struct stat st_fd;
c8b730
-
c8b730
-        if (fd < 0)
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        if (fstat(fd, &st_fd) < 0)
c8b730
-                return -errno;
c8b730
-
c8b730
-        if (!S_ISREG(st_fd.st_mode) && !S_ISCHR(st_fd.st_mode))
c8b730
-                return 0;
c8b730
-
c8b730
-        if (path) {
c8b730
-                struct stat st_path;
c8b730
-
c8b730
-                if (stat(path, &st_path) < 0) {
c8b730
-
c8b730
-                        if (errno == ENOENT || errno == ENOTDIR)
c8b730
-                                return 0;
c8b730
-
c8b730
-                        return -errno;
c8b730
-                }
c8b730
-
c8b730
-                if (S_ISREG(st_fd.st_mode) && S_ISREG(st_path.st_mode))
c8b730
-                        return
c8b730
-                                st_path.st_dev == st_fd.st_dev &&
c8b730
-                                st_path.st_ino == st_fd.st_ino;
c8b730
-                else if (S_ISCHR(st_fd.st_mode) && S_ISCHR(st_path.st_mode))
c8b730
-                        return st_path.st_rdev == st_fd.st_rdev;
c8b730
-                else
c8b730
-                        return 0;
c8b730
-        }
c8b730
-
c8b730
-        return 1;
c8b730
-}
c8b730
-
c8b730
-static int sd_is_socket_internal(int fd, int type, int listening) {
c8b730
-        struct stat st_fd;
c8b730
-
c8b730
-        if (fd < 0 || type < 0)
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        if (fstat(fd, &st_fd) < 0)
c8b730
-                return -errno;
c8b730
-
c8b730
-        if (!S_ISSOCK(st_fd.st_mode))
c8b730
-                return 0;
c8b730
-
c8b730
-        if (type != 0) {
c8b730
-                int other_type = 0;
c8b730
-                socklen_t l = sizeof(other_type);
c8b730
-
c8b730
-                if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0)
c8b730
-                        return -errno;
c8b730
-
c8b730
-                if (l != sizeof(other_type))
c8b730
-                        return -EINVAL;
c8b730
-
c8b730
-                if (other_type != type)
c8b730
-                        return 0;
c8b730
-        }
c8b730
-
c8b730
-        if (listening >= 0) {
c8b730
-                int accepting = 0;
c8b730
-                socklen_t l = sizeof(accepting);
c8b730
-
c8b730
-                if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0)
c8b730
-                        return -errno;
c8b730
-
c8b730
-                if (l != sizeof(accepting))
c8b730
-                        return -EINVAL;
c8b730
-
c8b730
-                if (!accepting != !listening)
c8b730
-                        return 0;
c8b730
-        }
c8b730
-
c8b730
-        return 1;
c8b730
-}
c8b730
-
c8b730
-union sockaddr_union {
c8b730
-        struct sockaddr sa;
c8b730
-        struct sockaddr_in in4;
c8b730
-        struct sockaddr_in6 in6;
c8b730
-        struct sockaddr_un un;
c8b730
-        struct sockaddr_storage storage;
c8b730
-};
c8b730
-
c8b730
-_sd_export_ int sd_is_socket(int fd, int family, int type, int listening) {
c8b730
-        int r;
c8b730
-
c8b730
-        if (family < 0)
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        r = sd_is_socket_internal(fd, type, listening);
c8b730
-        if (r <= 0)
c8b730
-                return r;
c8b730
-
c8b730
-        if (family > 0) {
c8b730
-                union sockaddr_union sockaddr = {};
c8b730
-                socklen_t l = sizeof(sockaddr);
c8b730
-
c8b730
-                if (getsockname(fd, &sockaddr.sa, &l) < 0)
c8b730
-                        return -errno;
c8b730
-
c8b730
-                if (l < sizeof(sa_family_t))
c8b730
-                        return -EINVAL;
c8b730
-
c8b730
-                return sockaddr.sa.sa_family == family;
c8b730
-        }
c8b730
-
c8b730
-        return 1;
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) {
c8b730
-        union sockaddr_union sockaddr = {};
c8b730
-        socklen_t l = sizeof(sockaddr);
c8b730
-        int r;
c8b730
-
c8b730
-        if (family != 0 && family != AF_INET && family != AF_INET6)
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        r = sd_is_socket_internal(fd, type, listening);
c8b730
-        if (r <= 0)
c8b730
-                return r;
c8b730
-
c8b730
-        if (getsockname(fd, &sockaddr.sa, &l) < 0)
c8b730
-                return -errno;
c8b730
-
c8b730
-        if (l < sizeof(sa_family_t))
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        if (sockaddr.sa.sa_family != AF_INET &&
c8b730
-            sockaddr.sa.sa_family != AF_INET6)
c8b730
-                return 0;
c8b730
-
c8b730
-        if (family > 0)
c8b730
-                if (sockaddr.sa.sa_family != family)
c8b730
-                        return 0;
c8b730
-
c8b730
-        if (port > 0) {
c8b730
-                if (sockaddr.sa.sa_family == AF_INET) {
c8b730
-                        if (l < sizeof(struct sockaddr_in))
c8b730
-                                return -EINVAL;
c8b730
-
c8b730
-                        return htons(port) == sockaddr.in4.sin_port;
c8b730
-                } else {
c8b730
-                        if (l < sizeof(struct sockaddr_in6))
c8b730
-                                return -EINVAL;
c8b730
-
c8b730
-                        return htons(port) == sockaddr.in6.sin6_port;
c8b730
-                }
c8b730
-        }
c8b730
-
c8b730
-        return 1;
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) {
c8b730
-        union sockaddr_union sockaddr = {};
c8b730
-        socklen_t l = sizeof(sockaddr);
c8b730
-        int r;
c8b730
-
c8b730
-        r = sd_is_socket_internal(fd, type, listening);
c8b730
-        if (r <= 0)
c8b730
-                return r;
c8b730
-
c8b730
-        if (getsockname(fd, &sockaddr.sa, &l) < 0)
c8b730
-                return -errno;
c8b730
-
c8b730
-        if (l < sizeof(sa_family_t))
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        if (sockaddr.sa.sa_family != AF_UNIX)
c8b730
-                return 0;
c8b730
-
c8b730
-        if (path) {
c8b730
-                if (length == 0)
c8b730
-                        length = strlen(path);
c8b730
-
c8b730
-                if (length == 0)
c8b730
-                        /* Unnamed socket */
c8b730
-                        return l == offsetof(struct sockaddr_un, sun_path);
c8b730
-
c8b730
-                if (path[0])
c8b730
-                        /* Normal path socket */
c8b730
-                        return
c8b730
-                                (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) &&
c8b730
-                                memcmp(path, sockaddr.un.sun_path, length+1) == 0;
c8b730
-                else
c8b730
-                        /* Abstract namespace socket */
c8b730
-                        return
c8b730
-                                (l == offsetof(struct sockaddr_un, sun_path) + length) &&
c8b730
-                                memcmp(path, sockaddr.un.sun_path, length) == 0;
c8b730
-        }
c8b730
-
c8b730
-        return 1;
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_is_mq(int fd, const char *path) {
c8b730
-#if !defined(__linux__) || defined(SD_DAEMON_DISABLE_MQ)
c8b730
-        return 0;
c8b730
-#else
c8b730
-        struct mq_attr attr;
c8b730
-
c8b730
-        if (fd < 0)
c8b730
-                return -EINVAL;
c8b730
-
c8b730
-        if (mq_getattr(fd, &attr) < 0)
c8b730
-                return -errno;
c8b730
-
c8b730
-        if (path) {
c8b730
-                char fpath[PATH_MAX];
c8b730
-                struct stat a, b;
c8b730
-
c8b730
-                if (path[0] != '/')
c8b730
-                        return -EINVAL;
c8b730
-
c8b730
-                if (fstat(fd, &a) < 0)
c8b730
-                        return -errno;
c8b730
-
c8b730
-                strncpy(stpcpy(fpath, "/dev/mqueue"), path, sizeof(fpath) - 12);
c8b730
-                fpath[sizeof(fpath)-1] = 0;
c8b730
-
c8b730
-                if (stat(fpath, &b) < 0)
c8b730
-                        return -errno;
c8b730
-
c8b730
-                if (a.st_dev != b.st_dev ||
c8b730
-                    a.st_ino != b.st_ino)
c8b730
-                        return 0;
c8b730
-        }
c8b730
-
c8b730
-        return 1;
c8b730
-#endif
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_notify(int unset_environment, const char *state) {
c8b730
-#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC)
c8b730
-        return 0;
c8b730
-#else
c8b730
-        int fd = -1, r;
c8b730
-        struct msghdr msghdr;
c8b730
-        struct iovec iovec;
c8b730
-        union sockaddr_union sockaddr;
c8b730
-        const char *e;
c8b730
-
c8b730
-        if (!state) {
c8b730
-                r = -EINVAL;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        e = getenv("NOTIFY_SOCKET");
c8b730
-        if (!e)
c8b730
-                return 0;
c8b730
-
c8b730
-        /* Must be an abstract socket, or an absolute path */
c8b730
-        if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
c8b730
-                r = -EINVAL;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
c8b730
-        if (fd < 0) {
c8b730
-                r = -errno;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        memset(&sockaddr, 0, sizeof(sockaddr));
c8b730
-        sockaddr.sa.sa_family = AF_UNIX;
c8b730
-        strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
c8b730
-
c8b730
-        if (sockaddr.un.sun_path[0] == '@')
c8b730
-                sockaddr.un.sun_path[0] = 0;
c8b730
-
c8b730
-        memset(&iovec, 0, sizeof(iovec));
c8b730
-        iovec.iov_base = (char*) state;
c8b730
-        iovec.iov_len = strlen(state);
c8b730
-
c8b730
-        memset(&msghdr, 0, sizeof(msghdr));
c8b730
-        msghdr.msg_name = &sockaddr;
c8b730
-        msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
c8b730
-
c8b730
-        if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
c8b730
-                msghdr.msg_namelen = sizeof(struct sockaddr_un);
c8b730
-
c8b730
-        msghdr.msg_iov = &iovec;
c8b730
-        msghdr.msg_iovlen = 1;
c8b730
-
c8b730
-        if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
c8b730
-                r = -errno;
c8b730
-                goto finish;
c8b730
-        }
c8b730
-
c8b730
-        r = 1;
c8b730
-
c8b730
-finish:
c8b730
-        if (unset_environment)
c8b730
-                unsetenv("NOTIFY_SOCKET");
c8b730
-
c8b730
-        if (fd >= 0)
c8b730
-                close(fd);
c8b730
-
c8b730
-        return r;
c8b730
-#endif
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_notifyf(int unset_environment, const char *format, ...) {
c8b730
-#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
c8b730
-        return 0;
c8b730
-#else
c8b730
-        va_list ap;
c8b730
-        char *p = NULL;
c8b730
-        int r;
c8b730
-
c8b730
-        va_start(ap, format);
c8b730
-        r = vasprintf(&p, format, ap);
c8b730
-        va_end(ap);
c8b730
-
c8b730
-        if (r < 0 || !p)
c8b730
-                return -ENOMEM;
c8b730
-
c8b730
-        r = sd_notify(unset_environment, p);
c8b730
-        free(p);
c8b730
-
c8b730
-        return r;
c8b730
-#endif
c8b730
-}
c8b730
-
c8b730
-_sd_export_ int sd_booted(void) {
c8b730
-#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
c8b730
-        return 0;
c8b730
-#else
c8b730
-        struct stat st;
c8b730
-
c8b730
-        /* We test whether the runtime unit file directory has been
c8b730
-         * created. This takes place in mount-setup.c, so is
c8b730
-         * guaranteed to happen very early during boot. */
c8b730
-
c8b730
-        if (lstat("/run/systemd/system/", &st) < 0)
c8b730
-                return 0;
c8b730
-
c8b730
-        return !!S_ISDIR(st.st_mode);
c8b730
-#endif
c8b730
-}
c8b730
diff --git a/sd-daemon.h b/sd-daemon.h
c8b730
deleted file mode 100644
c8b730
index daa3f4c857..0000000000
c8b730
--- a/sd-daemon.h
c8b730
+++ /dev/null
c8b730
@@ -1,282 +0,0 @@
c8b730
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
c8b730
-
c8b730
-#ifndef foosddaemonhfoo
c8b730
-#define foosddaemonhfoo
c8b730
-
c8b730
-/***
c8b730
-  Copyright 2010 Lennart Poettering
c8b730
-
c8b730
-  Permission is hereby granted, free of charge, to any person
c8b730
-  obtaining a copy of this software and associated documentation files
c8b730
-  (the "Software"), to deal in the Software without restriction,
c8b730
-  including without limitation the rights to use, copy, modify, merge,
c8b730
-  publish, distribute, sublicense, and/or sell copies of the Software,
c8b730
-  and to permit persons to whom the Software is furnished to do so,
c8b730
-  subject to the following conditions:
c8b730
-
c8b730
-  The above copyright notice and this permission notice shall be
c8b730
-  included in all copies or substantial portions of the Software.
c8b730
-
c8b730
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c8b730
-  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c8b730
-  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c8b730
-  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
c8b730
-  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
c8b730
-  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
c8b730
-  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c8b730
-  SOFTWARE.
c8b730
-***/
c8b730
-
c8b730
-#include <sys/types.h>
c8b730
-#include <inttypes.h>
c8b730
-
c8b730
-#ifdef __cplusplus
c8b730
-extern "C" {
c8b730
-#endif
c8b730
-
c8b730
-/*
c8b730
-  Reference implementation of a few systemd related interfaces for
c8b730
-  writing daemons. These interfaces are trivial to implement. To
c8b730
-  simplify porting we provide this reference implementation.
c8b730
-  Applications are welcome to reimplement the algorithms described
c8b730
-  here if they do not want to include these two source files.
c8b730
-
c8b730
-  The following functionality is provided:
c8b730
-
c8b730
-  - Support for logging with log levels on stderr
c8b730
-  - File descriptor passing for socket-based activation
c8b730
-  - Daemon startup and status notification
c8b730
-  - Detection of systemd boots
c8b730
-
c8b730
-  You may compile this with -DDISABLE_SYSTEMD to disable systemd
c8b730
-  support. This makes all those calls NOPs that are directly related to
c8b730
-  systemd (i.e. only sd_is_xxx() will stay useful).
c8b730
-
c8b730
-  Since this is drop-in code we don't want any of our symbols to be
c8b730
-  exported in any case. Hence we declare hidden visibility for all of
c8b730
-  them.
c8b730
-
c8b730
-  You may find an up-to-date version of these source files online:
c8b730
-
c8b730
-  http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h
c8b730
-  http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c
c8b730
-
c8b730
-  This should compile on non-Linux systems, too, but with the
c8b730
-  exception of the sd_is_xxx() calls all functions will become NOPs.
c8b730
-
c8b730
-  See sd-daemon(3) for more information.
c8b730
-*/
c8b730
-
c8b730
-#ifndef _sd_printf_attr_
c8b730
-#  if __GNUC__ >= 4
c8b730
-#    define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
c8b730
-#  else
c8b730
-#    define _sd_printf_attr_(a,b)
c8b730
-#  endif
c8b730
-#endif
c8b730
-
c8b730
-/*
c8b730
-  Log levels for usage on stderr:
c8b730
-
c8b730
-          fprintf(stderr, SD_NOTICE "Hello World!\n");
c8b730
-
c8b730
-  This is similar to printk() usage in the kernel.
c8b730
-*/
c8b730
-#define SD_EMERG   "<0>"  /* system is unusable */
c8b730
-#define SD_ALERT   "<1>"  /* action must be taken immediately */
c8b730
-#define SD_CRIT    "<2>"  /* critical conditions */
c8b730
-#define SD_ERR     "<3>"  /* error conditions */
c8b730
-#define SD_WARNING "<4>"  /* warning conditions */
c8b730
-#define SD_NOTICE  "<5>"  /* normal but significant condition */
c8b730
-#define SD_INFO    "<6>"  /* informational */
c8b730
-#define SD_DEBUG   "<7>"  /* debug-level messages */
c8b730
-
c8b730
-/* The first passed file descriptor is fd 3 */
c8b730
-#define SD_LISTEN_FDS_START 3
c8b730
-
c8b730
-/*
c8b730
-  Returns how many file descriptors have been passed, or a negative
c8b730
-  errno code on failure. Optionally, removes the $LISTEN_FDS and
c8b730
-  $LISTEN_PID file descriptors from the environment (recommended, but
c8b730
-  problematic in threaded environments). If r is the return value of
c8b730
-  this function you'll find the file descriptors passed as fds
c8b730
-  SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
c8b730
-  errno style error code on failure. This function call ensures that
c8b730
-  the FD_CLOEXEC flag is set for the passed file descriptors, to make
c8b730
-  sure they are not passed on to child processes. If FD_CLOEXEC shall
c8b730
-  not be set, the caller needs to unset it after this call for all file
c8b730
-  descriptors that are used.
c8b730
-
c8b730
-  See sd_listen_fds(3) for more information.
c8b730
-*/
c8b730
-int sd_listen_fds(int unset_environment);
c8b730
-
c8b730
-/*
c8b730
-  Helper call for identifying a passed file descriptor. Returns 1 if
c8b730
-  the file descriptor is a FIFO in the file system stored under the
c8b730
-  specified path, 0 otherwise. If path is NULL a path name check will
c8b730
-  not be done and the call only verifies if the file descriptor
c8b730
-  refers to a FIFO. Returns a negative errno style error code on
c8b730
-  failure.
c8b730
-
c8b730
-  See sd_is_fifo(3) for more information.
c8b730
-*/
c8b730
-int sd_is_fifo(int fd, const char *path);
c8b730
-
c8b730
-/*
c8b730
-  Helper call for identifying a passed file descriptor. Returns 1 if
c8b730
-  the file descriptor is a special character device on the file
c8b730
-  system stored under the specified path, 0 otherwise.
c8b730
-  If path is NULL a path name check will not be done and the call
c8b730
-  only verifies if the file descriptor refers to a special character.
c8b730
-  Returns a negative errno style error code on failure.
c8b730
-
c8b730
-  See sd_is_special(3) for more information.
c8b730
-*/
c8b730
-int sd_is_special(int fd, const char *path);
c8b730
-
c8b730
-/*
c8b730
-  Helper call for identifying a passed file descriptor. Returns 1 if
c8b730
-  the file descriptor is a socket of the specified family (AF_INET,
c8b730
-  ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
c8b730
-  family is 0 a socket family check will not be done. If type is 0 a
c8b730
-  socket type check will not be done and the call only verifies if
c8b730
-  the file descriptor refers to a socket. If listening is > 0 it is
c8b730
-  verified that the socket is in listening mode. (i.e. listen() has
c8b730
-  been called) If listening is == 0 it is verified that the socket is
c8b730
-  not in listening mode. If listening is < 0 no listening mode check
c8b730
-  is done. Returns a negative errno style error code on failure.
c8b730
-
c8b730
-  See sd_is_socket(3) for more information.
c8b730
-*/
c8b730
-int sd_is_socket(int fd, int family, int type, int listening);
c8b730
-
c8b730
-/*
c8b730
-  Helper call for identifying a passed file descriptor. Returns 1 if
c8b730
-  the file descriptor is an Internet socket, of the specified family
c8b730
-  (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
c8b730
-  SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
c8b730
-  check is not done. If type is 0 a socket type check will not be
c8b730
-  done. If port is 0 a socket port check will not be done. The
c8b730
-  listening flag is used the same way as in sd_is_socket(). Returns a
c8b730
-  negative errno style error code on failure.
c8b730
-
c8b730
-  See sd_is_socket_inet(3) for more information.
c8b730
-*/
c8b730
-int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port);
c8b730
-
c8b730
-/*
c8b730
-  Helper call for identifying a passed file descriptor. Returns 1 if
c8b730
-  the file descriptor is an AF_UNIX socket of the specified type
c8b730
-  (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
c8b730
-  a socket type check will not be done. If path is NULL a socket path
c8b730
-  check will not be done. For normal AF_UNIX sockets set length to
c8b730
-  0. For abstract namespace sockets set length to the length of the
c8b730
-  socket name (including the initial 0 byte), and pass the full
c8b730
-  socket path in path (including the initial 0 byte). The listening
c8b730
-  flag is used the same way as in sd_is_socket(). Returns a negative
c8b730
-  errno style error code on failure.
c8b730
-
c8b730
-  See sd_is_socket_unix(3) for more information.
c8b730
-*/
c8b730
-int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length);
c8b730
-
c8b730
-/*
c8b730
-  Helper call for identifying a passed file descriptor. Returns 1 if
c8b730
-  the file descriptor is a POSIX Message Queue of the specified name,
c8b730
-  0 otherwise. If path is NULL a message queue name check is not
c8b730
-  done. Returns a negative errno style error code on failure.
c8b730
-*/
c8b730
-int sd_is_mq(int fd, const char *path);
c8b730
-
c8b730
-/*
c8b730
-  Informs systemd about changed daemon state. This takes a number of
c8b730
-  newline separated environment-style variable assignments in a
c8b730
-  string. The following variables are known:
c8b730
-
c8b730
-     READY=1      Tells systemd that daemon startup is finished (only
c8b730
-                  relevant for services of Type=notify). The passed
c8b730
-                  argument is a boolean "1" or "0". Since there is
c8b730
-                  little value in signaling non-readiness the only
c8b730
-                  value daemons should send is "READY=1".
c8b730
-
c8b730
-     STATUS=...   Passes a single-line status string back to systemd
c8b730
-                  that describes the daemon state. This is free-from
c8b730
-                  and can be used for various purposes: general state
c8b730
-                  feedback, fsck-like programs could pass completion
c8b730
-                  percentages and failing programs could pass a human
c8b730
-                  readable error message. Example: "STATUS=Completed
c8b730
-                  66% of file system check..."
c8b730
-
c8b730
-     ERRNO=...    If a daemon fails, the errno-style error code,
c8b730
-                  formatted as string. Example: "ERRNO=2" for ENOENT.
c8b730
-
c8b730
-     BUSERROR=... If a daemon fails, the D-Bus error-style error
c8b730
-                  code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut"
c8b730
-
c8b730
-     MAINPID=...  The main pid of a daemon, in case systemd did not
c8b730
-                  fork off the process itself. Example: "MAINPID=4711"
c8b730
-
c8b730
-     WATCHDOG=1   Tells systemd to update the watchdog timestamp.
c8b730
-                  Services using this feature should do this in
c8b730
-                  regular intervals. A watchdog framework can use the
c8b730
-                  timestamps to detect failed services.
c8b730
-
c8b730
-  Daemons can choose to send additional variables. However, it is
c8b730
-  recommended to prefix variable names not listed above with X_.
c8b730
-
c8b730
-  Returns a negative errno-style error code on failure. Returns > 0
c8b730
-  if systemd could be notified, 0 if it couldn't possibly because
c8b730
-  systemd is not running.
c8b730
-
c8b730
-  Example: When a daemon finished starting up, it could issue this
c8b730
-  call to notify systemd about it:
c8b730
-
c8b730
-     sd_notify(0, "READY=1");
c8b730
-
c8b730
-  See sd_notifyf() for more complete examples.
c8b730
-
c8b730
-  See sd_notify(3) for more information.
c8b730
-*/
c8b730
-int sd_notify(int unset_environment, const char *state);
c8b730
-
c8b730
-/*
c8b730
-  Similar to sd_notify() but takes a format string.
c8b730
-
c8b730
-  Example 1: A daemon could send the following after initialization:
c8b730
-
c8b730
-     sd_notifyf(0, "READY=1\n"
c8b730
-                   "STATUS=Processing requests...\n"
c8b730
-                   "MAINPID=%lu",
c8b730
-                   (unsigned long) getpid());
c8b730
-
c8b730
-  Example 2: A daemon could send the following shortly before
c8b730
-  exiting, on failure:
c8b730
-
c8b730
-     sd_notifyf(0, "STATUS=Failed to start up: %s\n"
c8b730
-                   "ERRNO=%i",
c8b730
-                   strerror(errno),
c8b730
-                   errno);
c8b730
-
c8b730
-  See sd_notifyf(3) for more information.
c8b730
-*/
c8b730
-int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3);
c8b730
-
c8b730
-/*
c8b730
-  Returns > 0 if the system was booted with systemd. Returns < 0 on
c8b730
-  error. Returns 0 if the system was not booted with systemd. Note
c8b730
-  that all of the functions above handle non-systemd boots just
c8b730
-  fine. You should NOT protect them with a call to this function. Also
c8b730
-  note that this function checks whether the system, not the user
c8b730
-  session is controlled by systemd. However the functions above work
c8b730
-  for both user and system services.
c8b730
-
c8b730
-  See sd_booted(3) for more information.
c8b730
-*/
c8b730
-int sd_booted(void);
c8b730
-
c8b730
-#ifdef __cplusplus
c8b730
-}
c8b730
-#endif
c8b730
-
c8b730
-#endif