[systemd-commits] 4 commits - .gitignore Makefile.am TODO src/core src/login src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Fri Sep 21 03:47:44 PDT 2012


 .gitignore                 |    1 
 Makefile.am                |   11 --
 TODO                       |    4 
 src/core/selinux-access.c  |    1 
 src/login/logind-button.c  |    4 
 src/login/logind-dbus.c    |   33 ++++---
 src/login/logind-inhibit.c |    9 +-
 src/login/logind-inhibit.h |    2 
 src/login/logind.c         |    2 
 src/login/multi-seat-x.c   |  196 ---------------------------------------------
 src/shared/log.c           |    2 
 src/shared/util.c          |    4 
 12 files changed, 38 insertions(+), 231 deletions(-)

New commits:
commit 636d30a0895f17eca8313d50f9b2fc1ec5e128da
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 21 12:46:22 2012 +0200

    multi-seat: drop multi-seat-x wrapper, as upstream X can handle multi-seat graphics on its own now

diff --git a/.gitignore b/.gitignore
index cc904f1..c1459ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,7 +13,6 @@
 /build-aux
 /test-watchdog
 /test-journal-send
-/systemd-multi-seat-x
 /systemd-cgtop
 /systemd-coredump
 /systemd-cat
diff --git a/Makefile.am b/Makefile.am
index 36b33c2..1828d7f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3347,17 +3347,6 @@ logind-install-data-hook:
 INSTALL_DATA_HOOKS += \
 	logind-install-data-hook
 
-systemd_multi_seat_x_SOURCES = \
-	src/login/multi-seat-x.c
-
-systemd_multi_seat_x_LDADD = \
-	libsystemd-label.la \
-	libsystemd-shared.la \
-	libudev.la
-
-rootlibexec_PROGRAMS += \
-	systemd-multi-seat-x
-
 dist_udevrules_DATA += \
 	src/login/70-uaccess.rules \
 	src/login/70-power-switch.rules
diff --git a/src/login/multi-seat-x.c b/src/login/multi-seat-x.c
deleted file mode 100644
index 59f7088..0000000
--- a/src/login/multi-seat-x.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*-*- 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 <string.h>
-#include <unistd.h>
-
-#include <libudev.h>
-
-#include "util.h"
-#include "mkdir.h"
-
-int main(int argc, char *argv[]) {
-
-        struct udev *udev = NULL;
-        struct udev_enumerate *enumerator = NULL;
-        struct udev_list_entry *first, *item;
-        int i;
-        const char *seat = NULL;
-        char **new_argv;
-        char *path = NULL, *device_node = NULL;
-        int r;
-        FILE *f = NULL;
-
-        /* This binary will go away as soon as X natively supports
-         * display enumeration with udev in a way that covers both PCI
-         * and USB. */
-
-        /* This will simply determine the fb device id of the graphics
-         * device assigned to a seat and write a configuration file
-         * from it and then spawn the real X server. */
-
-        /* If this file is removed, don't forget to remove the code
-         * that invokes this in gdm and other display managers. */
-
-        for (i = 1; i < argc; i++)
-                if (streq(argv[i], "-seat"))
-                        seat = argv[i+1];
-
-        if (isempty(seat) || streq(seat, "seat0")) {
-                argv[0] = (char*) X_SERVER;
-                execv(X_SERVER, argv);
-                log_error("Failed to execute real X server: %m");
-                goto fail;
-        }
-
-        udev = udev_new();
-        if (!udev) {
-                log_error("Failed to allocate udev environment.");
-                goto fail;
-        }
-
-        enumerator = udev_enumerate_new(udev);
-        if (!enumerator) {
-                log_error("Failed to allocate udev enumerator.");
-                goto fail;
-        }
-
-        udev_enumerate_add_match_subsystem(enumerator, "graphics");
-        udev_enumerate_add_match_tag(enumerator, seat);
-
-        r = udev_enumerate_scan_devices(enumerator);
-        if (r < 0) {
-                log_error("Failed to enumerate devices.");
-                goto fail;
-        }
-
-        first = udev_enumerate_get_list_entry(enumerator);
-        udev_list_entry_foreach(item, first) {
-                struct udev_device *d;
-                const char *dn;
-
-                d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
-                if (!d)
-                        continue;
-
-                dn = udev_device_get_devnode(d);
-
-                if (dn) {
-                        device_node = strdup(dn);
-                        if (!device_node) {
-                                udev_device_unref(d);
-                                log_oom();
-                                goto fail;
-                        }
-                }
-
-                udev_device_unref(d);
-
-                if (device_node)
-                        break;
-        }
-
-        if (!device_node) {
-                log_error("Failed to find device node for seat %s.", seat);
-                goto fail;
-        }
-
-        r = mkdir_safe_label("/run/systemd/multi-session-x", 0755, 0, 0);
-        if (r < 0) {
-                log_error("Failed to create directory: %s", strerror(-r));
-                goto fail;
-        }
-
-        path = strappend("/run/systemd/multi-session-x/", seat);
-        if (!path) {
-                log_oom();
-                goto fail;
-        }
-
-        f = fopen(path, "we");
-        if (!f) {
-                log_error("Failed to write configuration file: %m");
-                goto fail;
-        }
-
-        fprintf(f,
-                "Section \"Device\"\n"
-                "        Identifier \"udev\"\n"
-                "        Driver \"fbdev\"\n"
-                "        Option \"fbdev\" \"%s\"\n"
-                "EndSection\n"
-                "Section \"ServerFlags\"\n"
-                "        Option \"AutoAddDevices\" \"True\"\n"
-                "        Option \"AllowEmptyInput\" \"True\"\n"
-                "        Option \"DontVTSwitch\" \"True\"\n"
-                "EndSection\n"
-                "Section \"InputClass\"\n"
-                "        Identifier \"Force Input Devices to Seat\"\n"
-                "        Option \"GrabDevice\" \"True\"\n"
-                "EndSection\n",
-                device_node);
-
-        fflush(f);
-
-        if (ferror(f)) {
-                log_error("Failed to write configuration file: %m");
-                goto fail;
-        }
-
-        fclose(f);
-        f = NULL;
-
-        new_argv = alloca(sizeof(char*) * (argc + 3 + 1));
-        memcpy(new_argv, argv, sizeof(char*) * (argc + 2 + 1));
-
-        new_argv[0] = (char*) X_SERVER;
-        new_argv[argc+0] = (char*) "-config";
-        new_argv[argc+1] = path;
-        new_argv[argc+2] = (char*) "-sharevts";
-        new_argv[argc+3] = NULL;
-
-        udev_enumerate_unref(enumerator);
-        enumerator = NULL;
-
-        udev_unref(udev);
-        udev = NULL;
-
-        free(device_node);
-        device_node = NULL;
-
-        execv(X_SERVER, new_argv);
-        log_error("Failed to execute real X server: %m");
-
-fail:
-        if (enumerator)
-                udev_enumerate_unref(enumerator);
-
-        if (udev)
-                udev_unref(udev);
-
-        free(path);
-        free(device_node);
-
-        if (f)
-                fclose(f);
-
-        return EXIT_FAILURE;
-}

commit 7f1736f73619fcadcb974640dc1052aa0c654850
Author: Lukas Nykryn <lnykryn at redhat.com>
Date:   Fri Sep 21 10:23:08 2012 +0200

    core: call va_end in all cases

diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
index 8a84071..8513634 100644
--- a/src/core/selinux-access.c
+++ b/src/core/selinux-access.c
@@ -276,6 +276,7 @@ static int log_callback(int type, const char *fmt, ...)
                 vsnprintf(buf, sizeof(buf), fmt, ap);
                 audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC,
                                            buf, NULL, NULL, NULL, 0);
