[systemd-commits] 6 commits - configure.ac Makefile.am src/core src/journal src/login src/machine src/test

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Thu Sep 26 02:31:50 PDT 2013


 Makefile.am                   |   17 -
 configure.ac                  |   20 +
 src/core/execute.c            |   27 +-
 src/journal/journald-server.c |   20 +
 src/login/logind-core.c       |  514 ++++++++++++++++++++++++++++++++++++++++++
 src/login/logind.c            |  484 ---------------------------------------
 src/machine/machined-dbus.c   |   46 +++
 src/machine/machined.c        |   46 ---
 src/test/test-hashmap.c       |    8 
 9 files changed, 624 insertions(+), 558 deletions(-)

New commits:
commit 2b3ab29de466ae6bd7c3243a5a48c7291cc2af0a
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Sep 25 17:04:41 2013 +0200

    Move part of logind.c into a separate file
    
    liblogind-core.la was underlinked, missing a few functions
    defined in logind.c. They are moved to a new file, logind-core.c,
    and this file is linked into liblogind-core.la.
    In addition, logind-acl.c is attached to the liblogind-core.la,
    instead of systemd-logind directly.

diff --git a/Makefile.am b/Makefile.am
index 0eee1d9..92de163 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3761,15 +3761,8 @@ systemd_logind_LDADD = \
 	libsystemd-logind-core.la \
 	$(libsystemd_logind_core_la_LIBADD)
 
-if HAVE_ACL
-systemd_logind_SOURCES += \
-	src/login/logind-acl.c
-
-systemd_logind_LDADD += \
-	libsystemd-acl.la
-endif
-
 libsystemd_logind_core_la_SOURCES = \
+	src/login/logind-core.c \
 	src/login/logind-dbus.c \
 	src/login/logind-device.c \
 	src/login/logind-device.h \
@@ -3807,6 +3800,14 @@ libsystemd_logind_core_la_LIBADD = \
 	libsystemd-id128-internal.la \
 	libudev.la
 
