chiark / gitweb /
bus: properly handle EOF error conditions in proxyd
[elogind.git] / src / libsystemd-bus / sd-bus.c
index 44ab071c4791656683c3eff8ad9500bfaba03a51..6bd1eaa81b5ec82a75732a349608846bba1a6481 100644 (file)
@@ -34,6 +34,7 @@
 #include "strv.h"
 #include "set.h"
 #include "missing.h"
+#include "def.h"
 
 #include "sd-bus.h"
 #include "bus-internal.h"
@@ -1047,12 +1048,7 @@ _public_ int sd_bus_open_system(sd_bus **ret) {
         if (e)
                 r = sd_bus_set_address(b, e);
         else
-#ifdef ENABLE_KDBUS
-                r = sd_bus_set_address(b, "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket");
-#else
-                r = sd_bus_set_address(b, "unix:path=/run/dbus/system_bus_socket");
-#endif
-
+                r = sd_bus_set_address(b, DEFAULT_SYSTEM_BUS_PATH);
         if (r < 0)
                 goto fail;
 
@@ -1103,13 +1099,13 @@ _public_ int sd_bus_open_user(sd_bus **ret) {
                         }
 
 #ifdef ENABLE_KDBUS
-                        asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus;unix:path=%s/bus", (unsigned long) getuid(), ee);
+                        asprintf(&b->address, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT, (unsigned long) getuid(), ee);
 #else
-                        b->address = strjoin("unix:path=", ee, "/bus", NULL);
+                        asprintf(&b->address, UNIX_USER_BUS_FMT, ee);
 #endif
                 } else {
 #ifdef ENABLE_KDBUS
-                        asprintf(&b->address, "kernel:path=/dev/kdbus/%lu-user/bus", (unsigned long) getuid());
+                        asprintf(&b->address, KERNEL_USER_BUS_FMT, (unsigned long) getuid());
 #else
                         return -ECONNREFUSED;
 #endif
@@ -1238,7 +1234,7 @@ _public_ void sd_bus_close(sd_bus *bus) {
 
         /* We'll leave the fd open in case this is a kernel bus, since
          * there might still be memblocks around that reference this
-         * bus, and they might need to invoke the KDBUS_CMD_FREE
+         * bus, and they might need to invoke the KDBUS_CMD_FREE
          * ioctl on the fd when they are freed. */
 }
 
@@ -1503,7 +1499,7 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie) {
         if (r < 0)
                 return r;
 
-        /* Remarshall if we have to. This will possible unref the
+        /* Remarshall if we have to. This will possibly unref the
          * message and place a replacement in m */
         r = bus_remarshal_message(bus, &m);
         if (r < 0)
@@ -1519,8 +1515,10 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie) {
 
                 r = bus_write_message(bus, m, &idx);
                 if (r < 0) {
-                        if (r == -EPIPE || r == -ENOTCONN || r == -ESHUTDOWN)
+                        if (r == -ENOTCONN || r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
                                 bus_enter_closing(bus);
+                                return -ECONNRESET;
+                        }
 
                         return r;
                 } else if (!bus->is_kernel && idx < BUS_MESSAGE_SIZE(m))  {
@@ -1803,8 +1801,10 @@ _public_ int sd_bus_call(
 
                 r = bus_read_message(bus);
                 if (r < 0) {
-                        if (r == -EPIPE || r == -ENOTCONN || r == -ESHUTDOWN)
+                        if (r == -ENOTCONN || r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
                                 bus_enter_closing(bus);
+                                return -ECONNRESET;
+                        }
 
                         return r;
                 }
@@ -1830,8 +1830,10 @@ _public_ int sd_bus_call(
 
                 r = dispatch_wqueue(bus);
                 if (r < 0) {
-                        if (r == -EPIPE || r == -ENOTCONN || r == -ESHUTDOWN)
+                        if (r == -ENOTCONN || r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
                                 bus_enter_closing(bus);
+                                return -ECONNRESET;
+                        }
 
                         return r;
                 }
@@ -2329,7 +2331,7 @@ _public_ int sd_bus_process(sd_bus *bus, sd_bus_message **ret) {
 
         case BUS_OPENING:
                 r = bus_socket_process_opening(bus);
-                if (r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
+                if (r == -ENOTCONN || r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
                         bus_enter_closing(bus);
                         r = 1;
                 } else if (r < 0)
@@ -2340,7 +2342,7 @@ _public_ int sd_bus_process(sd_bus *bus, sd_bus_message **ret) {
 
         case BUS_AUTHENTICATING:
                 r = bus_socket_process_authenticating(bus);
-                if (r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
+                if (r == -ENOTCONN || r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
                         bus_enter_closing(bus);
                         r = 1;
                 } else if (r < 0)
@@ -2354,7 +2356,7 @@ _public_ int sd_bus_process(sd_bus *bus, sd_bus_message **ret) {
         case BUS_RUNNING:
         case BUS_HELLO:
                 r = process_running(bus, ret);
-                if (r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
+                if (r == -ENOTCONN || r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
                         bus_enter_closing(bus);
                         r = 1;
 
@@ -2466,8 +2468,10 @@ _public_ int sd_bus_flush(sd_bus *bus) {
         for (;;) {
                 r = dispatch_wqueue(bus);
                 if (r < 0) {
-                        if (r == -EPIPE || r == -ENOTCONN || r == -ESHUTDOWN)
+                        if (r == -ENOTCONN || r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
                                 bus_enter_closing(bus);
+                                return -ECONNRESET;
+                        }
 
                         return r;
                 }