chiark / gitweb /
dbus: use private connections wherever possible
authorLennart Poettering <lennart@poettering.net>
Sun, 11 Jul 2010 00:22:46 +0000 (02:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 11 Jul 2010 00:22:46 +0000 (02:22 +0200)
src/dbus-common.c
src/initctl.c
src/systemctl.c
src/test-loopback.c

index 11d989d7c34de57a7dd8a62b9f41ef205f5804ec..267ab2646cc94d991eaefa50d0cd537e7d268822 100644 (file)
@@ -62,7 +62,7 @@ int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private, DBusError *
         /* If we are root, then let's not go via the bus */
         if (geteuid() == 0 && t == DBUS_BUS_SYSTEM) {
 
-                if (!(bus = dbus_connection_open("unix:abstract=/org/freedesktop/systemd1/private", error)))
+                if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", error)))
                         return -EIO;
 
                 if (bus_check_peercred(bus) < 0) {
index 7241acb8dfe59771c9d5c930eeb1aeaecbaccc2e..83a560a14a538e305d16bb8f45d85cc633fa98f4 100644 (file)
@@ -232,7 +232,7 @@ static void server_done(Server *s) {
                 close_nointr_nofail(s->epoll_fd);
 
         if (s->bus) {
-               dbus_connection_set_exit_on_disconnect(s->bus, FALSE);
+               dbus_connection_close(s->bus);
                dbus_connection_unref(s->bus);
         }
 }
@@ -297,14 +297,10 @@ static int server_init(Server *s, unsigned n_sockets) {
                 s->n_fifos ++;
         }
 
-        if (!(s->bus = dbus_connection_open("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
+        if (bus_connect(DBUS_BUS_SYSTEM, &s->bus, NULL, &error) < 0) {
                 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;
 
index 799f57d006d3b0b6b0883e7eba18cbcad1418cbe..d90471773ecb2b6c9fdc0ed0058a703c1e501df0 100644 (file)
@@ -3056,7 +3056,7 @@ static int talk_upstart(void) {
         if (utmp_get_runlevel(&previous, NULL) < 0)
                 previous = 'N';
 
-        if (!(bus = dbus_connection_open("unix:abstract=/com/ubuntu/upstart", &error))) {
+        if (!(bus = dbus_connection_open_private("unix:abstract=/com/ubuntu/upstart", &error))) {
                 if (dbus_error_has_name(&error, DBUS_ERROR_NO_SERVER)) {
                         r = 0;
                         goto finish;
@@ -3120,8 +3120,10 @@ finish:
         if (reply)
                 dbus_message_unref(reply);
 
-        if (bus)
+        if (bus) {
+                dbus_connection_close(bus);
                 dbus_connection_unref(bus);
+        }
 
         dbus_error_free(&error);
 
@@ -3444,8 +3446,10 @@ int main(int argc, char*argv[]) {
 
 finish:
 
-        if (bus)
+        if (bus) {
+                dbus_connection_close(bus);
                 dbus_connection_unref(bus);
+        }
 
         dbus_error_free(&error);
 
index 478f2f61e80b37852d6fc7ed17f2569c41539656..74449871a23b6d85856f7daf302127b9a9ec1eaf 100644 (file)
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
+#include <fcntl.h>
 
 #include "loopback-setup.h"
 #include "util.h"