+if HAVE_ACL
+libsystemd_logind_core_la_SOURCES += \
+	src/login/logind-acl.c
+
+libsystemd_logind_core_la_LIBADD += \
+	libsystemd-acl.la
+endif
+
 noinst_LTLIBRARIES += \
 	libsystemd-logind-core.la
 
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
new file mode 100644
index 0000000..36999ac
--- /dev/null
+++ b/src/login/logind-core.c
@@ -0,0 +1,514 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2011 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <linux/vt.h>
+
+#include "logind.h"
+#include "dbus-common.h"
+#include "strv.h"
+
+int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device) {
+        Device *d;
+
+        assert(m);
+        assert(sysfs);
+
+        d = hashmap_get(m->devices, sysfs);
+        if (d) {
+                if (_device)
+                        *_device = d;
+
+                /* we support adding master-flags, but not removing them */
+                d->master = d->master || master;
+
+                return 0;
+        }
+
+        d = device_new(m, sysfs, master);
+        if (!d)
+                return -ENOMEM;
+
+        if (_device)
+                *_device = d;
+
+        return 0;
+}
+
+int manager_add_seat(Manager *m, const char *id, Seat **_seat) {
+        Seat *s;
+
+        assert(m);
+        assert(id);
+
+        s = hashmap_get(m->seats, id);
+        if (s) {
+                if (_seat)
+                        *_seat = s;
+
+                return 0;
+        }
+
+        s = seat_new(m, id);
+        if (!s)
+                return -ENOMEM;
+
+        if (_seat)
+                *_seat = s;
+
+        return 0;
+}
+
+int manager_add_session(Manager *m, const char *id, Session **_session) {
+        Session *s;
+
+        assert(m);
+        assert(id);
+
+        s = hashmap_get(m->sessions, id);
+        if (s) {
+                if (_session)
+                        *_session = s;
+
+                return 0;
+        }
+
+        s = session_new(m, id);
+        if (!s)
+                return -ENOMEM;
+
+        if (_session)
+                *_session = s;
+
+        return 0;
+}
+
+int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user) {
+        User *u;
+
+        assert(m);
+        assert(name);
+
+        u = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
+        if (u) {
+                if (_user)
+                        *_user = u;
+
+                return 0;
+        }
+
+        u = user_new(m, uid, gid, name);
+        if (!u)
+                return -ENOMEM;
+
+        if (_user)
+                *_user = u;
+
+        return 0;
+}
+
+int manager_add_user_by_name(Manager *m, const char *name, User **_user) {
+        uid_t uid;
+        gid_t gid;
+        int r;
+
+        assert(m);
+        assert(name);
+
+        r = get_user_creds(&name, &uid, &gid, NULL, NULL);
+        if (r < 0)
+                return r;
+
+        return manager_add_user(m, uid, gid, name, _user);
+}
+
+int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user) {
+        struct passwd *p;
+
+        assert(m);
+
+        errno = 0;
+        p = getpwuid(uid);
+        if (!p)
+                return errno ? -errno : -ENOENT;
+
+        return manager_add_user(m, uid, p->pw_gid, p->pw_name, _user);
+}
+
+int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor) {
+        Inhibitor *i;
+
+        assert(m);
+        assert(id);
+
+        i = hashmap_get(m->inhibitors, id);
+        if (i) {
+                if (_inhibitor)
+                        *_inhibitor = i;
+
+                return 0;
+        }
+
+        i = inhibitor_new(m, id);
+        if (!i)
+                return -ENOMEM;
+
+        if (_inhibitor)
+                *_inhibitor = i;
+
+        return 0;
+}
+
+int manager_add_button(Manager *m, const char *name, Button **_button) {
+        Button *b;
+
+        assert(m);
+        assert(name);
+
+        b = hashmap_get(m->buttons, name);
+        if (b) {
+                if (_button)
+                        *_button = b;
+
+                return 0;
+        }
+
+        b = button_new(m, name);
+        if (!b)
+                return -ENOMEM;
+
+        if (_button)
+                *_button = b;
+
+        return 0;
+}
+
+int manager_watch_busname(Manager *m, const char *name) {
+        char *n;
+        int r;
+
+        assert(m);
+        assert(name);
+
+        if (hashmap_get(m->busnames, name))
+                return 0;
+
+        n = strdup(name);
+        if (!n)
+                return -ENOMEM;
+
+        r = hashmap_put(m->busnames, n, n);
+        if (r < 0) {
+                free(n);
+                return r;
+        }
+
+        return 0;
+}
+
+void manager_drop_busname(Manager *m, const char *name) {
+        Session *session;
+        Iterator i;
+        char *key;
+
+        assert(m);
+        assert(name);
+
+        if (!hashmap_get(m->busnames, name))
+                return;
+
+        /* keep it if the name still owns a controller */
+        HASHMAP_FOREACH(session, m->sessions, i)
+                if (session_is_controller(session, name))
+                        return;
+
+        key = hashmap_remove(m->busnames, name);
+        if (key)
+                free(key);
+}
+
+int manager_process_seat_device(Manager *m, struct udev_device *d) {
+        Device *device;
+        int r;
+
+        assert(m);
+
+        if (streq_ptr(udev_device_get_action(d), "remove")) {
+
+                device = hashmap_get(m->devices, udev_device_get_syspath(d));
+                if (!device)
+                        return 0;
+
+                seat_add_to_gc_queue(device->seat);
+                device_free(device);
+
+        } else {
+                const char *sn;
+                Seat *seat = NULL;
+                bool master;
+
+                sn = udev_device_get_property_value(d, "ID_SEAT");
+                if (isempty(sn))
+                        sn = "seat0";
+
+                if (!seat_name_is_valid(sn)) {
+                        log_warning("Device with invalid seat name %s found, ignoring.", sn);
+                        return 0;
+                }
+
+                /* ignore non-master devices for unknown seats */
+                master = udev_device_has_tag(d, "master-of-seat");
+                if (!master && !(seat = hashmap_get(m->seats, sn)))
+                        return 0;
+
+                r = manager_add_device(m, udev_device_get_syspath(d), master, &device);
+                if (r < 0)
+                        return r;
+
+                if (!seat) {
+                        r = manager_add_seat(m, sn, &seat);
+                        if (r < 0) {
+                                if (!device->seat)
+                                        device_free(device);
+
+                                return r;
+                        }
+                }
+
+                device_attach(device, seat);
+                seat_start(seat);
+        }
+
+        return 0;
+}
+
+int manager_process_button_device(Manager *m, struct udev_device *d) {
+        Button *b;
+
+        int r;
+
+        assert(m);
+
+        if (streq_ptr(udev_device_get_action(d), "remove")) {
+
+                b = hashmap_get(m->buttons, udev_device_get_sysname(d));
+                if (!b)
+                        return 0;
+
+                button_free(b);
+
+        } else {
+                const char *sn;
+
+                r = manager_add_button(m, udev_device_get_sysname(d), &b);
+                if (r < 0)
+                        return r;
+
+                sn = udev_device_get_property_value(d, "ID_SEAT");
+                if (isempty(sn))
+                        sn = "seat0";
+
+                button_set_seat(b, sn);
+                button_open(b);
+        }
+
+        return 0;
+}
+
+int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) {
+        _cleanup_free_ char *unit = NULL;
+        Session *s;
+        int r;
+
+        assert(m);
+        assert(session);
+
+        if (pid < 1)
+                return -EINVAL;
+
+        r = cg_pid_get_unit(pid, &unit);
+        if (r < 0)
+                return r;
+
+        s = hashmap_get(m->session_units, unit);
+        if (!s)
+                return 0;
+
+        *session = s;
+        return 1;
+}
+
+int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) {
+        _cleanup_free_ char *unit = NULL;
+        User *u;
+        int r;
+
+        assert(m);
+        assert(user);
+
+        if (pid < 1)
+                return -EINVAL;
+
+        r = cg_pid_get_slice(pid, &unit);
+        if (r < 0)
+                return r;
+
+        u = hashmap_get(m->user_units, unit);
+        if (!u)
+                return 0;
+
+        *user = u;
+        return 1;
+}
+
+int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
+        Session *s;
+        bool idle_hint;
+        dual_timestamp ts = { 0, 0 };
+        Iterator i;
+
+        assert(m);
+
+        idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false, false, 0);
+
+        HASHMAP_FOREACH(s, m->sessions, i) {
+                dual_timestamp k;
+                int ih;
+
+                ih = session_get_idle_hint(s, &k);
+                if (ih < 0)
+                        return ih;
+
+                if (!ih) {
+                        if (!idle_hint) {
+                                if (k.monotonic < ts.monotonic)
+                                        ts = k;
+                        } else {
+                                idle_hint = false;
+                                ts = k;
+                        }
+                } else if (idle_hint) {
+
+                        if (k.monotonic > ts.monotonic)
+                                ts = k;
+                }
+        }
+
+        if (t)
+                *t = ts;
+
+        return idle_hint;
+}
+
+bool manager_shall_kill(Manager *m, const char *user) {
+        assert(m);
+        assert(user);
+
+        if (!m->kill_user_processes)
+                return false;
+
+        if (strv_contains(m->kill_exclude_users, user))
+                return false;
+
+        if (strv_isempty(m->kill_only_users))
+                return true;
+
+        return strv_contains(m->kill_only_users, user);
+}
+
+static int vt_is_busy(int vtnr) {
+        struct vt_stat vt_stat;
+        int r = 0, fd;
+
+        assert(vtnr >= 1);
+
+        /* We explicitly open /dev/tty1 here instead of /dev/tty0. If
+         * we'd open the latter we'd open the foreground tty which
+         * hence would be unconditionally busy. By opening /dev/tty1
+         * we avoid this. Since tty1 is special and needs to be an
+         * explicitly loaded getty or DM this is safe. */
+
+        fd = open_terminal("/dev/tty1", O_RDWR|O_NOCTTY|O_CLOEXEC);
+        if (fd < 0)
+                return -errno;
+
+        if (ioctl(fd, VT_GETSTATE, &vt_stat) < 0)
+                r = -errno;
+        else
+                r = !!(vt_stat.v_state & (1 << vtnr));
+
+        close_nointr_nofail(fd);
+
+        return r;
+}
+
+int manager_spawn_autovt(Manager *m, int vtnr) {
+        int r;
+        char *name = NULL;
+        const char *mode = "fail";
+
+        assert(m);
+        assert(vtnr >= 1);
+
+        if ((unsigned) vtnr > m->n_autovts &&
+            (unsigned) vtnr != m->reserve_vt)
+                return 0;
+
+        if ((unsigned) vtnr != m->reserve_vt) {
+                /* If this is the reserved TTY, we'll start the getty
+                 * on it in any case, but otherwise only if it is not
+                 * busy. */
+
+                r = vt_is_busy(vtnr);
+                if (r < 0)
+                        return r;
+                else if (r > 0)
+                        return -EBUSY;
+        }
+
+        if (asprintf(&name, "autovt at tty%i.service", vtnr) < 0) {
+                log_error("Could not allocate service name.");
+                r = -ENOMEM;
+                goto finish;
+        }
+
+        r = bus_method_call_with_reply (
+                        m->bus,
+                        "org.freedesktop.systemd1",
+                        "/org/freedesktop/systemd1",
+                        "org.freedesktop.systemd1.Manager",
+                        "StartUnit",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_STRING, &name,
+                        DBUS_TYPE_STRING, &mode,
+                        DBUS_TYPE_INVALID);
+
+finish:
+        free(name);
+
+        return r;
+}
diff --git a/src/login/logind.c b/src/login/logind.c
index 8bf520a..0628032 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -20,13 +20,11 @@
 ***/
 
 #include <errno.h>
