[systemd-commits] 7 commits - man/systemd.path.xml man/systemd.socket.xml src/dbus-path.c src/load-fragment.c src/mount-setup.c src/path.c src/path.h src/socket.c src/socket-util.c src/socket-util.h src/systemctl-bash-completion.sh src/tmpfiles.c src/unit.c tmpfiles.d/systemd.conf TODO units/local-fs.target units/systemd-ask-password-console.path units/systemd-ask-password-plymouth.path units/systemd-ask-password-wall.path

Lennart Poettering lennart at kemper.freedesktop.org
Mon Apr 11 10:23:51 PDT 2011


 TODO                                     |   36 +---
 man/systemd.path.xml                     |   22 ++
 man/systemd.socket.xml                   |   16 +
 src/dbus-path.c                          |    8 
 src/load-fragment.c                      |   12 +
 src/mount-setup.c                        |    1 
 src/path.c                               |   39 ++++
 src/path.h                               |    3 
 src/socket-util.c                        |  279 +++++++++++++++++++++----------
 src/socket-util.h                        |   11 +
 src/socket.c                             |   39 +++-
 src/systemctl-bash-completion.sh         |    2 
 src/tmpfiles.c                           |   48 ++++-
 src/unit.c                               |    2 
 tmpfiles.d/systemd.conf                  |    2 
 units/local-fs.target                    |    2 
 units/systemd-ask-password-console.path  |    1 
 units/systemd-ask-password-plymouth.path |    1 
 units/systemd-ask-password-wall.path     |    1 
 19 files changed, 404 insertions(+), 121 deletions(-)

New commits:
commit cc93c1b2866ba150556e20ae1797c23409afa9a3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Apr 10 03:27:27 2011 +0200

    unit: fix dump output

diff --git a/src/unit.c b/src/unit.c
index 37a7c07..e19061c 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -664,7 +664,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
                         "%s\tRefuseManualStart: %s\n"
                         "%s\tRefuseManualStop: %s\n"
                         "%s\tDefaultDependencies: %s\n"
-                        "%s\rOnFailureIsolate: %s\n",
+                        "%s\tOnFailureIsolate: %s\n",
                         prefix, yes_no(u->meta.stop_when_unneeded),
                         prefix, yes_no(u->meta.refuse_manual_start),
                         prefix, yes_no(u->meta.refuse_manual_stop),

commit 4ac9236fa14696db3e8a650a083a238eca9b9ae9
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Apr 10 03:27:19 2011 +0200

    socket: be a bit more verbose when refusing to start a socket unit

