static bool arg_remain_after_exit = false;
static const char *arg_unit = NULL;
static const char *arg_description = NULL;
static const char *arg_slice = NULL;
static bool arg_send_sighup = false;
static bool arg_remain_after_exit = false;
static const char *arg_unit = NULL;
static const char *arg_description = NULL;
static const char *arg_slice = NULL;
static bool arg_send_sighup = false;
" -h --help Show this help\n"
" --version Show package version\n"
" --user Run as user unit\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --user Run as user unit\n"
" --scope Run this as scope rather than service\n"
" --unit=UNIT Run under the specified unit name\n"
" --description=TEXT Description for unit\n"
" --scope Run this as scope rather than service\n"
" --unit=UNIT Run under the specified unit name\n"
" --description=TEXT Description for unit\n"
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "user", no_argument, NULL, ARG_USER },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "user", no_argument, NULL, ARG_USER },
{ "scope", no_argument, NULL, ARG_SCOPE },
{ "unit", required_argument, NULL, ARG_UNIT },
{ "description", required_argument, NULL, ARG_DESCRIPTION },
{ "slice", required_argument, NULL, ARG_SLICE },
{ "remain-after-exit", no_argument, NULL, 'r' },
{ "send-sighup", no_argument, NULL, ARG_SEND_SIGHUP },
{ "scope", no_argument, NULL, ARG_SCOPE },
{ "unit", required_argument, NULL, ARG_UNIT },
{ "description", required_argument, NULL, ARG_DESCRIPTION },
{ "slice", required_argument, NULL, ARG_SLICE },
{ "remain-after-exit", no_argument, NULL, 'r' },
{ "send-sighup", no_argument, NULL, ARG_SEND_SIGHUP },
+ { "host", required_argument, NULL, 'H' },
+ { "machine", required_argument, NULL, 'M' },
+ {},
- while ((c = getopt_long(argc, argv, "+hr", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "+hrH:M:", options, NULL)) >= 0) {
+ if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL) {
+ log_error("Execution in user context is not supported on non-local systems.");
+ return -EINVAL;
+ }
+
+ if (arg_scope && arg_transport != BUS_TRANSPORT_LOCAL) {
+ log_error("Scope execution is not supported on non-local systems.");
+ return -EINVAL;
+ }
+
log_info("Running as unit %s.", name);
r = sd_bus_message_new_method_call(
log_info("Running as unit %s.", name);
r = sd_bus_message_new_method_call(
static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_bus_error *error, sd_bus_message **reply) {
int r;
static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_bus_error *error, sd_bus_message **reply) {
int r;
- return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
+ r = sd_bus_message_append(m, "a(sa(sv))", 0);
+ if (r < 0)
+ return r;
+
+ return sd_bus_call(bus, m, 0, error, reply);
- return message_start_transient_unit_send(bus, m, error, &reply);
+ return message_start_transient_unit_send(bus, m, error, NULL);
- r = message_start_transient_unit_send(bus, m, error, &reply);
+ r = message_start_transient_unit_send(bus, m, error, NULL);
_cleanup_bus_unref_ sd_bus *bus = NULL;
_cleanup_free_ char *description = NULL, *command = NULL;
int r;
_cleanup_bus_unref_ sd_bus *bus = NULL;
_cleanup_free_ char *description = NULL, *command = NULL;
int r;
r = find_binary(argv[optind], &command);
if (r < 0) {
log_error("Failed to find executable %s: %s", argv[optind], strerror(-r));
r = find_binary(argv[optind], &command);
if (r < 0) {
log_error("Failed to find executable %s: %s", argv[optind], strerror(-r));
- if (arg_user)
- r = sd_bus_open_user(&bus);
- else
- r = sd_bus_open_system(&bus);
+ r = bus_open_transport(arg_transport, arg_host, arg_user, &bus);
}
if (arg_scope)
r = start_transient_scope(bus, argv + optind, &error);
else
r = start_transient_service(bus, argv + optind, &error);
}
if (arg_scope)
r = start_transient_scope(bus, argv + optind, &error);
else
r = start_transient_service(bus, argv + optind, &error);
- if (r < 0) {
- log_error("Failed start transient unit: %s", error.message ? error.message : strerror(-r));
- sd_bus_error_free(&error);
- goto fail;
- }
+ if (r < 0)
+ log_error("Failed start transient unit: %s", bus_error_message(&error, r));