+                va_end(ap);
                 return 0;
         }
 #endif

commit e98055de981b568c31f18f470181ae166b56f172
Author: Lukas Nykryn <lnykryn at redhat.com>
Date:   Fri Sep 21 10:22:46 2012 +0200

    shared: call va_end in all cases

diff --git a/src/shared/log.c b/src/shared/log.c
index 7b0a914..b618458 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -719,7 +719,6 @@ int log_struct_internal(
 
                         format = va_arg(ap, char *);
                 }
-                va_end(ap);
 
                 zero(mh);
                 mh.msg_iov = iovec;
@@ -731,6 +730,7 @@ int log_struct_internal(
                         r = 1;
 
         finish:
+                va_end(ap);
                 for (i = 1; i < n; i += 2)
                         free(iovec[i].iov_base);
 
diff --git a/src/shared/util.c b/src/shared/util.c
index be94515..97f766c 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5024,8 +5024,10 @@ char *strjoin(const char *x, ...) {
                                 break;
 
                         n = strlen(t);
-                        if (n > ((size_t) -1) - l)
+                        if (n > ((size_t) -1) - l) {
+                                va_end(ap);
                                 return NULL;
+                        }
 
                         l += n;
                 }

commit 409133be63387fc04d927e8aecd2f6ba03d2f143
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 21 11:57:48 2012 +0200

    logind: allow users to override their own suspend/sleep inhibitors

diff --git a/TODO b/TODO
index 61f1fa4..051d22b 100644
--- a/TODO
+++ b/TODO
@@ -19,6 +19,10 @@ F18:
 
 Features:
 
+* allow users from "wheel" to start/stop services
+
+* systemctl: when powering down/suspending check for inhibitors, and warn.
+
 * instantiated [Install] for target units
   https://bugs.freedesktop.org/show_bug.cgi?id=54377
 
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index d0c9ccd..e2d9fd2 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -188,7 +188,7 @@ static int button_handle(
         }
 
         /* If the key handling is inhibited, don't do anything */
-        if (manager_is_inhibited(b->manager, inhibit_key, INHIBIT_BLOCK, NULL, true)) {
+        if (manager_is_inhibited(b->manager, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0)) {
                 log_debug("Refusing key handling, %s is inhibited.", inhibit_what_to_string(inhibit_key));
                 return 0;
         }
@@ -197,7 +197,7 @@ static int button_handle(
 
         /* If the actual operation is inhibited, warn and fail */
         if (!ignore_inhibited &&
-            manager_is_inhibited(b->manager, inhibit_operation, INHIBIT_BLOCK, NULL, false)) {
+            manager_is_inhibited(b->manager, inhibit_operation, INHIBIT_BLOCK, NULL, false, false, 0)) {
 
 
                 /* If this is just a recheck of the lid switch then don't warn about anything */
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 4ae5ba7..650be34 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -956,24 +956,17 @@ static int flush_devices(Manager *m) {
 }
 
 static int have_multiple_sessions(
-                DBusConnection *connection,
                 Manager *m,
-                DBusMessage *message,
-                DBusError *error) {
+                uid_t uid) {
 
         Session *session;
         Iterator i;
-        unsigned long ul;
 
         assert(m);
 
-        ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
-        if (ul == (unsigned long) -1)
-                return -EIO;
-
         /* Check for other users' sessions. Greeter sessions do not count. */
         HASHMAP_FOREACH(session, m->sessions, i)
-                if (session->class == SESSION_USER && session->user->uid != ul)
+                if (session->class == SESSION_USER && session->user->uid != uid)
                         return true;
 
         return false;
@@ -1060,6 +1053,7 @@ static int bus_manager_can_shutdown_or_sleep(
         const char *result;
         DBusMessage *reply = NULL;
         int r;
+        unsigned long ul;
 
         assert(m);
         assert(connection);
@@ -1083,12 +1077,16 @@ static int bus_manager_can_shutdown_or_sleep(
                 }
         }
 
-        r = have_multiple_sessions(connection, m, message, error);
+        ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
+        if (ul == (unsigned long) -1)
+                return -EIO;
+
+        r = have_multiple_sessions(m, (uid_t) ul);
         if (r < 0)
                 return r;
 
         multiple_sessions = r > 0;
-        blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false);
+        blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, (uid_t) ul);
 
         if (multiple_sessions) {
                 r = verify_polkit(connection, message, action_multiple_sessions, false, &challenge, error);
@@ -1202,7 +1200,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(
 
         delayed =
                 m->inhibit_delay_max > 0 &&
-                manager_is_inhibited(m, w, INHIBIT_DELAY, NULL, false);
+                manager_is_inhibited(m, w, INHIBIT_DELAY, NULL, false, false, 0);
 
         if (delayed)
                 /* Shutdown is delayed, keep in mind what we
@@ -1236,6 +1234,7 @@ static int bus_manager_do_shutdown_or_sleep(
         bool multiple_sessions, blocked;
         DBusMessage *reply = NULL;
         int r;
+        unsigned long ul;
 
         assert(m);
         assert(connection);
@@ -1265,12 +1264,16 @@ static int bus_manager_do_shutdown_or_sleep(
                         return -ENOTSUP;
         }
 
-        r = have_multiple_sessions(connection, m, message, error);
+        ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
+        if (ul == (unsigned long) -1)
+                return -EIO;
+
+        r = have_multiple_sessions(m, (uid_t) ul);
         if (r < 0)
                 return r;
 
         multiple_sessions = r > 0;
-        blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false);
+        blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, (uid_t) ul);
 
         if (multiple_sessions) {
                 r = verify_polkit(connection, message, action_multiple_sessions, interactive, NULL, error);
@@ -2303,7 +2306,7 @@ int manager_dispatch_delayed(Manager *manager) {
         /* Continue delay? */
         delayed =
                 manager->delayed_timestamp + manager->inhibit_delay_max > now(CLOCK_MONOTONIC) &&
-                manager_is_inhibited(manager, manager->delayed_what, INHIBIT_DELAY, NULL, false);
+                manager_is_inhibited(manager, manager->delayed_what, INHIBIT_DELAY, NULL, false, false, 0);
         if (delayed)
                 return 0;
 
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index fce2f4d..66e4c29 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -364,7 +364,9 @@ bool manager_is_inhibited(
                 InhibitWhat w,
                 InhibitMode mm,
                 dual_timestamp *since,
-                bool only_active) {
+                bool ignore_inactive,
+                bool ignore_uid,
+                uid_t uid) {
 
         Inhibitor *i;
         Iterator j;
@@ -381,7 +383,10 @@ bool manager_is_inhibited(
                 if (i->mode != mm)
                         continue;
 
-                if (only_active && pid_is_active(m, i->pid) <= 0)
+                if (ignore_inactive && pid_is_active(m, i->pid) <= 0)
+                        continue;
+
+                if (ignore_uid && i->uid == uid)
                         continue;
 
                 if (!inhibited ||
diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h
index d89a1b3..f5cfb9b 100644
--- a/src/login/logind-inhibit.h
+++ b/src/login/logind-inhibit.h
@@ -83,7 +83,7 @@ int inhibitor_create_fifo(Inhibitor *i);
 void inhibitor_remove_fifo(Inhibitor *i);
 
 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm);
-bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool only_active);
+bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid);
 
 const char *inhibit_what_to_string(InhibitWhat k);
 InhibitWhat inhibit_what_from_string(const char *s);
diff --git a/src/login/logind.c b/src/login/logind.c
index 14c8355..ccd18b9 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1407,7 +1407,7 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
 
         assert(m);
 
-        idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false);
+        idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false, false, 0);
 
         HASHMAP_FOREACH(s, m->sessions, i) {
                 dual_timestamp k;



More information about the systemd-commits mailing list