diff --git a/src/socket.c b/src/socket.c
index 80adf16..a8f8dc3 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1363,15 +1363,19 @@ static int socket_start(Unit *u) {
 
         /* Cannot run this without the service being around */
         if (s->service) {
-                if (s->service->meta.load_state != UNIT_LOADED)
+                if (s->service->meta.load_state != UNIT_LOADED) {
+                        log_error("Socket service %s not loaded, refusing.", s->service->meta.id);
                         return -ENOENT;
+                }
 
                 /* If the service is already active we cannot start the
                  * socket */
                 if (s->service->state != SERVICE_DEAD &&
                     s->service->state != SERVICE_FAILED &&
-                    s->service->state != SERVICE_AUTO_RESTART)
+                    s->service->state != SERVICE_AUTO_RESTART) {
+                        log_error("Socket service %s already active, refusing.", s->service->meta.id);
                         return -EBUSY;
+                }
 
 #ifdef HAVE_SYSV_COMPAT
                 if (s->service->sysv_path) {

commit 7a22745ac3c267edf89a23a920a28d86df5d0f9a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Apr 10 03:27:00 2011 +0200

    socket: support netlink sockets

diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
index 8cbb512..306e688 100644
--- a/man/systemd.socket.xml
+++ b/man/systemd.socket.xml
@@ -219,6 +219,22 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><varname>ListenNetlink=</varname></term>
+                                <listitem><para>Specifies a Netlink
+                                family to create a socket for to
+                                listen on. This expects a short string
+                                referring to the AF_NETLINK family
+                                name (such as <varname>audit</varname>
+                                or <varname>kobject-uevent</varname>)
+                                as argument, optionally suffixed by a
+                                whitespace followed by a multicast
+                                group integer. Behaviour otherwise is
+                                very similar to the
+                                <varname>ListenDatagram=</varname>
+                                directive above.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><varname>BindIPv6Only=</varname></term>
                                 <listitem><para>Takes a one of
                                 <option>default</option>,
diff --git a/src/load-fragment.c b/src/load-fragment.c
index aac27b5..3440d91 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -220,6 +220,15 @@ static int config_parse_listen(
                 }
 
                 path_kill_slashes(p->path);
+        } else if (streq(lvalue, "ListenNetlink")) {
+                p->type = SOCKET_SOCKET;
+
+                if (socket_address_parse_netlink(&p->address, rvalue) < 0) {
+                        log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
+                        free(p);
+                        return 0;
+                }
+
         } else {
                 p->type = SOCKET_SOCKET;
 
@@ -1892,6 +1901,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "ListenDatagram",         config_parse_listen,          0, &u->socket,                                      "Socket"  },
                 { "ListenSequentialPacket", config_parse_listen,          0, &u->socket,                                      "Socket"  },
                 { "ListenFIFO",             config_parse_listen,          0, &u->socket,                                      "Socket"  },
+                { "ListenNetlink",          config_parse_listen,          0, &u->socket,                                      "Socket"  },
                 { "BindIPv6Only",           config_parse_socket_bind,     0, &u->socket,                                      "Socket"  },
                 { "Backlog",                config_parse_unsigned,        0, &u->socket.backlog,                              "Socket"  },
                 { "BindToDevice",           config_parse_bindtodevice,    0, &u->socket,                                      "Socket"  },
diff --git a/src/socket-util.c b/src/socket-util.c
index 9b4a1b3..4c28946 100644
--- a/src/socket-util.c
+++ b/src/socket-util.c
@@ -189,50 +189,102 @@ int socket_address_parse(SocketAddress *a, const char *s) {
         return 0;
 }
 
+int socket_address_parse_netlink(SocketAddress *a, const char *s) {
+        int family;
+        unsigned group = 0;
+        char* sfamily = NULL;
+        assert(a);
+        assert(s);
+
+        zero(*a);
+        a->type = SOCK_RAW;
+
+        errno = 0;
+        if (sscanf(s, "%ms %u", &sfamily, &group) < 1)
+                return errno ? -errno : -EINVAL;
+
+        if ((family = netlink_family_from_string(sfamily)) < 0)
+                if (safe_atoi(sfamily, &family) < 0) {
+                        free(sfamily);
+                        return -EINVAL;
+                }
+
+        free(sfamily);
+
+        a->sockaddr.nl.nl_family = AF_NETLINK;
+        a->sockaddr.nl.nl_groups = group;
+
+        a->type = SOCK_RAW;
+        a->size = sizeof(struct sockaddr_nl);
+        a->protocol = family;
+
+        return 0;
+}
+
 int socket_address_verify(const SocketAddress *a) {
         assert(a);
 
         switch (socket_address_family(a)) {
-                case AF_INET:
-                        if (a->size != sizeof(struct sockaddr_in))
-                                return -EINVAL;
 
-                        if (a->sockaddr.in4.sin_port == 0)
-                                return -EINVAL;
+        case AF_INET:
+                if (a->size != sizeof(struct sockaddr_in))
+                        return -EINVAL;
 
-                        return 0;
+                if (a->sockaddr.in4.sin_port == 0)
+                        return -EINVAL;
 
-                case AF_INET6:
-                        if (a->size != sizeof(struct sockaddr_in6))
-                                return -EINVAL;
+                if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM)
+                        return -EINVAL;
 
-                        if (a->sockaddr.in6.sin6_port == 0)
-                                return -EINVAL;
+                return 0;
+
+        case AF_INET6:
+                if (a->size != sizeof(struct sockaddr_in6))
+                        return -EINVAL;
 
-                        return 0;
+                if (a->sockaddr.in6.sin6_port == 0)
+                        return -EINVAL;
 
-                case AF_UNIX:
-                        if (a->size < offsetof(struct sockaddr_un, sun_path))
-                                return -EINVAL;
+                if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM)
+                        return -EINVAL;
 
-                        if (a->size > offsetof(struct sockaddr_un, sun_path)) {
+                return 0;
 
-                                if (a->sockaddr.un.sun_path[0] != 0) {
-                                        char *e;
+        case AF_UNIX:
+                if (a->size < offsetof(struct sockaddr_un, sun_path))
+                        return -EINVAL;
 
-                                        /* path */
-                                        if (!(e = memchr(a->sockaddr.un.sun_path, 0, sizeof(a->sockaddr.un.sun_path))))
-                                                return -EINVAL;
+                if (a->size > offsetof(struct sockaddr_un, sun_path)) {
 
-                                        if (a->size != offsetof(struct sockaddr_un, sun_path) + (e - a->sockaddr.un.sun_path) + 1)
-                                                return -EINVAL;
-                                }
+                        if (a->sockaddr.un.sun_path[0] != 0) {
+                                char *e;
+
+                                /* path */
+                                if (!(e = memchr(a->sockaddr.un.sun_path, 0, sizeof(a->sockaddr.un.sun_path))))
+                                        return -EINVAL;
+
+                                if (a->size != offsetof(struct sockaddr_un, sun_path) + (e - a->sockaddr.un.sun_path) + 1)
+                                        return -EINVAL;
                         }
+                }
 
-                        return 0;
+                if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM && a->type == SOCK_SEQPACKET)
+                        return -EINVAL;
 
-                default:
-                        return -EAFNOSUPPORT;
+                return 0;
+
+        case AF_NETLINK:
+
+                if (a->size != sizeof(struct sockaddr_nl))
+                        return -EINVAL;
+
+                if (a->type != SOCK_RAW && a->type != SOCK_DGRAM)
+                        return -EINVAL;
+
+                return 0;
+
+        default:
+                return -EAFNOSUPPORT;
         }
 }
 