-#include <pwd.h>
 #include <libudev.h>
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/epoll.h>
-#include <sys/ioctl.h>
 #include <linux/vt.h>
 #include <sys/timerfd.h>
 
@@ -192,313 +190,6 @@ void manager_free(Manager *m) {
         free(m);
 }
 
-int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device) {
-        Device *d;
-
-        assert(m);
-        assert(sysfs);
-
-        d = hashmap_get(m->devices, sysfs);
-        if (d) {
-                if (_device)
-                        *_device = d;
-
-                /* we support adding master-flags, but not removing them */
-                d->master = d->master || master;
-
-                return 0;
-        }
-
-        d = device_new(m, sysfs, master);
-        if (!d)
-                return -ENOMEM;
-
-        if (_device)
-                *_device = d;
-
-        return 0;
-}
-
-int manager_add_seat(Manager *m, const char *id, Seat **_seat) {
-        Seat *s;
-
-        assert(m);
-        assert(id);
-
-        s = hashmap_get(m->seats, id);
-        if (s) {
-                if (_seat)
-                        *_seat = s;
-
-                return 0;
-        }
-
-        s = seat_new(m, id);
-        if (!s)
-                return -ENOMEM;
-
-        if (_seat)
-                *_seat = s;
-
-        return 0;
-}
-
-int manager_add_session(Manager *m, const char *id, Session **_session) {
-        Session *s;
-
-        assert(m);
-        assert(id);
-
-        s = hashmap_get(m->sessions, id);
-        if (s) {
-                if (_session)
-                        *_session = s;
-
-                return 0;
-        }
-
-        s = session_new(m, id);
-        if (!s)
-                return -ENOMEM;
-
-        if (_session)
-                *_session = s;
-
-        return 0;
-}
-
-int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user) {
-        User *u;
-
-        assert(m);
-        assert(name);
-
-        u = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
-        if (u) {
-                if (_user)
-                        *_user = u;
-
-                return 0;
-        }
-
-        u = user_new(m, uid, gid, name);
-        if (!u)
-                return -ENOMEM;
-
-        if (_user)
-                *_user = u;
-
-        return 0;
-}
-
-int manager_add_user_by_name(Manager *m, const char *name, User **_user) {
-        uid_t uid;
-        gid_t gid;
-        int r;
-
-        assert(m);
-        assert(name);
-
-        r = get_user_creds(&name, &uid, &gid, NULL, NULL);
-        if (r < 0)
-                return r;
-
-        return manager_add_user(m, uid, gid, name, _user);
-}
-
-int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user) {
-        struct passwd *p;
-
-        assert(m);
-
-        errno = 0;
-        p = getpwuid(uid);
-        if (!p)
-                return errno ? -errno : -ENOENT;
-
-        return manager_add_user(m, uid, p->pw_gid, p->pw_name, _user);
-}
-
-int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor) {
-        Inhibitor *i;
-
-        assert(m);
-        assert(id);
-
-        i = hashmap_get(m->inhibitors, id);
-        if (i) {
-                if (_inhibitor)
-                        *_inhibitor = i;
-
-                return 0;
-        }
-
-        i = inhibitor_new(m, id);
-        if (!i)
-                return -ENOMEM;
-
-        if (_inhibitor)
-                *_inhibitor = i;
-
-        return 0;
-}
-
-int manager_add_button(Manager *m, const char *name, Button **_button) {
-        Button *b;
-
-        assert(m);
-        assert(name);
-
-        b = hashmap_get(m->buttons, name);
-        if (b) {
-                if (_button)
-                        *_button = b;
-
-                return 0;
-        }
-
-        b = button_new(m, name);
-        if (!b)
-                return -ENOMEM;
-
-        if (_button)
-                *_button = b;
-
-        return 0;
-}
-
-int manager_watch_busname(Manager *m, const char *name) {
-        char *n;
-        int r;
-
-        assert(m);
-        assert(name);
-
-        if (hashmap_get(m->busnames, name))
-                return 0;
-
-        n = strdup(name);
-        if (!n)
-                return -ENOMEM;
-
-        r = hashmap_put(m->busnames, n, n);
-        if (r < 0) {
-                free(n);
-                return r;
-        }
-
-        return 0;
-}
-
-void manager_drop_busname(Manager *m, const char *name) {
-        Session *session;
-        Iterator i;
-        char *key;
-
-        assert(m);
-        assert(name);
-
-        if (!hashmap_get(m->busnames, name))
-                return;
-
-        /* keep it if the name still owns a controller */
-        HASHMAP_FOREACH(session, m->sessions, i)
-                if (session_is_controller(session, name))
-                        return;
-
-        key = hashmap_remove(m->busnames, name);
-        if (key)
-                free(key);
-}
-
-int manager_process_seat_device(Manager *m, struct udev_device *d) {
-        Device *device;
-        int r;
-
-        assert(m);
-
-        if (streq_ptr(udev_device_get_action(d), "remove")) {
-
-                device = hashmap_get(m->devices, udev_device_get_syspath(d));
-                if (!device)
-                        return 0;
-
-                seat_add_to_gc_queue(device->seat);
-                device_free(device);
-
-        } else {
-                const char *sn;
-                Seat *seat = NULL;
-                bool master;
-
-                sn = udev_device_get_property_value(d, "ID_SEAT");
-                if (isempty(sn))
-                        sn = "seat0";
-
-                if (!seat_name_is_valid(sn)) {
-                        log_warning("Device with invalid seat name %s found, ignoring.", sn);
-                        return 0;
-                }
-
-                /* ignore non-master devices for unknown seats */
-                master = udev_device_has_tag(d, "master-of-seat");
-                if (!master && !(seat = hashmap_get(m->seats, sn)))
-                        return 0;
-
-                r = manager_add_device(m, udev_device_get_syspath(d), master, &device);
-                if (r < 0)
-                        return r;
-
-                if (!seat) {
-                        r = manager_add_seat(m, sn, &seat);
-                        if (r < 0) {
-                                if (!device->seat)
-                                        device_free(device);
-
-                                return r;
-                        }
-                }
-
-                device_attach(device, seat);
-                seat_start(seat);
-        }
-
-        return 0;
-}
-
-int manager_process_button_device(Manager *m, struct udev_device *d) {
-        Button *b;
-
-        int r;
-
-        assert(m);
-
-        if (streq_ptr(udev_device_get_action(d), "remove")) {
-
-                b = hashmap_get(m->buttons, udev_device_get_sysname(d));
-                if (!b)
-                        return 0;
-
-                button_free(b);
-
-        } else {
-                const char *sn;
-
-                r = manager_add_button(m, udev_device_get_sysname(d), &b);
-                if (r < 0)
-                        return r;
-
-                sn = udev_device_get_property_value(d, "ID_SEAT");
-                if (isempty(sn))
-                        sn = "seat0";
-
-                button_set_seat(b, sn);
-                button_open(b);
-        }
-
-        return 0;
-}
-
 int manager_enumerate_devices(Manager *m) {
         struct udev_list_entry *item = NULL, *first = NULL;
         struct udev_enumerate *e;
@@ -890,80 +581,6 @@ int manager_dispatch_console(Manager *m) {
         return 0;
 }
 
-static int vt_is_busy(int vtnr) {
-        struct vt_stat vt_stat;
-        int r = 0, fd;
-
-        assert(vtnr >= 1);
-
-        /* We explicitly open /dev/tty1 here instead of /dev/tty0. If
-         * we'd open the latter we'd open the foreground tty which
-         * hence would be unconditionally busy. By opening /dev/tty1
-         * we avoid this. Since tty1 is special and needs to be an
-         * explicitly loaded getty or DM this is safe. */
-
-        fd = open_terminal("/dev/tty1", O_RDWR|O_NOCTTY|O_CLOEXEC);
-        if (fd < 0)
-                return -errno;
-
-        if (ioctl(fd, VT_GETSTATE, &vt_stat) < 0)
-                r = -errno;
-        else
-                r = !!(vt_stat.v_state & (1 << vtnr));
-
-        close_nointr_nofail(fd);
-
-        return r;
-}
-
-int manager_spawn_autovt(Manager *m, int vtnr) {
-        int r;
-        char *name = NULL;
-        const char *mode = "fail";
-
-        assert(m);
-        assert(vtnr >= 1);
-
-        if ((unsigned) vtnr > m->n_autovts &&
-            (unsigned) vtnr != m->reserve_vt)
-                return 0;
-
-        if ((unsigned) vtnr != m->reserve_vt) {
-                /* If this is the reserved TTY, we'll start the getty
-                 * on it in any case, but otherwise only if it is not
-                 * busy. */
-
-                r = vt_is_busy(vtnr);
-                if (r < 0)
-                        return r;
-                else if (r > 0)
-                        return -EBUSY;
-        }
-
-        if (asprintf(&name, "autovt at tty%i.service", vtnr) < 0) {
-                log_error("Could not allocate service name.");
-                r = -ENOMEM;
-                goto finish;
-        }
-
-        r = bus_method_call_with_reply (
-                        m->bus,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
-                        "StartUnit",
-                        NULL,
-                        NULL,
-                        DBUS_TYPE_STRING, &name,
-                        DBUS_TYPE_STRING, &mode,
-                        DBUS_TYPE_INVALID);
-
-finish:
-        free(name);
-
-        return r;
-}
-
 static int manager_reserve_vt(Manager *m) {
         _cleanup_free_ char *p = NULL;
 
@@ -987,52 +604,6 @@ static int manager_reserve_vt(Manager *m) {
         return 0;
 }
 
-int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) {
-        _cleanup_free_ char *unit = NULL;
-        Session *s;
-        int r;
-
-        assert(m);
-        assert(session);
-
-        if (pid < 1)
-                return -EINVAL;
-
-        r = cg_pid_get_unit(pid, &unit);
-        if (r < 0)
-                return r;
-
-        s = hashmap_get(m->session_units, unit);
-        if (!s)
-                return 0;
-
-        *session = s;
-        return 1;
-}
-
-int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) {
-        _cleanup_free_ char *unit = NULL;
-        User *u;
-        int r;
-
-        assert(m);
-        assert(user);
-
-        if (pid < 1)
-                return -EINVAL;
-
-        r = cg_pid_get_slice(pid, &unit);
-        if (r < 0)
-                return r;
-
-        u = hashmap_get(m->user_units, unit);
-        if (!u)
-                return 0;
-
-        *user = u;
-        return 1;
-}
-
 static void manager_dispatch_other(Manager *m, int fd) {
         Session *s;
         Inhibitor *i;
@@ -1390,61 +961,6 @@ void manager_gc(Manager *m, bool drop_not_started) {
         }
 }
 
