]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/stdio-bridge/stdio-bridge.c
various: use _NEG_ macros to reduce indentation
[thirdparty/systemd.git] / src / stdio-bridge / stdio-bridge.c
index 33701e775eadcdb26794f6ac3bf67383aa16684b..48c29a67b4cdf9ffea6a404c5b19a358f54c7b65 100644 (file)
 #include "sd-daemon.h"
 
 #include "alloc-util.h"
+#include "build.h"
 #include "bus-internal.h"
 #include "bus-util.h"
 #include "errno-util.h"
 #include "io-util.h"
 #include "log.h"
 #include "main-func.h"
-#include "util.h"
-#include "version.h"
 
 #define DEFAULT_BUS_PATH "unix:path=/run/dbus/system_bus_socket"
 
 static const char *arg_bus_path = DEFAULT_BUS_PATH;
 static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
-static bool arg_user = false;
+static RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
 
 static int help(void) {
         printf("%s [OPTIONS...]\n\n"
-               "Forward messages between two D-Bus busses via a pipe or socket.\n\n"
+               "Forward messages between a pipe or socket and a D-Bus bus.\n\n"
                "  -h --help              Show this help\n"
                "     --version           Show package version\n"
                "  -p --bus-path=PATH     Path to the bus address (default: %s)\n"
@@ -73,11 +72,11 @@ static int parse_argv(int argc, char *argv[]) {
                         return version();
 
                 case ARG_USER:
-                        arg_user = true;
+                        arg_runtime_scope = RUNTIME_SCOPE_USER;
                         break;
 
                 case ARG_SYSTEM:
-                        arg_user = false;
+                        arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
                         break;
 
                 case 'p':
@@ -133,7 +132,7 @@ static int run(int argc, char *argv[]) {
                 return log_error_errno(r, "Failed to allocate bus: %m");
 
         if (arg_transport == BUS_TRANSPORT_MACHINE)
-                r = bus_set_address_machine(a, arg_user, arg_bus_path);
+                r = bus_set_address_machine(a, arg_runtime_scope, arg_bus_path);
         else
                 r = sd_bus_set_address(a, arg_bus_path);
         if (r < 0)
@@ -196,13 +195,11 @@ static int run(int argc, char *argv[]) {
                         continue;
 
                 r = sd_bus_process(b, &m);
-                if (r < 0) {
-                        /* treat 'connection reset by peer' as clean exit condition */
-                        if (ERRNO_IS_DISCONNECT(r))
-                                return 0;
-
+                if (ERRNO_IS_NEG_DISCONNECT(r))
+                        /* Treat 'connection reset by peer' as clean exit condition */
+                        return 0;
+                if (r < 0)
                         return log_error_errno(r, "Failed to process bus: %m");
-                }
 
                 if (m) {
                         r = sd_bus_send(a, m, NULL);
@@ -242,7 +239,7 @@ static int run(int argc, char *argv[]) {
                 };
 
                 r = ppoll_usec(p, ELEMENTSOF(p), t);
-                if (r < 0)
+                if (r < 0 && !ERRNO_IS_TRANSIENT(r))  /* don't be bothered by signals, i.e. EINTR */
                         return log_error_errno(r, "ppoll() failed: %m");
         }