@@ -245,74 +297,89 @@ int socket_address_print(const SocketAddress *a, char **p) {
                 return r;
 
         switch (socket_address_family(a)) {
-                case AF_INET: {
-                        char *ret;
 
-                        if (!(ret = new(char, INET_ADDRSTRLEN+1+5+1)))
-                                return -ENOMEM;
+        case AF_INET: {
+                char *ret;
 
-                        if (!inet_ntop(AF_INET, &a->sockaddr.in4.sin_addr, ret, INET_ADDRSTRLEN)) {
-                                free(ret);
-                                return -errno;
-                        }
+                if (!(ret = new(char, INET_ADDRSTRLEN+1+5+1)))
+                        return -ENOMEM;
 
-                        sprintf(strchr(ret, 0), ":%u", ntohs(a->sockaddr.in4.sin_port));
-                        *p = ret;
-                        return 0;
+                if (!inet_ntop(AF_INET, &a->sockaddr.in4.sin_addr, ret, INET_ADDRSTRLEN)) {
+                        free(ret);
+                        return -errno;
                 }
 
-                case AF_INET6: {
-                        char *ret;
+                sprintf(strchr(ret, 0), ":%u", ntohs(a->sockaddr.in4.sin_port));
+                *p = ret;
+                return 0;
+        }
 
-                        if (!(ret = new(char, 1+INET6_ADDRSTRLEN+2+5+1)))
-                                return -ENOMEM;
+        case AF_INET6: {
+                char *ret;
 
-                        ret[0] = '[';
-                        if (!inet_ntop(AF_INET6, &a->sockaddr.in6.sin6_addr, ret+1, INET6_ADDRSTRLEN)) {
-                                free(ret);
-                                return -errno;
-                        }
+                if (!(ret = new(char, 1+INET6_ADDRSTRLEN+2+5+1)))
+                        return -ENOMEM;
 
-                        sprintf(strchr(ret, 0), "]:%u", ntohs(a->sockaddr.in6.sin6_port));
-                        *p = ret;
-                        return 0;
+                ret[0] = '[';
+                if (!inet_ntop(AF_INET6, &a->sockaddr.in6.sin6_addr, ret+1, INET6_ADDRSTRLEN)) {
+                        free(ret);
+                        return -errno;
                 }
 
-                case AF_UNIX: {
-                        char *ret;
+                sprintf(strchr(ret, 0), "]:%u", ntohs(a->sockaddr.in6.sin6_port));
+                *p = ret;
+                return 0;
+        }
 
-                        if (a->size <= offsetof(struct sockaddr_un, sun_path)) {
+        case AF_UNIX: {
+                char *ret;
 
-                                if (!(ret = strdup("<unamed>")))
-                                        return -ENOMEM;
+                if (a->size <= offsetof(struct sockaddr_un, sun_path)) {
 
-                        } else if (a->sockaddr.un.sun_path[0] == 0) {
-                                /* abstract */
+                        if (!(ret = strdup("<unnamed>")))
+                                return -ENOMEM;
 
-                                /* FIXME: We assume we can print the
-                                 * socket path here and that it hasn't
-                                 * more than one NUL byte. That is
-                                 * actually an invalid assumption */
+                } else if (a->sockaddr.un.sun_path[0] == 0) {
+                        /* abstract */
 
-                                if (!(ret = new(char, sizeof(a->sockaddr.un.sun_path)+1)))
-                                        return -ENOMEM;
+                        /* FIXME: We assume we can print the
+                         * socket path here and that it hasn't
+                         * more than one NUL byte. That is
+                         * actually an invalid assumption */
 
-                                ret[0] = '@';
-                                memcpy(ret+1, a->sockaddr.un.sun_path+1, sizeof(a->sockaddr.un.sun_path)-1);
-                                ret[sizeof(a->sockaddr.un.sun_path)] = 0;
+                        if (!(ret = new(char, sizeof(a->sockaddr.un.sun_path)+1)))
+                                return -ENOMEM;
 
-                        } else {
+                        ret[0] = '@';
+                        memcpy(ret+1, a->sockaddr.un.sun_path+1, sizeof(a->sockaddr.un.sun_path)-1);
+                        ret[sizeof(a->sockaddr.un.sun_path)] = 0;
 
-                                if (!(ret = strdup(a->sockaddr.un.sun_path)))
-                                        return -ENOMEM;
-                        }
+                } else {
 
-                        *p = ret;
-                        return 0;
+                        if (!(ret = strdup(a->sockaddr.un.sun_path)))
+                                return -ENOMEM;
                 }
 
-                default:
-                        return -EINVAL;
+                *p = ret;
+                return 0;
+        }
+
+        case AF_NETLINK: {
+                const char *sfamily;
+
+                if ((sfamily = netlink_family_to_string(a->protocol)))
+                        r = asprintf(p, "%s %u", sfamily, a->sockaddr.nl.nl_groups);
+                else
+                        r = asprintf(p, "%i %u", a->protocol, a->sockaddr.nl.nl_groups);
+
+                if (r < 0)
+                        return -ENOMEM;
+
+                return 0;
+        }
+
+        default:
+                return -EINVAL;
         }
 }
 
@@ -341,7 +408,7 @@ int socket_address_listen(
         if (r < 0)
                 return r;
 
-        fd = socket(socket_address_family(a), a->type | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
+        fd = socket(socket_address_family(a), a->type | SOCK_NONBLOCK | SOCK_CLOEXEC, a->protocol);
         r = fd < 0 ? -errno : 0;
 
         label_socket_clear();
@@ -356,14 +423,16 @@ int socket_address_listen(
                         goto fail;
         }
 
-        if (bind_to_device)
-                if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, bind_to_device, strlen(bind_to_device)+1) < 0)
-                        goto fail;
+        if (socket_address_family(a) == AF_INET || socket_address_family(a) == AF_INET6) {
+                if (bind_to_device)
+                        if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, bind_to_device, strlen(bind_to_device)+1) < 0)
+                                goto fail;
 
-        if (free_bind) {
-                one = 1;
-                if (setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) < 0)
-                        log_warning("IP_FREEBIND failed: %m");
+                if (free_bind) {
+                        one = 1;
+                        if (setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) < 0)
+                                log_warning("IP_FREEBIND failed: %m");
+                }
         }
 
         one = 1;
