#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"
}
static int parse_argv(int argc, char *argv[]) {
-
enum {
ARG_VERSION = 0x100,
ARG_MACHINE,
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hp:M:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hp:M:", options, NULL)) >= 0)
switch (c) {
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':
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown option code %c", c);
}
- }
return 1;
}
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)
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);
};
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");
}