[systemd-commits] 2 commits - fixme src/cgroup.c src/dbus-manager.c src/org.freedesktop.systemd1.conf src/systemctl.c

Lennart Poettering lennart at kemper.freedesktop.org
Thu Aug 12 17:08:40 PDT 2010


 fixme                             |    4 ----
 src/cgroup.c                      |   15 +++++++++++++++
 src/dbus-manager.c                |   31 +++++++++++++++++++++++++++++++
 src/org.freedesktop.systemd1.conf |    4 ++++
 src/systemctl.c                   |   35 +++++++++++++++++++++++++++++++++--
 5 files changed, 83 insertions(+), 6 deletions(-)

New commits:
commit 4455bcd0e646eda1a952671734045bf1b2e9b69f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 13 02:08:34 2010 +0200

    cgroup: try harder to find a unit a PID belongs to by traversing through parent cgroups

diff --git a/src/cgroup.c b/src/cgroup.c
index 23ba5d8..fff00d0 100644
--- a/src/cgroup.c
+++ b/src/cgroup.c
@@ -335,6 +335,21 @@ Unit* cgroup_unit_by_pid(Manager *m, pid_t pid) {
                 return NULL;
 
         l = hashmap_get(m->cgroup_bondings, group);
+
+        if (!l) {
+                char *slash;
+
+                while ((slash = strrchr(group, '/'))) {
+                        if (slash == group)
+                                break;
+
+                        *slash = 0;
+
+                        if ((l = hashmap_get(m->cgroup_bondings, group)))
+                                break;
+                }
+        }
+
         free(group);
 
         LIST_FOREACH(by_path, b, l) {
commit 598b557bf0dea33db2c13d383382efbd847ed5f0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 13 02:07:22 2010 +0200

    systemctl: when calling 'status' accept a PID

diff --git a/fixme b/fixme
index 3f62c17..a525f08 100644
--- a/fixme
+++ b/fixme
@@ -51,8 +51,6 @@
 
 * selinux policy loading
 
-* systemctl status $PID, systemctl stop $PID!
-
 * place /etc/inittab with explaining blurb.
 
 * fingerprint.target, wireless.target, gps.target
@@ -75,8 +73,6 @@
 
 * plymouth after/before getty?
 
-* D-Bus call GetUnitByPID
-
 * be more forgiving when parsing unit files, when encountering incorrect lines with non assignments
 
 * ExecStart= mehrfach bei Type=finish
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index 6d0ecc3..dfe8a91 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -33,6 +33,10 @@
         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
         "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n"        \
         "  </method>\n"                                                 \
+        "  <method name=\"GetUnitByPID\">\n"                            \
+        "   <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n"         \
+        "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n"        \
+        "  </method>\n"                                                 \
         "  <method name=\"LoadUnit\">\n"                                \
         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
         "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n"        \
@@ -290,7 +294,34 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                                     DBUS_TYPE_OBJECT_PATH, &path,
                                     DBUS_TYPE_INVALID))
                         goto oom;
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitByPID")) {
+                const char *name;
+                Unit *u;
+                uint32_t pid;
+
+                if (!dbus_message_get_args(
+                                    message,
+                                    &error,
+                                    DBUS_TYPE_UINT32, &pid,
+                                    DBUS_TYPE_INVALID))
+                        return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+
+                if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
+                        dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
+                        return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+                }
+
+                if (!(reply = dbus_message_new_method_return(message)))
+                        goto oom;
+
+                if (!(path = unit_dbus_path(u)))
+                        goto oom;
 
+                if (!dbus_message_append_args(
+                                    reply,
+                                    DBUS_TYPE_OBJECT_PATH, &path,
+                                    DBUS_TYPE_INVALID))
+                        goto oom;
         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LoadUnit")) {
                 const char *name;
                 Unit *u;
diff --git a/src/org.freedesktop.systemd1.conf b/src/org.freedesktop.systemd1.conf
index 831df59..153374d 100644
--- a/src/org.freedesktop.systemd1.conf
+++ b/src/org.freedesktop.systemd1.conf
@@ -45,6 +45,10 @@
 
                 <allow send_destination="org.freedesktop.systemd1"
                        send_interface="org.freedesktop.systemd1.Manager"
+                       send_member="GetUnitByPID"/>
+
+                <allow send_destination="org.freedesktop.systemd1"
+                       send_interface="org.freedesktop.systemd1.Manager"
                        send_member="GetJob"/>
 
                 <allow send_destination="org.freedesktop.systemd1"
diff --git a/src/systemctl.c b/src/systemctl.c
index 8f7755f..cf075ed 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -2121,7 +2121,9 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                 const char *path = NULL;
                 uint32_t id;
 
-                if (!show_properties || safe_atou32(args[i], &id) < 0) {
+                if (safe_atou32(args[i], &id) < 0) {
+
+                        /* Interpret as unit name */
 
                         if (!(m = dbus_message_new_method_call(
                                               "org.freedesktop.systemd1",
@@ -2177,7 +2179,9 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                                 }
                         }
 
-                } else {
+                } else if (show_properties) {
+
+                        /* Interpret as job id */
 
                         if (!(m = dbus_message_new_method_call(
                                               "org.freedesktop.systemd1",
@@ -2202,6 +2206,33 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                                 r = -EIO;
                                 goto finish;
                         }
+                } else {
+
+                        /* Interpret as PID */
+
+                        if (!(m = dbus_message_new_method_call(
+                                              "org.freedesktop.systemd1",
+                                              "/org/freedesktop/systemd1",
+                                              "org.freedesktop.systemd1.Manager",
+                                              "GetUnitByPID"))) {
+                                log_error("Could not allocate message.");
+                                r = -ENOMEM;
+                                goto finish;
+                        }
+
+                        if (!dbus_message_append_args(m,
+                                                      DBUS_TYPE_UINT32, &id,
+                                                      DBUS_TYPE_INVALID)) {
+                                log_error("Could not append arguments to message.");
+                                r = -ENOMEM;
+                                goto finish;
+                        }
+
+                        if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
+                                log_error("Failed to issue method call: %s", error.message);
+                                r = -EIO;
+                                goto finish;
+                        }
                 }
 
                 if (!dbus_message_get_args(reply, &error,


More information about the systemd-commits mailing list