@@ -397,7 +466,7 @@ int socket_address_listen(
         if (r < 0)
                 goto fail;
 
-        if (a->type == SOCK_STREAM)
+        if (socket_address_can_accept(a))
                 if (listen(fd, backlog) < 0)
                         goto fail;
 
@@ -471,6 +540,16 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
 
                 break;
 
+        case AF_NETLINK:
+
+                if (a->protocol != b->protocol)
+                        return false;
+
+                if (a->sockaddr.nl.nl_groups != b->sockaddr.nl.nl_groups)
+                        return false;
+
+                break;
+
         default:
                 /* Cannot compare, so we assume the addresses are different */
                 return false;
@@ -493,6 +572,18 @@ bool socket_address_is(const SocketAddress *a, const char *s, int type) {
         return socket_address_equal(a, &b);
 }
 
+bool socket_address_is_netlink(const SocketAddress *a, const char *s) {
+        struct SocketAddress b;
+
+        assert(a);
+        assert(s);
+
+        if (socket_address_parse_netlink(&b, s) < 0)
+                return false;
+
+        return socket_address_equal(a, &b);
+}
+
 bool socket_address_needs_mount(const SocketAddress *a, const char *prefix) {
         assert(a);
 
@@ -523,6 +614,28 @@ bool socket_ipv6_is_supported(void) {
         return enabled;
 }
 
+static const char* const netlink_family_table[] = {
+        [NETLINK_ROUTE] = "route",
+        [NETLINK_FIREWALL] = "firewall",
+        [NETLINK_INET_DIAG] = "inet-diag",
+        [NETLINK_NFLOG] = "nflog",
+        [NETLINK_XFRM] = "xfrm",
+        [NETLINK_SELINUX] = "selinux",
+        [NETLINK_ISCSI] = "iscsi",
+        [NETLINK_AUDIT] = "audit",
+        [NETLINK_FIB_LOOKUP] = "fib-lookup",
+        [NETLINK_CONNECTOR] = "connector",
+        [NETLINK_NETFILTER] = "netfilter",
+        [NETLINK_IP6_FW] = "ip6-fw",
+        [NETLINK_DNRTMSG] = "dnrtmsg",
+        [NETLINK_KOBJECT_UEVENT] = "kobject-uevent",
+        [NETLINK_GENERIC] = "generic",
+        [NETLINK_SCSITRANSPORT] = "scsitransport",
+        [NETLINK_ECRYPTFS] = "ecryptfs"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(netlink_family, int);
+
 static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIND_IPV6_ONLY_MAX] = {
         [SOCKET_ADDRESS_DEFAULT] = "default",
         [SOCKET_ADDRESS_BOTH] = "both",
diff --git a/src/socket-util.h b/src/socket-util.h
index 4743c37..0e891ec 100644
--- a/src/socket-util.h
+++ b/src/socket-util.h
@@ -26,6 +26,8 @@
 #include <netinet/in.h>
 #include <sys/un.h>
 #include <net/if.h>
+#include <asm/types.h>
+#include <linux/netlink.h>
 
 #include "macro.h"
 #include "util.h"
@@ -35,6 +37,7 @@ union sockaddr_union {
         struct sockaddr_in in4;
         struct sockaddr_in6 in6;
         struct sockaddr_un un;
+        struct sockaddr_nl nl;
         struct sockaddr_storage storage;
 };
 
@@ -47,6 +50,9 @@ typedef struct SocketAddress {
 
         /* Socket type, i.e. SOCK_STREAM, SOCK_DGRAM, ... */
         int type;
+
+        /* Socket protocol, IPPROTO_xxx, usually 0, except for netlink */
+        int protocol;
 } SocketAddress;
 
 typedef enum SocketAddressBindIPv6Only {
@@ -60,6 +66,7 @@ typedef enum SocketAddressBindIPv6Only {
 #define socket_address_family(a) ((a)->sockaddr.sa.sa_family)
 
 int socket_address_parse(SocketAddress *a, const char *s);
+int socket_address_parse_netlink(SocketAddress *a, const char *s);
 int socket_address_print(const SocketAddress *a, char **p);
 int socket_address_verify(const SocketAddress *a);
 
@@ -77,6 +84,7 @@ int socket_address_listen(
                 int *ret);
 
 bool socket_address_is(const SocketAddress *a, const char *s, int type);
+bool socket_address_is_netlink(const SocketAddress *a, const char *s);
 
 bool socket_address_equal(const SocketAddress *a, const SocketAddress *b);
 
@@ -85,6 +93,9 @@ bool socket_address_needs_mount(const SocketAddress *a, const char *prefix);
 const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b);
 SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s);
 
+const char* netlink_family_to_string(int b);
+int netlink_family_from_string(const char *s);
+
 bool socket_ipv6_is_supported(void);
 
 #endif
diff --git a/src/socket.c b/src/socket.c
index beb3286..80adf16 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -366,7 +366,10 @@ static int socket_load(Unit *u) {
         return socket_verify(s);
 }
 
-static const char* listen_lookup(int type) {
+static const char* listen_lookup(int family, int type) {
+
+        if (family == AF_NETLINK)
+                return "ListenNetlink";
 
         if (type == SOCK_STREAM)
                 return "ListenStream";
@@ -477,7 +480,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                         else
                                 t = k;
 
-                        fprintf(f, "%s%s: %s\n", prefix, listen_lookup(p->address.type), t);
+                        fprintf(f, "%s%s: %s\n", prefix, listen_lookup(socket_address_family(&p->address), p->address.type), t);
                         free(k);
                 } else
                         fprintf(f, "%sListenFIFO: %s\n", prefix, p->path);
@@ -1447,7 +1450,10 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
                         if ((r = socket_address_print(&p->address, &t)) < 0)
                                 return r;
 
-                        unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t);
+                        if (socket_address_family(&p->address) == AF_NETLINK)
+                                unit_serialize_item_format(u, f, "netlink", "%i %s", copy, t);
+                        else
+                                unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t);
                         free(t);
                 } else {
                         assert(p->type == SOCKET_FIFO);
@@ -1542,6 +1548,25 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
                         }
                 }
 
