[systemd-commits] 4 commits - execute.c execute.h fixme initctl.c load-fragment.c logger.c Makefile.am sd-daemon.c sd-daemon.h

Lennart Poettering lennart at kemper.freedesktop.org
Sat May 15 16:49:55 PDT 2010


 Makefile.am     |    8 ++-
 execute.c       |    6 +-
 execute.h       |    1 
 fixme           |   66 ++++++++++++++++--------------
 initctl.c       |   66 +++++++-----------------------
 load-fragment.c |    1 
 logger.c        |  123 +++++++++++++++++++++++++++-----------------------------
 sd-daemon.c     |   96 +++++++++++++++++++++++++++++++++++++++++++
 sd-daemon.h     |   61 +++++++++++++++++++++++++++
 9 files changed, 281 insertions(+), 147 deletions(-)

New commits:
commit 129126f3792c452c871c0a096dcb1020c4d8096b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun May 16 01:49:45 2010 +0200

    fixme: update todo list

diff --git a/fixme b/fixme
index 3618d54..969c6cd 100644
--- a/fixme
+++ b/fixme
@@ -1,49 +1,53 @@
+* timer
 
-- trigger mounting; mounts might take time, need to be executed asynchronously in a forked process?
+* enforce max number of concurrent connection limit in sockets.
 
-- need gc for active jobs that nothing cares for
+* complete dbus exposure
 
-- need gc for units that are not referenced anymore
+* make conf parser work more like .desktop parsers
 
-- refreshing of units (i.e. reload config files)
+* implicitly import "defaults" settings file into all types
 
-- further dbusification (i.e. export dependency information, per-unit-type data)
+* write .service file install tool
 
-- cgroupsification
+* service startup should be delayed if the matching socket is being started
 
-- snapshot system
+* add #ifdefs for non-redhat builds in sysv parser
 
-- add a job mode which shuts everything down but what is requested
+* add #ifdefs for non-sysv builds
 
-- implement timer
+* bootchart hookup
 
-- implement automount
+* dbus.service and syslog.service should be symlinked not ifdef to the right distro-specific names
 
-- create session/pgroup for child processes? handle input on console properly? interactive fsck? interactive luks password?
+* reinvestigate random seed, hwclock
 
-- fs namespaces
+* rework sysv stuff to have SPECIAL_SYSV_BEFORE, SPECIAL_SYSV_AFTER instead SPECIAL_RCSYSINIT
 
-- templating/instances
+* introduce serialized mode
 
-- verify fragment data after loading: refuse cycles on yourself, service units contradicting, more than one Start executable, ...
+* when refusing start due to ratelimit, enter restart state
 
-- .socket needs to be notified not only by .service state changes, but also unsuccessful start jobs
+* "disabled" load state?
 
-- we probably cannot use glibc's syslog() for logging, since it
-  presumably uses the logging socket in blocking mode which might
-  trigger a deadlock if syslog does not process the socket anymore
-  (maybe because it is restarted) and the socket buffer is full.
+* uid are 32bit
 
-- in udev/mount if properties change we need to delete the old
-  settings and install the new settings. Deleting the old settings is
-  currently missing.
+* %m in printf() instead of strerror();
 
-- ability to kill services? i.e. in contrast to stopping them, go directly
-  into killing mode?
+* gc: don't reap broken services
+
+* iCalendar semantics for the timer stuff (RFC2445)
 
-- restart-on-success, restart-on-failure, restart-on-abort, restart-on-name-gnone
+* autofs für /dev/mqueue usw.
 
-- port over to LISTEN_FDS/LISTEN_PID:
+* provide sysv-like command line utilities
+
+* Add OnlyByDependency
+
+* ability to kill services? i.e. in contrast to stopping them, go directly
+  into killing mode?
+
+* port over to LISTEN_FDS/LISTEN_PID:
 
    - uuidd    DONE
    - nscd     DONE
@@ -59,10 +63,12 @@
    - avahi-daemon (/var/run/avahi-daemon/socket)
    - distccd
 
-- teach dbus to talk to systemd when autospawning services
+* teach dbus to talk to systemd when autospawning services
+
+* unix sockets chown()/chgrp()
 