-int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
-        Session *s;
-        bool idle_hint;
-        dual_timestamp ts = { 0, 0 };
-        Iterator i;
-
-        assert(m);
-
-        idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false, false, 0);
-
-        HASHMAP_FOREACH(s, m->sessions, i) {
-                dual_timestamp k;
-                int ih;
-
-                ih = session_get_idle_hint(s, &k);
-                if (ih < 0)
-                        return ih;
-
-                if (!ih) {
-                        if (!idle_hint) {
-                                if (k.monotonic < ts.monotonic)
-                                        ts = k;
-                        } else {
-                                idle_hint = false;
-                                ts = k;
-                        }
-                } else if (idle_hint) {
-
-                        if (k.monotonic > ts.monotonic)
-                                ts = k;
-                }
-        }
-
-        if (t)
-                *t = ts;
-
-        return idle_hint;
-}
-
-bool manager_shall_kill(Manager *m, const char *user) {
-        assert(m);
-        assert(user);
-
-        if (!m->kill_user_processes)
-                return false;
-
-        if (strv_contains(m->kill_exclude_users, user))
-                return false;
-
-        if (strv_isempty(m->kill_only_users))
-                return true;
-
-        return strv_contains(m->kill_only_users, user);
-}
-
 int manager_dispatch_idle_action(Manager *m) {
         struct dual_timestamp since;
         struct itimerspec its = {};

commit bd16acf35e13a19cd2ded0a0c2ef774a98f73808
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Sep 25 13:26:08 2013 +0200

    Move functions around to fix underlinking in test-machine-tables

diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index a526a52..22caadf 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -40,6 +40,7 @@
 #include "unit-name.h"
 #include "bus-errors.h"
 #include "virt.h"
+#include "cgroup-util.h"
 
 #define BUS_MANAGER_INTERFACE                                           \
         " <interface name=\"org.freedesktop.machine1.Manager\">\n"      \
@@ -994,3 +995,48 @@ int manager_unit_is_active(Manager *manager, const char *unit) {
 
         return !streq(state, "inactive") && !streq(state, "failed");
 }
+
+int manager_add_machine(Manager *m, const char *name, Machine **_machine) {
+        Machine *machine;
+
+        assert(m);
+        assert(name);
+
+        machine = hashmap_get(m->machines, name);
+        if (machine) {
+                if (_machine)
+                        *_machine = machine;
+
+                return 0;
+        }
+
+        machine = machine_new(m, name);
+        if (!machine)
+                return -ENOMEM;
+
+        if (_machine)
+                *_machine = machine;
+
+        return 0;
+}
+
+int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
+        _cleanup_free_ char *unit = NULL;
+        Machine *mm;
+        int r;
+
+        assert(m);
+        assert(pid >= 1);
+        assert(machine);
+
+        r = cg_pid_get_unit(pid, &unit);
+        if (r < 0)
+                return r;
+
+        mm = hashmap_get(m->machine_units, unit);
+        if (!mm)
+                return 0;
+
+        *machine = mm;
+        return 1;
+}
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 3ce51da..ad804a1 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -34,7 +34,6 @@
 #include "strv.h"
 #include "conf-parser.h"
 #include "mkdir.h"
-#include "cgroup-util.h"
 
 Manager *manager_new(void) {
         Manager *m;
@@ -83,30 +82,6 @@ void manager_free(Manager *m) {
         free(m);
 }
 
-int manager_add_machine(Manager *m, const char *name, Machine **_machine) {
-        Machine *machine;
-
-        assert(m);
-        assert(name);
-
-        machine = hashmap_get(m->machines, name);
-        if (machine) {
-                if (_machine)
-                        *_machine = machine;
-
-                return 0;
-        }
-
-        machine = machine_new(m, name);
-        if (!machine)
-                return -ENOMEM;
-
-        if (_machine)
-                *_machine = machine;
-
-        return 0;
-}
-
 int manager_enumerate_machines(Manager *m) {
         _cleanup_closedir_ DIR *d = NULL;
         struct dirent *de;
@@ -149,27 +124,6 @@ int manager_enumerate_machines(Manager *m) {
         return r;
 }
 
-int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
-        _cleanup_free_ char *unit = NULL;
-        Machine *mm;
-        int r;
-
-        assert(m);
-        assert(pid >= 1);
-        assert(machine);
-
-        r = cg_pid_get_unit(pid, &unit);
-        if (r < 0)
-                return r;
-
-        mm = hashmap_get(m->machine_units, unit);
-        if (!mm)
-                return 0;
-
-        *machine = mm;
-        return 1;
-}
-
 static int manager_connect_bus(Manager *m) {
         DBusError error;
         int r;

commit 732bfe09aeffc3cd78b80ee9e20c9c3babd944d6
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Sep 26 10:31:44 2013 +0200

    build-sys: add ./configure --enable-address-sanitizer
    
    Enabling address sanitizer seems like a useful thing, but is quite
    tricky. Proper flags have to be passed to CPPFLAGS, CFLAGS and
    LDFLAGS, but passing them on the commandline doesn't work because
    we tests are done with ld directly, and not with libtool like in
    real linking. We might want to fix this, but let's add a handy
    way to enable address checking anyway.

diff --git a/configure.ac b/configure.ac
index 156cc96..af0dbbe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,20 @@ if test -z "$GPERF" ; then
         AC_MSG_ERROR([*** gperf not found])
 fi
 
+# ------------------------------------------------------------------------------
+address_sanitizer_cflags=
+address_sanitizer_cppflags=
+address_sanitizer_ldflags=
+AC_ARG_ENABLE(address-sanitizer, AS_HELP_STRING([--enable-address-sanitizer], [enable -fsanitize=address]))
+AS_IF([test "x$enable_address_sanitizer" = "xyes"], [
+            CC_CHECK_FLAG_APPEND([with_as_cflags], [CFLAGS], [-fsanitize=address])
+            AS_IF([test -z "$with_as_cflags"],
+                  [AC_MSG_ERROR([*** -fsanitize=address is not supported])])
+            address_sanitizer_cflags="$with_as_cflags -fno-omit-frame-pointer -DVALGRIND=1"
+            address_sanitizer_cppflags="-DVALGRIND=1"
+            address_sanitizer_ldflags="-Wc,-fsanitize=address"
+      ])
+
 CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\
         -pipe \
         -Wall \
@@ -142,13 +156,13 @@ CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\
         -fdata-sections \
         -fstack-protector \
         --param=ssp-buffer-size=4])