+        } else if (streq(key, "netlink")) {
+                int fd, skip = 0;
+                SocketPort *p;
+
+                if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
+                        log_debug("Failed to parse socket value %s", value);
+                else {
+
+                        LIST_FOREACH(port, p, s->ports)
+                                if (socket_address_is_netlink(&p->address, value+skip))
+                                        break;
+
+                        if (p) {
+                                if (p->fd >= 0)
+                                        close_nointr_nofail(p->fd);
+                                p->fd = fdset_remove(fds, fd);
+                        }
+                }
+
         } else
                 log_debug("Unknown serialization key '%s'", key);
 

commit b9a2a36b519ccd79c4198e7dda4e657d597a14ad
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Apr 10 01:42:48 2011 +0200

    local-fs: invoke emergency.service mounting at boot fails

diff --git a/TODO b/TODO
index ce08b8a..04c3832 100644
--- a/TODO
+++ b/TODO
@@ -21,6 +21,8 @@ F15:
 
 * be nice to ingo
 
+* get writev() /dev/kmsg support into the F15 kernel
+
 Features:
 
 * fix alsa mixer restore to not print error when no config is stored
@@ -31,7 +33,6 @@ Features:
 * show enablement status in systemctl status
 
 * write blog stories about:
-  - chroot, nspawn and friends
   - the blame game: systemd-analyze
   - enabling dbus services
   - status update
@@ -46,12 +47,11 @@ Features:
 
 * take BSD file lock on tty devices when using them?
 
-* tmpfiles should allow two identical lines
-  https://bugzilla.redhat.com/show_bug.cgi?id=690253
-
 * avoid any flag files, or readahead files in /, we need to support r/o /
   or / on tmpfs like Android setups.
 
+* move readahead files into /var, look for them with .path units
+
 * teach dbus to activate all services it finds in /etc/systemd/services/org-*.service
 
 * get process transport into dbus for systemctl -P/-H
@@ -63,7 +63,16 @@ Features:
 
 * Find a way to replace /var/run, /var/lock directories with
   symlinks during an RPM package upgrade (filesystem.rpm or systemd.rpm).
-  We soon want to get rid of var-run.mount var-lock.mount units.
+  We soon want to get rid of var-run.mount var-lock.mount units:
+
+  if mountpoint /run ; then
+        umount /var/run || :
+  else
+        mount --move /var/run /run || mount --bind /var/run /run
+  fi
+  mv /var/run /var/.run.save
+  ln -s /run /var/run
+  echo "R /var/.run.save" > /etc/tmpfiles.d/remove-run-save.conf
 
 * when key file cannot be found, read it from kbd in cryptsetup
 
@@ -73,9 +82,6 @@ Features:
 
 * reuse mkdtemp namespace dirs in /tmp?
 
-* don't strip facility from kmsg log messages as soon as that is possible:
-    http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=9d90c8d9cde929cbc575098e825d7c29d9f45054
-
 * recreate systemd's D-Bus private socket file on SIGUSR2
 
 * be more specific what failed:
