[systemd-commits] 2 commits - src/bus-proxyd src/libsystemd-bus src/systemctl units/systemd-bus-proxyd at .service.in

Lennart Poettering lennart at kemper.freedesktop.org
Fri Dec 20 20:15:20 PST 2013


 src/bus-proxyd/bus-proxyd.c          |   77 +++++++++++++++++++++++++++++++----
 src/libsystemd-bus/bus-control.c     |    1 
 src/systemctl/systemctl.c            |   12 ++++-
 units/systemd-bus-proxyd at .service.in |    6 ++
 4 files changed, 86 insertions(+), 10 deletions(-)

New commits:
commit 0721804f03934c17509af4f485c3bcef9d86862c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Dec 21 04:19:51 2013 +0100

    bus: send status message from proxyd to systemd about client we are working for

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 4145217..d8caf40 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -39,13 +39,16 @@
 #include "bus-message.h"
 #include "bus-util.h"
 #include "build.h"
+#include "strv.h"
 
 #ifdef ENABLE_KDBUS
-const char *arg_address = "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket";
+static const char *arg_address = "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket";
 #else
-const char *arg_address = "unix:path=/run/dbus/system_bus_socket";
+static const char *arg_address = "unix:path=/run/dbus/system_bus_socket";
 #endif
 
+static char *arg_command_line_buffer = NULL;
+
 static int help(void) {
 
         printf("%s [OPTIONS...]\n\n"
@@ -102,14 +105,30 @@ static int parse_argv(int argc, char *argv[]) {
                 }
         }
 
+        /* If the first command line argument is only "x" characters
+         * we'll write who we are talking to into it, so that "ps" is
+         * explanatory */
+        arg_command_line_buffer = argv[optind];
+        if (argc > optind + 1 ||
+            (arg_command_line_buffer && arg_command_line_buffer[strspn(arg_command_line_buffer, "x")] != 0)) {
+                log_error("Too many arguments");
+                return -EINVAL;
+        }
+
         return 1;
 }
 
 int main(int argc, char *argv[]) {
+
+        _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
         _cleanup_bus_unref_ sd_bus *a = NULL, *b = NULL;
         sd_id128_t server_id;
-        bool is_unix;
         int r, in_fd, out_fd;
+        char **cmdline;
+        const char *comm;
+        bool is_unix;
+        uid_t uid;
+        pid_t pid;
 
         log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
         log_parse_environment();
@@ -201,11 +220,53 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
+        if (sd_bus_get_peer_creds(b, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_CMDLINE|SD_BUS_CREDS_COMM, &creds) >= 0 &&
+            sd_bus_creds_get_uid(creds, &uid) >= 0 &&
+            sd_bus_creds_get_pid(creds, &pid) >= 0 &&
+            sd_bus_creds_get_cmdline(creds, &cmdline) >= 0 &&
+            sd_bus_creds_get_comm(creds, &comm) >= 0) {
+                _cleanup_free_ char *p = NULL, *name = NULL;
+
+                name = uid_to_name(uid);
+                if (!name) {
+                        r = log_oom();
+                        goto finish;
+                }
+
+                p = strv_join(cmdline, " ");
+                if (!p) {
+                        r = log_oom();
+                        goto finish;
+                }
+
+                /* The status string gets the full command line ... */
+                sd_notifyf(false,
+                           "STATUS=Processing requests from client PID %lu (%s); UID %lu (%s)",
+                           (unsigned long) pid, p,
+                           (unsigned long) uid, name);
+
+                /* ... and the argv line only the short comm */
+                if (arg_command_line_buffer) {
+                        size_t m, w;
+
+                        m = strlen(arg_command_line_buffer);
+                        w = snprintf(arg_command_line_buffer, m,
+                                     "[PID %lu/%s; UID %lu/%s]",
+                                     (unsigned long) pid, comm,
+                                     (unsigned long) uid, name);
+
+                        if (m > w)
+                                memset(arg_command_line_buffer + w, 0, m - w);
+
+                }
+        }
+
         for (;;) {
                 _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
                 int events_a, events_b, fd;
                 uint64_t timeout_a, timeout_b, t;
                 struct timespec _ts, *ts;
+                int k;
 
                 r = sd_bus_process(a, &m);
                 if (r < 0) {
@@ -225,8 +286,9 @@ int main(int argc, char *argv[]) {
                                 goto finish;
                         }
 
-                        r = sd_bus_send(b, m, NULL);
-                        if (r < 0) {
+                        k = sd_bus_send(b, m, NULL);
+                        if (k < 0) {
+                                r = k;
                                 log_error("Failed to send message: %s", strerror(-r));
                                 goto finish;
                         }
@@ -253,8 +315,9 @@ int main(int argc, char *argv[]) {
                                 goto finish;
                         }
 
-                        r = sd_bus_send(a, m, NULL);
-                        if (r < 0) {
+                        k = sd_bus_send(a, m, NULL);
+                        if (k < 0) {
+                                r = k;
                                 log_error("Failed to send message: %s", strerror(-r));
                                 goto finish;
                         }
diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index bbee1b5..c3186a0 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -702,6 +702,7 @@ _public_ int sd_bus_get_owner(
         assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
         assert_return(!bus_pid_changed(bus), -ECHILD);
         assert_return(service_name_is_valid(name), -EINVAL);
+        assert_return(bus->bus_client, -ENODATA);
 
         if (bus->is_kernel)
                 return bus_get_owner_kdbus(bus, name, mask, creds);
diff --git a/units/systemd-bus-proxyd at .service.in b/units/systemd-bus-proxyd at .service.in
index 24b1200..0711b48 100644
--- a/units/systemd-bus-proxyd at .service.in
+++ b/units/systemd-bus-proxyd at .service.in
@@ -9,4 +9,8 @@
 Description=Legacy D-Bus Protocol Compatibility Daemon
 
 [Service]
-ExecStart=@rootlibexecdir@/systemd-bus-proxyd
+# The first argument will be replaced by the service by information on
+# the process requesting the proxy, we need a placeholder to keep the
+# space available for this.
+ExecStart=@rootlibexecdir@/systemd-bus-proxyd xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+NotifyAccess=main

commit 373d32c9f4746d58cda8c62f4c70d2e0e7aae1af
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Dec 21 05:07:44 2013 +0100

    systemctl: fix bad memory access when processing PIDs on the "systemctl status" command line

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index d1f6875..d0a03d9 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3678,6 +3678,7 @@ static int get_unit_dbus_path_by_pid(
 
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+        char *u;
         int r;
 
         r = sd_bus_call_method(
@@ -3694,10 +3695,15 @@ static int get_unit_dbus_path_by_pid(
                 return r;
         }
 
-        r = sd_bus_message_read(reply, "o", unit);
+        r = sd_bus_message_read(reply, "o", &u);
         if (r < 0)
                 return bus_log_parse_error(r);
 
+        u = strdup(u);
+        if (!u)
+                return log_oom();
+
+        *unit = u;
         return 0;
 }
 
@@ -3880,8 +3886,10 @@ static int show(sd_bus *bus, char **args) {
                         } else {
                                 /* Interpret as PID */
                                 r = get_unit_dbus_path_by_pid(bus, id, &unit);
-                                if (r < 0)
+                                if (r < 0) {
                                         ret = r;
+                                        continue;
+                                }
                         }
 
                         show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);



More information about the systemd-commits mailing list