[systemd-commits] 3 commits - src/dbus-common.c src/main.c src/util.c TODO

Lennart Poettering lennart at kemper.freedesktop.org
Thu Mar 10 15:52:37 PST 2011


 TODO              |    6 +++++-
 src/dbus-common.c |   39 +++++++++++++++++++++++++++++++++++++++
 src/main.c        |   24 ++++++++++++++++++------
 src/util.c        |   18 ++++++++++--------
 4 files changed, 72 insertions(+), 15 deletions(-)

New commits:
commit 720ce21d444f6497299c4c99a76fda546b06716a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Mar 11 00:52:13 2011 +0100

    util: close all fds before freezing execution

diff --git a/TODO b/TODO
index f2e3be4..daa9677 100644
--- a/TODO
+++ b/TODO
@@ -22,8 +22,6 @@ F15:
 
 * bind mounts are ignored
 
-* SIGALRM in systemctl
-
 * 0595f9a1c182a84581749823ef47c5f292e545f9 is borked, freezes shutdown
 
 Features:
diff --git a/src/dbus-common.c b/src/dbus-common.c
index 80b2115..809ea0f 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -77,6 +77,9 @@ int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private, DBusError *
                         return -EACCES;
                 }
 
+                /* This complexity should probably move into D-Bus itself:
+                 *
+                 * https://bugs.freedesktop.org/show_bug.cgi?id=35189 */
                 begin = tstamp = now(CLOCK_MONOTONIC);
                 for (;;) {
 
diff --git a/src/util.c b/src/util.c
index c02b39e..c9366c4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1815,8 +1815,9 @@ int close_all_fds(const int except[], unsigned n_except) {
                 if (ignore_file(de->d_name))
                         continue;
 
-                if ((r = safe_atoi(de->d_name, &fd)) < 0)
-                        goto finish;
+                if (safe_atoi(de->d_name, &fd) < 0)
+                        /* Let's better ignore this, just in case */
+                        continue;
 
                 if (fd < 3)
                         continue;
@@ -1839,16 +1840,13 @@ int close_all_fds(const int except[], unsigned n_except) {
                                 continue;
                 }
 
-                if ((r = close_nointr(fd)) < 0) {
+                if (close_nointr(fd) < 0) {
                         /* Valgrind has its own FD and doesn't want to have it closed */
-                        if (errno != EBADF)
-                                goto finish;
+                        if (errno != EBADF && r == 0)
+                                r = -errno;
                 }
         }
 
-        r = 0;
-
-finish:
         closedir(d);
         return r;
 }
@@ -3619,6 +3617,10 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid) {
 }
 
 void freeze(void) {
+
+        /* Make sure nobody waits for us on a socket anymore */
+        close_all_fds(NULL, 0);
+
         sync();
 
         for (;;)

commit b997812119882f95a9456ce15667b0545be8e417
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Mar 11 00:45:06 2011 +0100

    dbus: timeout connection setup

diff --git a/src/dbus-common.c b/src/dbus-common.c
index 69593cd..80b2115 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -27,6 +27,7 @@
 
 #include "log.h"
 #include "dbus-common.h"
+#include "util.h"
 
 int bus_check_peercred(DBusConnection *c) {
         int fd;
@@ -59,19 +60,54 @@ int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private, DBusError *
 
         assert(_bus);
 
+#define TIMEOUT_USEC (60*USEC_PER_SEC)
+
         /* If we are root, then let's not go via the bus */
         if (geteuid() == 0 && t == DBUS_BUS_SYSTEM) {
+                usec_t begin, tstamp;
 
                 if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", error)))
                         return -EIO;
 
                 if (bus_check_peercred(bus) < 0) {
+                        dbus_connection_close(bus);
                         dbus_connection_unref(bus);
 
                         dbus_set_error_const(error, DBUS_ERROR_ACCESS_DENIED, "Failed to verify owner of bus.");
                         return -EACCES;
                 }
 
+                begin = tstamp = now(CLOCK_MONOTONIC);
+                for (;;) {
+
+                        if (tstamp > begin + TIMEOUT_USEC)
+                                break;
+
+                        if (dbus_connection_get_is_authenticated(bus))
+                                break;
+
+                        if (!dbus_connection_read_write_dispatch(bus, ((begin + TIMEOUT_USEC - tstamp) + USEC_PER_MSEC - 1) / USEC_PER_MSEC))
+                                break;
+
+                        tstamp = now(CLOCK_MONOTONIC);
+                }
+
+                if (!dbus_connection_get_is_connected(bus)) {
+                        dbus_connection_close(bus);
+                        dbus_connection_unref(bus);
+
+                        dbus_set_error_const(error, DBUS_ERROR_NO_SERVER, "Connection terminated during authentication.");
+                        return -ECONNREFUSED;
+                }
+
+                if (!dbus_connection_get_is_authenticated(bus)) {
+                        dbus_connection_close(bus);
+                        dbus_connection_unref(bus);
+
+                        dbus_set_error_const(error, DBUS_ERROR_TIMEOUT, "Failed to authenticate in time.");
+                        return -EACCES;
+                }
+
                 if (private)
                         *private = true;
 

commit 099663ff8c117303af369a4d412dafed0c5614c2
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Mar 10 23:01:42 2011 +0100

    main: properly handle -b boot option

diff --git a/TODO b/TODO
index 9359782..f2e3be4 100644
--- a/TODO
+++ b/TODO
@@ -20,10 +20,16 @@ F15:
 
 * save/restore tool for SysV as requested by FPC
 
-* optionally create watched directories in .path units
+* bind mounts are ignored
+
+* SIGALRM in systemctl
+
+* 0595f9a1c182a84581749823ef47c5f292e545f9 is borked, freezes shutdown
 
 Features:
 
+* optionally create watched directories in .path units
+
 * consider services with no [Install] section and stored in /lib enabled by "systemctl is-enabled"
 
 * consider services with any kind of link in /etc/systemd/system enabled
diff --git a/src/main.c b/src/main.c
index 6d1fd7d..5d37f80 100644
--- a/src/main.c
+++ b/src/main.c
@@ -226,6 +226,8 @@ static int parse_proc_cmdline_word(const char *word) {
 
         static const char * const rlmap[] = {
                 "emergency", SPECIAL_EMERGENCY_TARGET,
+                "-b",        SPECIAL_EMERGENCY_TARGET,
+                "b",         SPECIAL_EMERGENCY_TARGET,
                 "single",    SPECIAL_RESCUE_TARGET,
                 "-s",        SPECIAL_RESCUE_TARGET,
                 "s",         SPECIAL_RESCUE_TARGET,
@@ -624,7 +626,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 1);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hD", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hDbsz:", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -800,19 +802,29 @@ static int parse_argv(int argc, char *argv[]) {
                         log_set_max_level(LOG_DEBUG);
                         break;
 
-                case '?':
-                        return -EINVAL;
+                case 'b':
+                case 's':
+                case 'z':
+                        /* Just to eat away the sysvinit kernel
+                         * cmdline args without getopt() error
+                         * messages that we'll parse in
+                         * parse_proc_cmdline_word() or ignore. */
 
+                case '?':
                 default:
-                        log_error("Unknown option code %c", c);
-                        return -EINVAL;
+                        if (getpid() != 1) {
+                                log_error("Unknown option code %c", c);
+                                return -EINVAL;
+                        }
+
+                        break;
                 }
 
         /* PID 1 will get the kernel arguments as parameters, which we
          * ignore and unconditionally read from
          * /proc/cmdline. However, we need to ignore those arguments
          * here. */
-        if (arg_running_as != MANAGER_SYSTEM && optind < argc) {
+        if (getpid() != 1 && optind < argc) {
                 log_error("Excess arguments.");
                 return -EINVAL;
         }



More information about the systemd-commits mailing list