@@ -110,8 +116,6 @@ Features:
 * Maybe implement "systemctl mask" and "systemctl unmask", but not
   document it? When doing that add switch to make this temporary by
   placing mask links in /dev.
-  Consider moving the actual fs operations into systemd behind a D-Bus
-  interface, to make namespaces/containers/remote connections work properly.
 
 * detect LXC environment
 
@@ -126,7 +130,7 @@ Features:
 * perhaps add "systemctl reenable" as combination of "systemctl disable" and "systemctl enable"
 
 * need a way to apply mount options of api vfs from systemd unit files
-  (or some other modern source?) instead of fstab
+  (or some other modern source?) instead of fstab?
 
 * maybe introduce ExecRestartPre=
 
@@ -134,8 +138,6 @@ Features:
 
 * Patch systemd-fsck to use -C and pass console fd to it
 
-* support remote/ssh systemctl/systemadm, and local privileged access → dbus patches need to be merged
-
 * configurable jitter for timer events
 
 * Support ProcessNeededForShutdown=true to allow stuff like mdmon
@@ -184,8 +186,6 @@ Features:
 
 * systemctl list-jobs - show dependencies
 
-* accountsservice is borked
-
 * auditd service files
 
 * add systemctl switch to dump transaction without executing it
diff --git a/units/local-fs.target b/units/local-fs.target
index 52d0e68..79fd9b8 100644
--- a/units/local-fs.target
+++ b/units/local-fs.target
@@ -9,3 +9,5 @@
 
 [Unit]
 Description=Local File Systems
+OnFailure=emergency.service
+OnFailureIsolate=yes

commit 0e456f978134100d2e0cc28c7205b3abefcc9cde
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Apr 10 01:30:14 2011 +0200

    path: optionally, create watched directories in .path units

diff --git a/TODO b/TODO
index 78cedde..ce08b8a 100644
--- a/TODO
+++ b/TODO
@@ -13,14 +13,14 @@ F15:
 
 * add fstab fields to add wait timeouts, change Wants to Requires by local-fs.target
 
-* hook emergency.target into local-fs.target in some way as OnFailure with isolate, add warning log message
-
 * bind mounts are ignored
   https://bugzilla.redhat.com/show_bug.cgi?id=682662
 
 * 0595f9a1c182a84581749823ef47c5f292e545f9 is borked, freezes shutdown
     (path: after installing inotify watches, recheck file again to fix race)
 
+* be nice to ingo
+
 Features:
 
 * fix alsa mixer restore to not print error when no config is stored
@@ -95,8 +95,6 @@ Features:
   about policy loading. Probably check for available selinux in /proc/filesystems,
   and check for active selinux with getcon_raw() == "kernel"
 
-* optionally create watched directories in .path units
-
 * Support --test based on current system state
 
 * consider services with no [Install] section and stored in /lib enabled by "systemctl is-enabled"
diff --git a/man/systemd.path.xml b/man/systemd.path.xml
index d5495c7..e816c30 100644
--- a/man/systemd.path.xml
+++ b/man/systemd.path.xml
@@ -168,6 +168,28 @@
                                 identical, except for the
                                 suffix.</para></listitem>
                         </varlistentry>
+                        <varlistentry>
+                                <term><varname>MakeDirectory=</varname></term>
+
+                                <listitem><para>Takes a boolean
+                                argument. If true the directories to
+                                watch are created before
+                                watching. This option is ignored for
+                                <varname>PathExists=</varname>
+                                settings. Defaults to
+                                <option>false</option>.</para></listitem>
+                        </varlistentry>
+                        <varlistentry>
+                                <term><varname>DirectoryMode=</varname></term>
+
+                                <listitem><para>If
+                                <varname>MakeDirectory=</varname> is
+                                enabled use the mode specified here to
+                                create the directories in
+                                question. Takes an access mode in
+                                octal notation. Defaults to
+                                <option>0755</option>.</para></listitem>
+                        </varlistentry>
                 </variablelist>
         </refsect1>
 
diff --git a/src/dbus-path.c b/src/dbus-path.c
index cb1d4f0..1e757a3 100644
--- a/src/dbus-path.c
+++ b/src/dbus-path.c
@@ -29,6 +29,8 @@
         " <interface name=\"org.freedesktop.systemd1.Path\">\n"         \
         "  <property name=\"Unit\" type=\"s\" access=\"read\"/>\n"      \
         "  <property name=\"Paths\" type=\"a(ss)\" access=\"read\"/>\n" \
+        "  <property name=\"MakeDirectory\" type=\"b\" access=\"read\"/>\n" \
+        "  <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
         " </interface>\n"
 
 #define INTROSPECTION                                                   \
