summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-10-30 16:44:55 +0100
committerLennart Poettering <lennart@poettering.net>2013-10-30 16:44:55 +0100
commitd21ed1ead18d16d35c30299a69d3366847f8a039 (patch)
tree34387ec5193e1c9b229f93b278d0d830fa0b4008 /src/libsystemd-bus
parent5220a6f3a1f5a7324898ecfe7649af254cf561a6 (diff)
run: add support for executing commands remotely via SSH or in a container
Also, unify the transport logic a bit, since we reuse the same scheme in many of our client tools.
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/bus-container.c2
-rw-r--r--src/libsystemd-bus/bus-util.c35
-rw-r--r--src/libsystemd-bus/bus-util.h10
3 files changed, 47 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-container.c b/src/libsystemd-bus/bus-container.c
index eac1863244..31bb624b34 100644
--- a/src/libsystemd-bus/bus-container.c
+++ b/src/libsystemd-bus/bus-container.c
@@ -44,6 +44,8 @@ int bus_container_connect(sd_bus *b) {
return -ENOMEM;
r = parse_env_file(p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL);
+ if (r == -ENOENT)
+ return -EHOSTDOWN;
if (r < 0)
return r;
if (!s)
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index 53be009be2..e62ea6a877 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -594,3 +594,38 @@ int bus_generic_print_property(const char *name, sd_bus_message *property, bool
return 0;
}
+
+int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) {
+ int r;
+
+ assert(transport >= 0);
+ assert(transport < _BUS_TRANSPORT_MAX);
+ assert(bus);
+
+ assert_return((transport == BUS_TRANSPORT_LOCAL) == !host, -EINVAL);
+ assert_return(transport == BUS_TRANSPORT_LOCAL || !user, -ENOTSUP);
+
+ switch (transport) {
+
+ case BUS_TRANSPORT_LOCAL:
+ if (user)
+ r = sd_bus_open_user(bus);
+ else
+ r = sd_bus_open_system(bus);
+
+ break;
+
+ case BUS_TRANSPORT_REMOTE:
+ r = sd_bus_open_system_remote(host, bus);
+ break;
+
+ case BUS_TRANSPORT_CONTAINER:
+ r = sd_bus_open_system_container(host, bus);
+ break;
+
+ default:
+ assert_not_reached("Hmm, unknown transport type.");
+ }
+
+ return r;
+}
diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h
index 46e10b3c1d..e70006e6eb 100644
--- a/src/libsystemd-bus/bus-util.h
+++ b/src/libsystemd-bus/bus-util.h
@@ -27,6 +27,14 @@
#include "time-util.h"
#include "util.h"
+typedef enum BusTransport {
+ BUS_TRANSPORT_LOCAL,
+ BUS_TRANSPORT_REMOTE,
+ BUS_TRANSPORT_CONTAINER,
+ _BUS_TRANSPORT_MAX,
+ _BUS_TRANSPORT_INVALID = -1
+} BusTransport;
+
int bus_async_unregister_and_quit(sd_event *e, sd_bus *bus, const char *name);
int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout);
@@ -39,6 +47,8 @@ void bus_verify_polkit_async_registry_free(sd_bus *bus, Hashmap *registry);
int bus_open_system_systemd(sd_bus **_bus);
+int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
+
int bus_generic_print_property(const char *name, sd_bus_message *property, bool all);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref);