[systemd-commits] 6 commits - Makefile.am src/dbus-common.c src/dbus-common.h src/initctl.c src/install.c src/main.c src/service.c src/systemctl.c src/util.c

Lennart Poettering lennart at kemper.freedesktop.org
Tue Jul 6 19:13:32 PDT 2010


 Makefile.am       |    3 +
 src/dbus-common.c |    9 +++++
 src/dbus-common.h |    2 -
 src/initctl.c     |    5 +++
 src/install.c     |    2 -
 src/main.c        |    2 -
 src/service.c     |   71 ++++++++++++++++++++++++++++++++++++++++++++++
 src/systemctl.c   |   83 +++++++++++++++++++++++++++++++-----------------------
 src/util.c        |    8 ++---
 9 files changed, 141 insertions(+), 44 deletions(-)

New commits:
commit ecdbca40bd985f269cd77fc122a648630f330c28
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 7 04:12:59 2010 +0200

    service: serialize exec status

diff --git a/src/service.c b/src/service.c
index c9abb08..ecfd054 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1972,6 +1972,28 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
                 unit_serialize_item_format(u, f, "socket-fd", "%i", copy);
         }
 
+        if (s->main_exec_status.pid > 0) {
+                unit_serialize_item_format(u, f, "main-exec-status-pid", "%lu", (unsigned long) s->main_exec_status.pid);
+
+                if (s->main_exec_status.start_timestamp.realtime > 0) {
+                        unit_serialize_item_format(u, f, "main-exec-status-start-realtime",
+                                                   "%llu", (unsigned long long) s->main_exec_status.start_timestamp.realtime);
+
+                        unit_serialize_item_format(u, f, "main-exec-status-start-monotonic",
+                                                   "%llu", (unsigned long long) s->main_exec_status.start_timestamp.monotonic);
+                }
+
+                if (s->main_exec_status.exit_timestamp.realtime > 0) {
+                        unit_serialize_item_format(u, f, "main-exec-status-exit-realtime",
+                                                   "%llu", (unsigned long long) s->main_exec_status.exit_timestamp.realtime);
+                        unit_serialize_item_format(u, f, "main-exec-status-exit-monotonic",
+                                                   "%llu", (unsigned long long) s->main_exec_status.exit_timestamp.monotonic);
+
+                        unit_serialize_item_format(u, f, "main-exec-status-code", "%i", s->main_exec_status.code);
+                        unit_serialize_item_format(u, f, "main-exec-status-status", "%i", s->main_exec_status.status);
+                }
+        }
+
         return 0;
 }
 
@@ -2039,6 +2061,55 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
                                 close_nointr_nofail(s->socket_fd);
                         s->socket_fd = fdset_remove(fds, fd);
                 }
+        } else if (streq(key, "main-exec-status-pid")) {
+                pid_t pid;
+
+                if ((r = parse_pid(value, &pid)) < 0)
+                        log_debug("Failed to parse main-exec-status-pid value %s", value);
+                else
+                        s->main_exec_status.pid = pid;
+        } else if (streq(key, "main-exec-status-code")) {
+                int i;
+
+                if ((r = safe_atoi(value, &i)) < 0)
+                        log_debug("Failed to parse main-exec-status-code value %s", value);
+                else
+                        s->main_exec_status.code = i;
+        } else if (streq(key, "main-exec-status-status")) {
+                int i;
+
+                if ((r = safe_atoi(value, &i)) < 0)
+                        log_debug("Failed to parse main-exec-status-status value %s", value);
+                else
+                        s->main_exec_status.status = i;
+        } else if (streq(key, "main-exec-status-start-realtime")) {
+                uint64_t k;
+
+                if ((r = safe_atollu(value, &k)) < 0)
+                        log_debug("Failed to parse main-exec-status-start-realtime value %s", value);
+                else
+                        s->main_exec_status.start_timestamp.realtime = (usec_t) k;
+        } else if (streq(key, "main-exec-status-start-monotonic")) {
+                uint64_t k;
+
+                if ((r = safe_atollu(value, &k)) < 0)
+                        log_debug("Failed to parse main-exec-status-start-monotonic value %s", value);
+                else
+                        s->main_exec_status.start_timestamp.monotonic = (usec_t) k;
+        } else if (streq(key, "main-exec-status-exit-realtime")) {
+                uint64_t k;
+
+                if ((r = safe_atollu(value, &k)) < 0)
+                        log_debug("Failed to parse main-exec-status-exit-realtime value %s", value);
+                else
+                        s->main_exec_status.exit_timestamp.realtime = (usec_t) k;
+        } else if (streq(key, "main-exec-status-exit-monotonic")) {
+                uint64_t k;
+
+                if ((r = safe_atollu(value, &k)) < 0)
+                        log_debug("Failed to parse main-exec-status-exit-monotonic value %s", value);
+                else
+                        s->main_exec_status.exit_timestamp.monotonic = (usec_t) k;
         } else
                 log_debug("Unknown serialization key '%s'", key);
 
commit 7c70671781fb5eb9c7e086af43663ea5cdb2140f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 7 03:51:56 2010 +0200

    main: lower default log level to INFO