@@ -93,8 +95,10 @@ static int bus_path_append_unit(Manager *m, DBusMessageIter *i, const char *prop
 DBusHandlerResult bus_path_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
-                { "org.freedesktop.systemd1.Path", "Unit",  bus_path_append_unit,       "s",     u                      },
-                { "org.freedesktop.systemd1.Path", "Paths", bus_path_append_paths,      "a(ss)", u                      },
+                { "org.freedesktop.systemd1.Path", "Unit",          bus_path_append_unit,     "s",     u                        },
+                { "org.freedesktop.systemd1.Path", "Paths",         bus_path_append_paths,    "a(ss)", u                        },
+                { "org.freedesktop.systemd1.Path", "MakeDirectory", bus_property_append_bool, "b",     &u->path.make_directory  },
+                { "org.freedesktop.systemd1.Path", "DirectoryMode", bus_property_append_mode, "u",     &u->path.directory_mode  },
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
diff --git a/src/load-fragment.c b/src/load-fragment.c
index c27c9d8..aac27b5 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1944,6 +1944,8 @@ static int load_from_path(Unit *u, const char *path) {
                 { "PathChanged",            config_parse_path_spec,       0, &u->path,                                        "Path"    },
                 { "DirectoryNotEmpty",      config_parse_path_spec,       0, &u->path,                                        "Path"    },
                 { "Unit",                   config_parse_path_unit,       0, &u->path,                                        "Path"    },
+                { "MakeDirectory",          config_parse_bool,            0, &u->path.make_directory,                         "Path"    },
+                { "DirectoryMode",          config_parse_mode,            0, &u->path.directory_mode,                         "Path"    },
 
                 /* The [Install] section is ignored here. */
                 { "Alias",                  NULL,                         0, NULL,                                            "Install" },
diff --git a/src/mount-setup.c b/src/mount-setup.c
index 8520583..663a72f 100644
--- a/src/mount-setup.c
+++ b/src/mount-setup.c
@@ -260,7 +260,6 @@ int mount_setup(void) {
 
         /* Create a few directories we always want around */
         mkdir("/run/systemd", 0755);
-        mkdir("/run/systemd/ask-password", 0755);
 
         return mount_cgroup_controllers();
 }
diff --git a/src/path.c b/src/path.c
index f7878b5..1a3e28f 100644
--- a/src/path.c
+++ b/src/path.c
@@ -39,6 +39,15 @@ static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
         [PATH_FAILED] = UNIT_FAILED
 };
 
+static void path_init(Unit *u) {
+        Path *p = PATH(u);
+
+        assert(u);
+        assert(u->meta.load_state == UNIT_STUB);
+
+        p->directory_mode = 0755;
+}
+
 static void path_unwatch_one(Path *p, PathSpec *s) {
 
         if (s->inotify_fd < 0)
@@ -169,9 +178,13 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) {
 
         fprintf(f,
                 "%sPath State: %s\n"
-                "%sUnit: %s\n",
+                "%sUnit: %s\n"
+                "%sMakeDirectory: %s\n"
+                "%sDirectoryMode: %04o\n",
                 prefix, path_state_to_string(p->state),
-                prefix, p->unit->meta.id);
+                prefix, p->unit->meta.id,
+                prefix, yes_no(p->make_directory),
+                prefix, p->directory_mode);
 
         LIST_FOREACH(spec, s, p->specs)
                 fprintf(f,
@@ -408,6 +421,25 @@ fail:
         path_enter_dead(p, false);
 }
 
+static void path_mkdir(Path *p) {
+        PathSpec *s;
+
+        assert(p);
+
+        if (!p->make_directory)
+                return;
+
+        LIST_FOREACH(spec, s, p->specs) {
+                int r;
+
+                if (s->type == PATH_EXISTS)
+                        continue;
+
+                if ((r = mkdir_p(s->path, p->directory_mode)) < 0)
+                        log_warning("mkdir(%s) failed: %s", s->path, strerror(-r));
+        }
+}
+
 static int path_start(Unit *u) {
         Path *p = PATH(u);
 
@@ -417,6 +449,8 @@ static int path_start(Unit *u) {
         if (p->unit->meta.load_state != UNIT_LOADED)
                 return -ENOENT;
 
+        path_mkdir(p);
+
         p->failure = false;
         path_enter_waiting(p, true, true, false);
 
@@ -639,6 +673,7 @@ DEFINE_STRING_TABLE_LOOKUP(path_type, PathType);
 const UnitVTable path_vtable = {
         .suffix = ".path",
 
+        .init = path_init,
         .done = path_done,
         .load = path_load,
 
diff --git a/src/path.h b/src/path.h
index 0dff120..8ba0ce6 100644
--- a/src/path.h
+++ b/src/path.h
@@ -70,6 +70,9 @@ struct Path {
 
         bool failure;
         bool inotify_triggered;
+
+        bool make_directory;
+        mode_t directory_mode;
 };
 
 void path_unit_notify(Unit *u, UnitActiveState new_state);
diff --git a/tmpfiles.d/systemd.conf b/tmpfiles.d/systemd.conf
index 2ab8e2b..5e8ed99 100644
--- a/tmpfiles.d/systemd.conf
+++ b/tmpfiles.d/systemd.conf
@@ -21,3 +21,5 @@ d /var/cache/man - - - 30d
 r /forcefsck
 r /forcequotacheck
 r /fastboot
+
+d /run/systemd/ask-password 0755 root root -
diff --git a/units/systemd-ask-password-console.path b/units/systemd-ask-password-console.path
index 4005a27..b5acf94 100644
--- a/units/systemd-ask-password-console.path
+++ b/units/systemd-ask-password-console.path
@@ -13,3 +13,4 @@ Before=basic.target shutdown.target
 
 [Path]
 DirectoryNotEmpty=/run/systemd/ask-password
+MakeDirectory=yes
diff --git a/units/systemd-ask-password-plymouth.path b/units/systemd-ask-password-plymouth.path
index a2aec44..6a96520 100644
--- a/units/systemd-ask-password-plymouth.path
+++ b/units/systemd-ask-password-plymouth.path
@@ -13,3 +13,4 @@ Before=basic.target shutdown.target
 
 [Path]
 DirectoryNotEmpty=/run/systemd/ask-password
+MakeDirectory=yes
diff --git a/units/systemd-ask-password-wall.path b/units/systemd-ask-password-wall.path
index 7a883d5..050b73b 100644
--- a/units/systemd-ask-password-wall.path
+++ b/units/systemd-ask-password-wall.path
@@ -13,3 +13,4 @@ Before=basic.target shutdown.target
 
 [Path]
 DirectoryNotEmpty=/run/systemd/ask-password
+MakeDirectory=yes

commit bfe95f35bf87c91d63b9d62dde5f029dd38d27a4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Apr 8 04:49:43 2011 +0200

    tmpfiles: don't warn if two identical lines are configured
    
    https://bugzilla.redhat.com/show_bug.cgi?id=690253

diff --git a/TODO b/TODO
index 7c5fe63..78cedde 100644
--- a/TODO
+++ b/TODO
@@ -21,8 +21,6 @@ F15:
 * 0595f9a1c182a84581749823ef47c5f292e545f9 is borked, freezes shutdown
     (path: after installing inotify watches, recheck file again to fix race)
 
-* active_enter timestamps borked?
-
 Features:
 
 * fix alsa mixer restore to not print error when no config is stored
diff --git a/src/tmpfiles.c b/src/tmpfiles.c
index b21df95..2526d1e 100644
--- a/src/tmpfiles.c
+++ b/src/tmpfiles.c
@@ -623,9 +623,39 @@ static void item_free(Item *i) {
         free(i);
 }
 
+static bool item_equal(Item *a, Item *b) {
+        assert(a);
+        assert(b);
+
+        if (!streq_ptr(a->path, b->path))
+                return false;
+
+        if (a->type != b->type)
+                return false;
+
+        if (a->uid_set != b->uid_set ||
+            (a->uid_set && a->uid != b->uid))
+            return false;
+
+        if (a->gid_set != b->gid_set ||
+            (a->gid_set && a->gid != b->gid))
+            return false;
+
+        if (a->mode_set != b->mode_set ||
+            (a->mode_set && a->mode != b->mode))
+            return false;
+
+        if (a->age_set != b->age_set ||
+            (a->age_set && a->age != b->age))
+            return false;
+
+        return true;
+}
+
 static int parse_line(const char *fname, unsigned line, const char *buffer) {
-        Item *i;
+        Item *i, *existing;
         char *mode = NULL, *user = NULL, *group = NULL, *age = NULL;
+        Hashmap *h;
         int r;
 
         assert(fname);
@@ -742,13 +772,19 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                 i->age_set = true;
         }
 
-        if ((r = hashmap_put(needs_glob(i->type) ? globs : items, i->path, i)) < 0) {
-                if (r == -EEXIST) {
+        h = needs_glob(i->type) ? globs : items;
+
+        if ((existing = hashmap_get(h, i->path))) {
+
+                /* Two identical items are fine */
+                if (!item_equal(existing, i))
                         log_warning("Two or more conflicting lines for %s configured, ignoring.", i->path);
-                        r = 0;
-                        goto finish;
-                }
 
+                r = 0;
+                goto finish;
+        }
+
+        if ((r = hashmap_put(h, i->path, i)) < 0) {
                 log_error("Failed to insert item %s: %s", i->path, strerror(-r));
                 goto finish;
         }

commit 2dcd4d240630c98f8cb025090c2bbfa65aa28a8a
Author: Brendan Jones <brendan.jones.it at gmail.com>
Date:   Fri Apr 8 04:29:20 2011 +0200

    bash: fix typo
    
    There's a typo in the bash completion script which disables isolate
    target completion.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=694321

diff --git a/src/systemctl-bash-completion.sh b/src/systemctl-bash-completion.sh
index ae0ecb7..dc18ab6 100644
--- a/src/systemctl-bash-completion.sh
+++ b/src/systemctl-bash-completion.sh
@@ -81,7 +81,7 @@ _systemctl () {
              [FAILED_UNITS]='reset-failed'
           [STARTABLE_UNITS]='start restart reload-or-restart'
           [STOPPABLE_UNITS]='stop kill try-restart condrestart'
-         [ISOLATEBLE_UNITS]='isolate'
+         [ISOLATABLE_UNITS]='isolate'
          [RELOADABLE_UNITS]='reload reload-or-try-restart force-reload'
                      [JOBS]='cancel'
                 [SNAPSHOTS]='delete'



More information about the systemd-commits mailing list