-- unix sockets chown()/chgrp()
+Regularly:
 
-- watch dbus names for figuring out when a service has finished startup/goes down
+* look for close() vs. close_nointr() vs. close_nointr_nofail()
 
-- initialize console tty on startup
+* check for strerror(r) instead of strerror(-r)
commit 4f4a1dbf2171aa62da04d2e3b6945e8992139d14
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun May 16 01:46:35 2010 +0200

    logger: support printk() style priority prefixes

diff --git a/execute.c b/execute.c
index a36e52b..12f5145 100644
--- a/execute.c
+++ b/execute.c
@@ -187,10 +187,12 @@ static int connect_logger_as(const ExecContext *context, ExecOutput output, cons
         dprintf(fd,
                 "%s\n"
                 "%i\n"
-                "%s\n",
+                "%s\n"
+                "%i\n",
                 output == EXEC_OUTPUT_KERNEL ? "kmsg" : "syslog",
                 context->syslog_priority,
-                context->syslog_identifier ? context->syslog_identifier : ident);
+                context->syslog_identifier ? context->syslog_identifier : ident,
+                !context->syslog_no_prefix);
 
         if (fd != nfd) {
                 r = dup2(fd, nfd) < 0 ? -errno : nfd;
diff --git a/execute.h b/execute.h
index 5c2d157..be73542 100644
--- a/execute.h
+++ b/execute.h
@@ -98,6 +98,7 @@ struct ExecContext {
 
         int syslog_priority;
         char *syslog_identifier;
+        bool syslog_no_prefix;
 
         char *tty_path;
 
diff --git a/load-fragment.c b/load-fragment.c
index deebba3..148a579 100644
--- a/load-fragment.c
+++ b/load-fragment.c
@@ -1198,6 +1198,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "SyslogIdentifier",       config_parse_string,          &(context).syslog_identifier,                    section   }, \
                 { "SyslogFacility",         config_parse_facility,        &(context).syslog_priority,                      section   }, \
                 { "SyslogLevel",            config_parse_level,           &(context).syslog_priority,                      section   }, \
+                { "SyslogNoPrefix",         config_parse_bool,            &(context).syslog_no_prefix,                     section   }, \
                 { "Capabilities",           config_parse_capabilities,    &(context),                                      section   }, \
                 { "SecureBits",             config_parse_secure_bits,     &(context),                                      section   }, \
                 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context),                                      section   }, \
diff --git a/logger.c b/logger.c
index b7c8ab8..f81d2c5 100644
--- a/logger.c
+++ b/logger.c
@@ -55,10 +55,16 @@ typedef struct Server {
         unsigned n_streams;
 } Server;
 
+typedef enum StreamTarget {
+        STREAM_SYSLOG,
+        STREAM_KMSG
+} StreamTarget;
+
 typedef enum StreamState {
-        STREAM_LOG_TARGET,
+        STREAM_TARGET,
         STREAM_PRIORITY,
         STREAM_PROCESS,
+        STREAM_PREFIX,
         STREAM_RUNNING
 } StreamState;
 