diff --git a/src/main.c b/src/main.c
index 3220942..6ff3ebc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -833,7 +833,7 @@ int main(int argc, char *argv[]) {
 
         log_show_color(true);
         log_show_location(false);
-        log_set_max_level(LOG_DEBUG);
+        log_set_max_level(LOG_INFO);
 
         if (getpid() == 1) {
                 arg_running_as = MANAGER_SYSTEM;
commit 2e54424d83c633b6362528c8f97beba89e0ce28b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 7 03:49:39 2010 +0200

    util: minor simplification when printing welcome text

diff --git a/src/util.c b/src/util.c
index 774f061..a5f904d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2675,11 +2675,11 @@ void status_welcome(void) {
          * script did. */
 
         if (startswith(r, "Red Hat"))
-                status_printf("\tWelcome to \x1B[0;31m%s\x1B[0m!\n", r); /* Red for RHEL */
+                status_printf("Welcome to \x1B[0;31m%s\x1B[0m!\n", r); /* Red for RHEL */
         else if (startswith(r, "Fedora"))
-                status_printf("\tWelcome to \x1B[0;34m%s\x1B[0m!\n", r); /* Blue for Fedora */
+                status_printf("Welcome to \x1B[0;34m%s\x1B[0m!\n", r); /* Blue for Fedora */
         else
-                status_printf("\tWelcome to %s!\n", r);
+                status_printf("Welcome to %s!\n", r);
 
         free(r);
 
@@ -2691,7 +2691,7 @@ void status_welcome(void) {
 
         truncate_nl(r);
 
-        status_printf("\tWelcome to \x1B[0;32m%s\x1B[0m!\n", r); /* Green for SUSE */
+        status_printf("Welcome to \x1B[0;32m%s\x1B[0m!\n", r); /* Green for SUSE */
         free(r);
 #else
 #warning "You probably should add a welcome text logic here."
commit e0376b177ca00bc5c3d8a271f6422ef3c869861b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 7 03:49:08 2010 +0200

    systemctl: minor beautifications

diff --git a/src/systemctl.c b/src/systemctl.c
index 081f34b..f585e11 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -239,20 +239,26 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
 
                         int a = 0, b = 0;
 
+                        if (streq(active_state, "maintenance"))
+                                fputs(ANSI_HIGHLIGHT_ON, stdout);
+
                         printf("%-45s %-6s %-12s %-12s%n", id, load_state, active_state, sub_state, &a);
 
                         if (job_id != 0)
                                 printf(" %-15s%n", job_type, &b);
                         else
-                                b = 1 + 16;
+                                b = 1 + 15;
 
                         if (a + b + 2 < columns()) {
                                 if (job_id == 0)
                                         printf("                ");
 
-                                printf("%.*s", columns() - a - b - 2, description);
+                                printf(" %.*s", columns() - a - b - 2, description);
                         }
 
+                        if (streq(active_state, "maintenance"))
+                                fputs(ANSI_HIGHLIGHT_OFF, stdout);
+
                         fputs("\n", stdout);
                         k++;
                 }
commit a822056bca49a63cb832230af22f789c5ab5b856
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 7 03:48:37 2010 +0200

    initctl: check peer credentials after connection

diff --git a/Makefile.am b/Makefile.am
index 0215f23..b444c02 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -453,7 +453,8 @@ systemd_logger_LDADD = \
 
 systemd_initctl_SOURCES = \
 	src/initctl.c \
-	src/sd-daemon.c
+	src/sd-daemon.c \
+	src/dbus-common.c
 
 systemd_initctl_CFLAGS = \
 	$(AM_CFLAGS) \
diff --git a/src/initctl.c b/src/initctl.c
index a18cf38..7241acb 100644
--- a/src/initctl.c
+++ b/src/initctl.c
@@ -41,6 +41,7 @@
 #include "initreq.h"
 #include "special.h"
 #include "sd-daemon.h"
+#include "dbus-common.h"
 
 #define SERVER_FD_MAX 16
 #define TIMEOUT ((int) (10*MSEC_PER_SEC))
@@ -300,6 +301,10 @@ static int server_init(Server *s, unsigned n_sockets) {
                 log_error("Failed to get D-Bus connection: %s", error.message);
                 goto fail;
         }
+        if ((r = bus_check_peercred(s->bus)) < 0) {
+                log_error("Bus connection failed peer credential check: %s", strerror(-r));
+                goto fail;
+        }
 
         return 0;
 
commit f4579ce704b9db0358b90c282da9536410a4df5a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 7 03:43:39 2010 +0200

    dbus: don't try to run AddMatch when connected to a private bus

diff --git a/src/dbus-common.c b/src/dbus-common.c
index 504eefb..11d989d 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -54,7 +54,7 @@ int bus_check_peercred(DBusConnection *c) {
         return 1;
 }
 
-int bus_connect(DBusBusType t, DBusConnection **_bus, DBusError *error) {
+int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private, DBusError *error) {
         DBusConnection *bus;
 
         assert(_bus);
@@ -71,9 +71,16 @@ int bus_connect(DBusBusType t, DBusConnection **_bus, DBusError *error) {
                         dbus_set_error_const(error, DBUS_ERROR_ACCESS_DENIED, "Failed to verify owner of bus.");
                         return -EACCES;
                 }
+
+                if (private)
+                        *private = true;
+
         } else {
                 if (!(bus = dbus_bus_get(t, error)))
                         return -EIO;
+
+                if (private)
+                        *private = false;
         }
 
         dbus_connection_set_exit_on_disconnect(bus, FALSE);
diff --git a/src/dbus-common.h b/src/dbus-common.h
index f355de1..b28755f 100644
--- a/src/dbus-common.h
+++ b/src/dbus-common.h
@@ -26,6 +26,6 @@
 
 int bus_check_peercred(DBusConnection *c);
 
-int bus_connect(DBusBusType t, DBusConnection **_bus, DBusError *error);
+int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private_bus, DBusError *error);
 
 #endif
diff --git a/src/install.c b/src/install.c
index 3bf5761..3b70bd1 100644
--- a/src/install.c
+++ b/src/install.c
@@ -791,7 +791,7 @@ static int do_run(void) {
                 return 0;
         }
 
-        if ((r = bus_connect(arg_where == WHERE_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, &error)) < 0) {
+        if ((r = bus_connect(arg_where == WHERE_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, NULL, &error)) < 0) {
                 log_error("Failed to get D-Bus connection: %s", error.message);
                 goto finish;
         }
diff --git a/src/systemctl.c b/src/systemctl.c
index 5c91c32..081f34b 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -75,6 +75,8 @@ enum action {
         _ACTION_MAX
 } arg_action = ACTION_SYSTEMCTL;
 
+static bool private_bus = false;
+
 static bool error_is_no_service(DBusError *error) {
 
         assert(error);
@@ -561,6 +563,9 @@ static int enable_wait_for_jobs(DBusConnection *bus) {
 
         assert(bus);
 
+        if (private_bus)
+                return 0;
+
         dbus_error_init(&error);
         dbus_bus_add_match(bus,
                            "type='signal',"
@@ -1849,43 +1854,45 @@ static int monitor(DBusConnection *bus, char **args, unsigned n) {
 
         dbus_error_init(&error);
 
-        dbus_bus_add_match(bus,
-                           "type='signal',"
-                           "sender='org.freedesktop.systemd1',"
-                           "interface='org.freedesktop.systemd1.Manager',"
-                           "path='/org/freedesktop/systemd1'",
-                           &error);
+        if (!private_bus) {
+                dbus_bus_add_match(bus,
+                                   "type='signal',"
+                                   "sender='org.freedesktop.systemd1',"
+                                   "interface='org.freedesktop.systemd1.Manager',"
+                                   "path='/org/freedesktop/systemd1'",
+                                   &error);
 
-        if (dbus_error_is_set(&error)) {
-                log_error("Failed to add match: %s", error.message);
-                r = -EIO;
-                goto finish;
-        }
+                if (dbus_error_is_set(&error)) {
+                        log_error("Failed to add match: %s", error.message);
+                        r = -EIO;
+                        goto finish;
+                }
 
-        dbus_bus_add_match(bus,
-                           "type='signal',"
-                           "sender='org.freedesktop.systemd1',"
-                           "interface='org.freedesktop.systemd1.Unit',"
-                           "member='Changed'",
-                           &error);
+                dbus_bus_add_match(bus,
+                                   "type='signal',"
+                                   "sender='org.freedesktop.systemd1',"
+                                   "interface='org.freedesktop.systemd1.Unit',"
+                                   "member='Changed'",
+                                   &error);
 
-        if (dbus_error_is_set(&error)) {
-                log_error("Failed to add match: %s", error.message);
-                r = -EIO;
-                goto finish;
-        }
+                if (dbus_error_is_set(&error)) {
+                        log_error("Failed to add match: %s", error.message);
+                        r = -EIO;
+                        goto finish;
+                }
 
-        dbus_bus_add_match(bus,
-                           "type='signal',"
-                           "sender='org.freedesktop.systemd1',"
-                           "interface='org.freedesktop.systemd1.Job',"
-                           "member='Changed'",
-                           &error);
+                dbus_bus_add_match(bus,
+                                   "type='signal',"
+                                   "sender='org.freedesktop.systemd1',"
+                                   "interface='org.freedesktop.systemd1.Job',"
+                                   "member='Changed'",
+                                   &error);
 
-        if (dbus_error_is_set(&error)) {
-                log_error("Failed to add match: %s", error.message);
-                r = -EIO;
-                goto finish;
+                if (dbus_error_is_set(&error)) {
+                        log_error("Failed to add match: %s", error.message);
+                        r = -EIO;
+                        goto finish;
+                }
         }
 
         if (!dbus_connection_add_filter(bus, monitor_filter, NULL, NULL)) {
@@ -3286,7 +3293,7 @@ int main(int argc, char*argv[]) {
                 goto finish;
         }
 
-        bus_connect(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, &error);
+        bus_connect(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, &private_bus, &error);
 
         switch (arg_action) {
 


More information about the systemd-commits mailing list