-AC_SUBST([OUR_CFLAGS], $with_cflags)
+AC_SUBST([OUR_CFLAGS], "$with_cflags $address_sanitizer_cflags")
 
 AS_CASE([$CFLAGS], [*-O[[12345g\ ]]*],
         [CC_CHECK_FLAGS_APPEND([with_cppflags], [CPPFLAGS], [\
                -Wp,-D_FORTIFY_SOURCE=2])],
         [AC_MSG_RESULT([skipping -D_FORTIFY_SOURCE, optimization not enabled])])
-AC_SUBST([OUR_CPPFLAGS], $with_cppflags)
+AC_SUBST([OUR_CPPFLAGS], "$with_cppflags $address_sanitizer_cppflags")
 
 CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [\
         -Wl,--as-needed \
@@ -156,7 +170,7 @@ CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [\
         -Wl,--gc-sections \
         -Wl,-z,relro \
         -Wl,-z,now])
-AC_SUBST([OUR_LDFLAGS], $with_ldflags)
+AC_SUBST([OUR_LDFLAGS], "$with_ldflags $address_sanitizer_ldflags")
 
 # ------------------------------------------------------------------------------
 # we use python to build the man page index, and for systemd-python

commit 5843c5ebb4341382ae9c87e93c2c87467e573548
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Sep 19 16:57:57 2013 -0500

    journald: accept EPOLLERR from /dev/kmsg
    
    Also print out unexpected epoll events explictly.

diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index cc8ce0d..e888480 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1060,7 +1060,8 @@ int process_event(Server *s, struct epoll_event *ev) {
                 ssize_t n;
 
                 if (ev->events != EPOLLIN) {
-                        log_error("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll for %s: %"PRIx32,
+                                  "signal fd", ev->events);
                         return -EIO;
                 }
 
@@ -1113,8 +1114,12 @@ int process_event(Server *s, struct epoll_event *ev) {
         } else if (ev->data.fd == s->dev_kmsg_fd) {
                 int r;
 
-                if (ev->events != EPOLLIN) {
-                        log_error("Got invalid event from epoll.");
+                if (ev->events & EPOLLERR)
+                        log_warning("/dev/kmsg buffer overrun, some messages lost.");
+
+                if (!(ev->events & EPOLLIN)) {
+                        log_error("Got invalid event from epoll for %s: %"PRIx32,
+                                  "/dev/kmsg", ev->events);
                         return -EIO;
                 }
 
@@ -1128,7 +1133,9 @@ int process_event(Server *s, struct epoll_event *ev) {
                    ev->data.fd == s->syslog_fd) {
 
                 if (ev->events != EPOLLIN) {
-                        log_error("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll for %s: %"PRIx32,
+                                  ev->data.fd == s->native_fd ? "native fd" : "syslog fd",
+                                  ev->events);
                         return -EIO;
                 }
 
@@ -1249,7 +1256,8 @@ int process_event(Server *s, struct epoll_event *ev) {
         } else if (ev->data.fd == s->stdout_fd) {
 
                 if (ev->events != EPOLLIN) {
-                        log_error("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll for %s: %"PRIx32,
+                                  "stdout fd", ev->events);
                         return -EIO;
                 }
 
@@ -1260,6 +1268,8 @@ int process_event(Server *s, struct epoll_event *ev) {
                 StdoutStream *stream;
 
                 if ((ev->events|EPOLLIN|EPOLLHUP) != (EPOLLIN|EPOLLHUP)) {
+                        log_error("Got invalid event from epoll for %s: %"PRIx32,
+                                  "stdout stream", ev->events);
                         log_error("Got invalid event from epoll.");
                         return -EIO;
                 }

commit 8097ab4f0cf7a52ac6ca45cb2b2dfe4850a2dee5
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Sep 25 17:52:43 2013 +0200

    test-hashmap: fix access to uninitialized memory

diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
index 2aead79..2c27d08 100644
--- a/src/test/test-hashmap.c
+++ b/src/test/test-hashmap.c
@@ -468,9 +468,11 @@ static void test_hashmap_get(void) {
 }
 
 static void test_uint64_compare_func(void) {
-        assert_se(uint64_compare_func("a", "a") == 0);
-        assert_se(uint64_compare_func("a", "b") == -1);
-        assert_se(uint64_compare_func("b", "a") == 1);
+        const uint64_t a = 0x100, b = 0x101;
+
+        assert_se(uint64_compare_func(&a, &a) == 0);
+        assert_se(uint64_compare_func(&a, &b) == -1);
+        assert_se(uint64_compare_func(&b, &a) == 1);
 }
 
 static void test_trivial_compare_func(void) {

commit f546241b6dd82d20ff915f618d143a19db8a4574
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Aug 28 07:54:43 2013 -0400

    execute.c: little modernization

diff --git a/src/core/execute.c b/src/core/execute.c
index 0bfa418..a53ef48 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -760,24 +760,30 @@ static int setup_pam(
          * daemon. We do things this way to ensure that the main PID
          * of the daemon is the one we initially fork()ed. */
 
-        if ((pam_code = pam_start(name, user, &conv, &handle)) != PAM_SUCCESS) {
+        pam_code = pam_start(name, user, &conv, &handle);
+        if (pam_code != PAM_SUCCESS) {
                 handle = NULL;
                 goto fail;
         }
 
-        if (tty)
-                if ((pam_code = pam_set_item(handle, PAM_TTY, tty)) != PAM_SUCCESS)
+        if (tty) {
+                pam_code = pam_set_item(handle, PAM_TTY, tty);
+                if (pam_code != PAM_SUCCESS)
                         goto fail;
+        }
 
-        if ((pam_code = pam_acct_mgmt(handle, PAM_SILENT)) != PAM_SUCCESS)
+        pam_code = pam_acct_mgmt(handle, PAM_SILENT);
+        if (pam_code != PAM_SUCCESS)
                 goto fail;
 
-        if ((pam_code = pam_open_session(handle, PAM_SILENT)) != PAM_SUCCESS)
+        pam_code = pam_open_session(handle, PAM_SILENT);
+        if (pam_code != PAM_SUCCESS)
                 goto fail;
 
         close_session = true;
 
-        if ((!(e = pam_getenvlist(handle)))) {
+        e = pam_getenvlist(handle);
+        if (!e) {
                 pam_code = PAM_BUF_ERR;
                 goto fail;
         }
@@ -791,7 +797,8 @@ static int setup_pam(
 
         parent_pid = getpid();
 
-        if ((pam_pid = fork()) < 0)
+        pam_pid = fork();
+        if (pam_pid < 0)
                 goto fail;
 
         if (pam_pid == 0) {
@@ -842,9 +849,11 @@ static int setup_pam(
                 }
 
                 /* If our parent died we'll end the session */
-                if (getppid() != parent_pid)
-                        if ((pam_code = pam_close_session(handle, PAM_DATA_SILENT)) != PAM_SUCCESS)
+                if (getppid() != parent_pid) {
+                        pam_code = pam_close_session(handle, PAM_DATA_SILENT);
+                        if (pam_code != PAM_SUCCESS)
                                 goto child_finish;
+                }
 
                 r = 0;
 



More information about the systemd-commits mailing list