@@ -75,6 +81,8 @@ struct Stream {
         pid_t pid;
         uid_t uid;
 
+        bool prefix;
+
         char buffer[STREAM_BUFFER];
         size_t length;
 
@@ -85,10 +93,24 @@ static int stream_log(Stream *s, char *p, usec_t timestamp) {
 
         char header_priority[16], header_time[64], header_pid[16];
         struct iovec iovec[5];
+        int priority;
 
         assert(s);
         assert(p);
 
+        priority = s->priority;
+
+        if (s->prefix &&
+            p[0] == '<' &&
+            p[1] >= '0' && p[1] <= '7' &&
+            p[2] == '>') {
+
+                /* Detected priority prefix */
+                priority = LOG_MAKEPRI(LOG_FAC(priority), (p[1] - '0'));
+
+                p += 3;
+        }
+
         if (*p == 0)
                 return 0;
 
@@ -105,10 +127,10 @@ static int stream_log(Stream *s, char *p, usec_t timestamp) {
          */
 
         snprintf(header_priority, sizeof(header_priority), "<%i>",
-                 s->target == LOG_TARGET_SYSLOG ? s->priority : LOG_PRI(s->priority));
+                 s->target == STREAM_SYSLOG ? priority : LOG_PRI(priority));
         char_array_0(header_priority);
 
-        if (s->target == LOG_TARGET_SYSLOG) {
+        if (s->target == STREAM_SYSLOG) {
                 time_t t;
                 struct tm *tm;
 
@@ -126,7 +148,7 @@ static int stream_log(Stream *s, char *p, usec_t timestamp) {
         zero(iovec);
         IOVEC_SET_STRING(iovec[0], header_priority);
 
-        if (s->target == LOG_TARGET_SYSLOG) {
+        if (s->target == STREAM_SYSLOG) {
                 struct msghdr msghdr;
 
                 IOVEC_SET_STRING(iovec[1], header_time);
@@ -141,7 +163,7 @@ static int stream_log(Stream *s, char *p, usec_t timestamp) {
                 if (sendmsg(s->server->syslog_fd, &msghdr, MSG_NOSIGNAL) < 0)
                         return -errno;
 
-        } else if (s->target == LOG_TARGET_KMSG) {
+        } else if (s->target == STREAM_KMSG) {
                 IOVEC_SET_STRING(iovec[1], s->process);
                 IOVEC_SET_STRING(iovec[2], header_pid);
                 IOVEC_SET_STRING(iovec[3], p);
@@ -165,13 +187,13 @@ static int stream_line(Stream *s, char *p, usec_t timestamp) {
 
         switch (s->state) {
 
-        case STREAM_LOG_TARGET:
+        case STREAM_TARGET:
                 if (streq(p, "syslog"))
-                        s->target = LOG_TARGET_SYSLOG;
+                        s->target = STREAM_SYSLOG;
                 else if (streq(p, "kmsg")) {
 
                         if (s->server->kmsg_fd >= 0 && s->uid == 0)
-                                s->target = LOG_TARGET_KMSG;
+                                s->target = STREAM_KMSG;
                         else {
                                 log_warning("/dev/kmsg logging not available.");
                                 return -EPERM;
@@ -201,6 +223,15 @@ static int stream_line(Stream *s, char *p, usec_t timestamp) {
                 if (!(s->process = strdup(p)))
                         return -ENOMEM;
 
+                s->state = STREAM_PREFIX;
+                return 0;
+
+        case STREAM_PREFIX:
+
+                if ((r = parse_boolean(p)) < 0)
+                        return r;
+
+                s->prefix = r;
                 s->state = STREAM_RUNNING;
                 return 0;
 
commit 8bfcc8ea65e29b1ebcd3d0fff600fe1638a85ec7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun May 16 01:45:52 2010 +0200

    logger,initctl: port to daemon reference implementation

diff --git a/Makefile.am b/Makefile.am
index d79a523..cf56386 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -207,11 +207,15 @@ test_loopback_LDADD = $(systemd_LDADD)
 
 systemd_logger_SOURCES = \
 	$(BASIC_SOURCES) \
-	logger.c
+	logger.c \
+	sd-daemon.c \
+	sd-daemon.h
 
 systemd_initctl_SOURCES = \
 	$(BASIC_SOURCES) \
-	initctl.c
+	initctl.c \
+	sd-daemon.c \
+	sd-daemon.h
 
 systemd_initctl_CPPFLAGS = \
 	$(AM_CPPFLAGS) \
diff --git a/initctl.c b/initctl.c
index 6dcc86f..9d8ecee 100644
--- a/initctl.c
+++ b/initctl.c
@@ -40,8 +40,8 @@
 #include "list.h"
 #include "initreq.h"
 #include "manager.h"
+#include "sd-daemon.h"
 
-#define SERVER_FD_START 3
 #define SERVER_FD_MAX 16
 #define TIMEOUT ((int) (10*MSEC_PER_SEC))
 
@@ -246,49 +246,6 @@ static void fifo_free(Fifo *f) {
         free(f);
 }
 
-static int verify_environment(unsigned *n_sockets) {
-        unsigned long long pid;
-        const char *e;
-        int r;
-        unsigned ns;
-
-        assert_se(n_sockets);
-
-        if (!(e = getenv("LISTEN_PID"))) {
-                log_error("Missing $LISTEN_PID environment variable.");
-                return -ENOENT;
-        }
-
-        if ((r = safe_atollu(e, &pid)) < 0) {
-                log_error("Failed to parse $LISTEN_PID: %s", strerror(-r));
-                return r;
-        }
-
-        if (pid != (unsigned long long) getpid()) {
-                log_error("Socket nor for me.");
-                return -ENOENT;
-        }
-
-        if (!(e = getenv("LISTEN_FDS"))) {
-                log_error("Missing $LISTEN_FDS environment variable.");
-                return -ENOENT;
-        }
-
-        if ((r = safe_atou(e, &ns)) < 0) {
-                log_error("Failed to parse $LISTEN_FDS: %s", strerror(-r));
-                return -E2BIG;
-        }
-
-        if (ns <= 0 || ns > SERVER_FD_MAX) {
-                log_error("Wrong number of file descriptors passed: %s", e);
-                return -E2BIG;
-        }
-
-        *n_sockets = ns;
-
-        return 0;
-}
-
 static void server_done(Server *s) {
         assert(s);
 
@@ -335,14 +292,14 @@ static int server_init(Server *s, unsigned n_sockets) {
                 zero(ev);
                 ev.events = EPOLLIN;
                 ev.data.ptr = f;
-                if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, SERVER_FD_START+i, &ev) < 0) {
+                if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, SD_LISTEN_FDS_START+i, &ev) < 0) {
                         r = -errno;
                         fifo_free(f);
                         log_error("Failed to add fifo fd to epoll object: %s", strerror(errno));
                         goto fail;
                 }
 
-                f->fd = SERVER_FD_START+i;
+                f->fd = SD_LISTEN_FDS_START+i;
                 LIST_PREPEND(Fifo, fifo, s->fifos, f);
                 f->server = s;
                 s->n_fifos ++;
@@ -386,15 +343,24 @@ static int process_event(Server *s, struct epoll_event *ev) {
 
 int main(int argc, char *argv[]) {
         Server server;
-        int r = 3;
-        unsigned n;
+        int r = 3, n;
+
+        log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
+        log_parse_environment();
 
         log_info("systemd-initctl running as pid %llu", (unsigned long long) getpid());
 
-        if (verify_environment(&n) < 0)
+        if ((n = sd_listen_fds(true)) < 0) {
+                log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
                 return 1;
+        }
+
+        if (n <= 0 || n > SERVER_FD_MAX) {
+                log_error("No or too many file descriptors passed.");
+                return 2;
+        }
 
-        if (server_init(&server, n) < 0)
+        if (server_init(&server, (unsigned) n) < 0)
                 return 2;
 
         for (;;) {
diff --git a/logger.c b/logger.c
index ba325c6..b7c8ab8 100644
--- a/logger.c
+++ b/logger.c
@@ -35,10 +35,10 @@
 #include "util.h"
 #include "log.h"
 #include "list.h"
+#include "sd-daemon.h"
 
 #define STREAM_BUFFER 2048
 #define STREAMS_MAX 256
-#define SERVER_FD_START 3
 #define SERVER_FD_MAX 16
 #define TIMEOUT ((int) (10*MSEC_PER_SEC))
 
@@ -348,49 +348,6 @@ fail:
         return r;
 }
 
-static int verify_environment(unsigned *n_sockets) {
-        unsigned long long pid;
-        const char *e;
-        int r;
-        unsigned ns;
-
-        assert_se(n_sockets);
-
-        if (!(e = getenv("LISTEN_PID"))) {
-                log_error("Missing $LISTEN_PID environment variable.");
-                return -ENOENT;
-        }
-
-        if ((r = safe_atollu(e, &pid)) < 0) {
-                log_error("Failed to parse $LISTEN_PID: %s", strerror(-r));
-                return r;
-        }
-
-        if (pid != (unsigned long long) getpid()) {
-                log_error("Socket nor for me.");
-                return -ENOENT;
-        }
-
-        if (!(e = getenv("LISTEN_FDS"))) {
-                log_error("Missing $LISTEN_FDS environment variable.");
-                return -ENOENT;
-        }
-
-        if ((r = safe_atou(e, &ns)) < 0) {
-                log_error("Failed to parse $LISTEN_FDS: %s", strerror(-r));
-                return -E2BIG;
-        }
-
-        if (ns <= 0 || ns > SERVER_FD_MAX) {
-                log_error("Wrong number of file descriptors passed: %s", e);
-                return -E2BIG;
-        }
-
-        *n_sockets = ns;
-
-        return 0;
-}
-
 static void server_done(Server *s) {
         unsigned i;
         assert(s);
@@ -399,7 +356,7 @@ static void server_done(Server *s) {
                 stream_free(s->streams);
 
         for (i = 0; i < s->n_server_fd; i++)
-                close_nointr_nofail(SERVER_FD_START+i);
+                close_nointr_nofail(SD_LISTEN_FDS_START+i);
 
         if (s->syslog_fd >= 0)
                 close_nointr_nofail(s->syslog_fd);
@@ -439,8 +396,8 @@ static int server_init(Server *s, unsigned n_sockets) {
 
                 zero(ev);
                 ev.events = EPOLLIN;
-                ev.data.ptr = UINT_TO_PTR(SERVER_FD_START+i);
-                if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, SERVER_FD_START+i, &ev) < 0) {
+                ev.data.ptr = UINT_TO_PTR(SD_LISTEN_FDS_START+i);
+                if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, SD_LISTEN_FDS_START+i, &ev) < 0) {
                         r = -errno;
                         log_error("Failed to add server fd to epoll object: %s", strerror(errno));
                         goto fail;
@@ -480,13 +437,13 @@ static int process_event(Server *s, struct epoll_event *ev) {
         assert(s);
 
         /* Yes, this is a bit ugly, we assume that that valid pointers
-         * are > SERVER_FD_START+SERVER_FD_MAX. Which is certainly
+         * are > SD_LISTEN_FDS_START+SERVER_FD_MAX. Which is certainly
          * true on Linux (and probably most other OSes, too, since the
          * first 4k usually are part of a seperate null pointer
          * dereference page. */
 
-        if (PTR_TO_UINT(ev->data.ptr) >= SERVER_FD_START &&
-            PTR_TO_UINT(ev->data.ptr) < SERVER_FD_START+s->n_server_fd) {
+        if (PTR_TO_UINT(ev->data.ptr) >= SD_LISTEN_FDS_START &&
+            PTR_TO_UINT(ev->data.ptr) < SD_LISTEN_FDS_START+s->n_server_fd) {
 
                 if (ev->events != EPOLLIN) {
                         log_info("Got invalid event from epoll. (1)");
@@ -505,7 +462,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
                 timestamp = now(CLOCK_REALTIME);
 
                 if (!(ev->events & EPOLLIN)) {
-                        log_info("Got invalid event from epoll. (3)");
+                        log_info("Got invalid event from epoll. (2)");
                         stream_free(stream);
                         return 0;
                 }
@@ -525,16 +482,25 @@ static int process_event(Server *s, struct epoll_event *ev) {
 
 int main(int argc, char *argv[]) {
         Server server;
-        int r = 3;
-        unsigned n;
+        int r = 3, n;
+
+        log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
+        log_parse_environment();
 
         log_info("systemd-logger running as pid %llu", (unsigned long long) getpid());
 
-        if (verify_environment(&n) < 0)
+        if ((n = sd_listen_fds(true)) < 0) {
+                log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
                 return 1;
+        }
 
-        if (server_init(&server, n) < 0)
+        if (n <= 0 || n > SERVER_FD_MAX) {
+                log_error("No or too many file descriptors passed.");
                 return 2;
+        }
+
+        if (server_init(&server, (unsigned) n) < 0)
+                return 3;
 
         for (;;) {
                 struct epoll_event event;
commit abbbea81a8fa70badb7a05e518d6b07c360fc09d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun May 16 01:43:53 2010 +0200

    sd-daemon: add reference implementation of various daemon apis

diff --git a/sd-daemon.c b/sd-daemon.c
new file mode 100644
index 0000000..cc972da
--- /dev/null
+++ b/sd-daemon.c
@@ -0,0 +1,96 @@
+/*-*- Mode: C; c-basic-offset: 8 -*-*/
+
+/***
+  Copyright 2010 Lennart Poettering
+
+  Permission is hereby granted, free of charge, to any person
+  obtaining a copy of this software and associated documentation files
+  (the "Software"), to deal in the Software without restriction,
+  including without limitation the rights to use, copy, modify, merge,
+  publish, distribute, sublicense, and/or sell copies of the Software,
+  and to permit persons to whom the Software is furnished to do so,
+  subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be
+  included in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+***/
+
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "sd-daemon.h"
+
+int sd_listen_fds(int unset_environment) {
+
+#ifdef DISABLE_SYSTEMD
+        return 0;
+#else
+        int r;
+        const char *e;
+        char *p = NULL;
+        unsigned long l;
+
+        if (!(e = getenv("LISTEN_PID"))) {
+                r = 0;
+                goto finish;
+        }
+
+        errno = 0;
+        l = strtoul(e, &p, 10);
+
+        if (errno != 0) {
+                r = -errno;
+                goto finish;
+        }
+
+        if (!p || *p || l <= 0) {
+                r = -EINVAL;
+                goto finish;
+        }
+
+        /* Is this for us? */
+        if (getpid() != (pid_t) l) {
+                r = 0;
+                goto finish;
+        }
+
+        if (!(e = getenv("LISTEN_FDS"))) {
+                r = 0;
+                goto finish;
+        }
+
+        errno = 0;
+        l = strtoul(e, &p, 10);
+
+        if (errno != 0) {
+                r = -errno;
+                goto finish;
+        }
+
+        if (!p || *p) {
+                r = -EINVAL;
+                goto finish;
+        }
+
+        r = (int) l;
+
+finish:
+        if (unset_environment) {
+                unsetenv("LISTEN_PID");
+                unsetenv("LISTEN_FDS");
+        }
+
+        return r;
+#endif
+}
diff --git a/sd-daemon.h b/sd-daemon.h
new file mode 100644
index 0000000..c7f5c1d
--- /dev/null
+++ b/sd-daemon.h
@@ -0,0 +1,61 @@
+/*-*- Mode: C; c-basic-offset: 8 -*-*/
+
+#ifndef foosddaemonhfoo
+#define foosddaemonhfoo
+
+/***
+  Copyright 2010 Lennart Poettering
+
+  Permission is hereby granted, free of charge, to any person
+  obtaining a copy of this software and associated documentation files
+  (the "Software"), to deal in the Software without restriction,
+  including without limitation the rights to use, copy, modify, merge,
+  publish, distribute, sublicense, and/or sell copies of the Software,
+  and to permit persons to whom the Software is furnished to do so,
+  subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be
+  included in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+***/
+
+/* Reference implementation of a few systemd related interfaces for
+ * writing daemons. These interfaces are trivial to implement, however
+ * to simplify porting we provide this reference
+ * implementation. Applications are free to reimplement the algorithms
+ * described here. */
+
+/*
+  Log levels for usage on stderr:
+
+          fprintf(stderr, SD_NOTICE "Hello World!");
+
+  This is similar to printk() usage in the kernel.
+*/
+
+#define SD_EMERG   "<0>"  /* system is unusable */
+#define SD_ALERT   "<1>"  /* action must be taken immediately */
+#define SD_CRIT    "<2>"  /* critical conditions */
+#define SD_ERR     "<3>"  /* error conditions */
+#define SD_WARNING "<4>"  /* warning conditions */
+#define SD_NOTICE  "<5>"  /* normal but significant condition */
+#define SD_INFO    "<6>"  /* informational */
+#define SD_DEBUG   "<7>"  /* debug-level messages */
+
+/* The first passed file descriptor is fd 3 */
+#define SD_LISTEN_FDS_START 3
+
+/* Returns how many file descriptors have been passed, or a negative
+ * errno code on failure. Optionally removes the $LISTEN_FDS and
+ * $LISTEN_PID file descriptors from the environment (recommended). */
+int sd_listen_fds(int unset_environment);
+
+#endif


More information about the systemd-commits mailing list