[systemd-commits] Makefile.am src/cgroups-agent.c src/dbus.c

Lennart Poettering lennart at kemper.freedesktop.org
Thu Aug 5 18:22:03 PDT 2010


 Makefile.am         |    3 ++-
 src/cgroups-agent.c |   21 +++++++++++++++++++--
 src/dbus.c          |   15 +++++++++++++++
 3 files changed, 36 insertions(+), 3 deletions(-)

New commits:
commit 3c661fadd5e0d74acc7596024db31be00c53b448
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 6 03:21:50 2010 +0200

    cgroup: if the system bus cannot be found, send cgroup empty msg directly to init proces

diff --git a/Makefile.am b/Makefile.am
index 3c54043..00765a7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -479,7 +479,8 @@ systemd_initctl_LDADD = \
 	$(DBUS_LIBS)
 
 systemd_cgroups_agent_SOURCES = \
-	src/cgroups-agent.c
+	src/cgroups-agent.c \
+	src/dbus-common.c
 
 systemd_cgroups_agent_CFLAGS = \
 	$(AM_CFLAGS) \
diff --git a/src/cgroups-agent.c b/src/cgroups-agent.c
index d3db151..a1eac14 100644
--- a/src/cgroups-agent.c
+++ b/src/cgroups-agent.c
@@ -22,6 +22,7 @@
 #include <dbus/dbus.h>
 
 #include "log.h"
+#include "dbus-common.h"
 
 int main(int argc, char *argv[]) {
         DBusError error;
@@ -36,9 +37,25 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
+        log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
+        log_parse_environment();
+
+        /* If possible we go via the system bus, to make sure that
+         * session instances get the messages. If not possible we talk
+         * to the system instance directly. */
         if (!(bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
-                log_error("Failed to get D-Bus connection: %s", error.message);
-                goto finish;
+
+                dbus_error_free(&error);
+
+                if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
+                        log_error("Failed to get D-Bus connection: %s", error.message);
+                        goto finish;
+                }
+
+                if (bus_check_peercred(bus) < 0) {
+                        log_error("Bus owner not root.");
+                        goto finish;
+                }
         }
 
         if (!(m = dbus_message_new_signal("/org/freedesktop/systemd1/agent", "org.freedesktop.systemd1.Agent", "Released"))) {
diff --git a/src/dbus.c b/src/dbus.c
index 0b93db5..0ab55b8 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -474,11 +474,14 @@ static DBusHandlerResult system_bus_message_filter(DBusConnection *connection, D
 
 static DBusHandlerResult private_bus_message_filter(DBusConnection *connection, DBusMessage *message, void *data) {
         Manager *m = data;
+        DBusError error;
 
         assert(connection);
         assert(message);
         assert(m);
 
+        dbus_error_init(&error);
+
         if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL ||
             dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL)
                 log_debug("Got D-Bus request: %s.%s() on %s",
@@ -488,6 +491,18 @@ static DBusHandlerResult private_bus_message_filter(DBusConnection *connection,
 
         if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected"))
                 shutdown_connection(m, connection);
+        else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) {
+                const char *cgroup;
+
+                if (!dbus_message_get_args(message, &error,
+                                           DBUS_TYPE_STRING, &cgroup,
+                                           DBUS_TYPE_INVALID))
+                        log_error("Failed to parse Released message: %s", error.message);
+                else
+                        cgroup_notify_empty(m, cgroup);
+        }
+
+        dbus_error_free(&error);
 
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }


More information about the systemd-commits mailing list