summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/dbus-scope.c4
-rw-r--r--src/core/dbus-service.c4
-rw-r--r--src/core/dbus-unit.c33
-rw-r--r--src/run/run.c53
4 files changed, 75 insertions, 19 deletions
diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c
index 1497b76761..604d147945 100644
--- a/src/core/dbus-scope.c
+++ b/src/core/dbus-scope.c
@@ -76,7 +76,7 @@ DBusHandlerResult bus_scope_message_handler(Unit *u, DBusConnection *c, DBusMess
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
-static int bus_scope_set_transient_properties(
+static int bus_scope_set_transient_property(
Scope *s,
const char *name,
DBusMessageIter *i,
@@ -146,7 +146,7 @@ int bus_scope_set_property(
if (u->load_state == UNIT_STUB) {
/* While we are created we still accept PIDs */
- r = bus_scope_set_transient_properties(s, name, i, mode, error);
+ r = bus_scope_set_transient_property(s, name, i, mode, error);
if (r != 0)
return r;
}
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
index e5e95a1ab9..3bedda6c01 100644
--- a/src/core/dbus-service.c
+++ b/src/core/dbus-service.c
@@ -165,7 +165,7 @@ DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connectio
return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
}
-static int bus_service_set_transient_properties(
+static int bus_service_set_transient_property(
Service *s,
const char *name,
DBusMessageIter *i,
@@ -304,7 +304,7 @@ int bus_service_set_property(
if (u->transient && u->load_state == UNIT_STUB) {
/* This is a transient unit, let's load a little more */
- r = bus_service_set_transient_properties(s, name, i, mode, error);
+ r = bus_service_set_transient_property(s, name, i, mode, error);
if (r != 0)
return r;
}
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index f518505750..36c3abdb97 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -764,6 +764,37 @@ oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
+static int bus_unit_set_transient_property(
+ Unit *u,
+ const char *name,
+ DBusMessageIter *i,
+ UnitSetPropertiesMode mode,
+ DBusError *error) {
+
+ int r;
+
+ assert(u);
+ assert(name);
+ assert(i);
+
+ if (streq(name, "Description")) {
+ const char *description;
+
+ if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(i, &description);
+
+ r = unit_set_description(u, description);
+ if (r < 0)
+ return r;
+
+ return 1;
+ }
+
+ return 0;
+}
+
int bus_unit_set_properties(
Unit *u,
DBusMessageIter *iter,
@@ -823,6 +854,8 @@ int bus_unit_set_properties(
dbus_message_iter_recurse(&sub2, &sub3);
r = UNIT_VTABLE(u)->bus_set_property(u, name, &sub3, for_real ? mode : UNIT_CHECK, error);
+ if (r == 0 && u->transient && u->load_state == UNIT_STUB)
+ r = bus_unit_set_transient_property(u, name, &sub3, for_real ? mode : UNIT_CHECK, error);
if (r < 0)
return r;
if (r == 0) {
diff --git a/src/run/run.c b/src/run/run.c
index b45116870c..98c3af058f 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -32,6 +32,7 @@
static bool arg_scope = false;
static bool arg_user = false;
static const char *arg_unit = NULL;
+static const char *arg_description = NULL;
static int help(void) {
@@ -41,7 +42,8 @@ static int help(void) {
" --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",
+ " --unit=UNIT Run under the specified unit name\n"
+ " --description=TEXT Description for unit\n",
program_invocation_short_name);
return 0;
@@ -53,16 +55,18 @@ static int parse_argv(int argc, char *argv[]) {
ARG_VERSION = 0x100,
ARG_USER,
ARG_SCOPE,
- ARG_UNIT
+ ARG_UNIT,
+ ARG_DESCRIPTION
};
static const struct option options[] = {
- { "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 },
- { NULL, 0, NULL, 0 }
+ { "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 },
+ { NULL, 0, NULL, 0 },
};
int c;
@@ -95,6 +99,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_unit = optarg;
break;
+ case ARG_DESCRIPTION:
+ arg_description = optarg;
+ break;
+
case '?':
return -EINVAL;
@@ -135,7 +143,7 @@ static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
if (r < 0)
return r;
- r = sd_bus_message_open_container(m, 'r', "sv");
+ r = sd_bus_message_append(m, "(sv)", "Description", "s", arg_description);
if (r < 0)
return r;
@@ -152,10 +160,6 @@ static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_
if (r < 0)
return r;
- r = sd_bus_message_close_container(m);
- if (r < 0)
- return r;
-
return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
}
@@ -180,6 +184,10 @@ static int start_transient_service(
if (r < 0)
return r;
+ r = sd_bus_message_open_container(m, 'r', "sv");
+ if (r < 0)
+ return r;
+
r = sd_bus_message_append(m, "s", "ExecStart");
if (r < 0)
return r;
@@ -230,6 +238,10 @@ static int start_transient_service(
if (r < 0)
return r;
+ r = sd_bus_message_close_container(m);
+ if (r < 0)
+ return r;
+
return message_start_transient_unit_send(bus, m, error, &reply);
}
@@ -253,7 +265,7 @@ static int start_transient_scope(
if (r < 0)
return r;
- r = sd_bus_message_append(m, "sv", "PIDs", "au", 1, (uint32_t) getpid());
+ r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, (uint32_t) getpid());
if (r < 0)
return r;
@@ -269,6 +281,7 @@ static int start_transient_scope(
int main(int argc, char* argv[]) {
sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_unref_ sd_bus *bus = NULL;
+ _cleanup_free_ char *description = NULL;
int r;
log_parse_environment();
@@ -278,6 +291,16 @@ int main(int argc, char* argv[]) {
if (r <= 0)
goto fail;
+ if (!arg_description) {
+ description = strv_join(argv + optind, " ");
+ if (!description) {
+ r = log_oom();
+ goto fail;
+ }
+
+ arg_description = description;
+ }
+
if (arg_user)
r = sd_bus_open_user(&bus);
else
@@ -292,7 +315,7 @@ int main(int argc, char* argv[]) {
else
r = start_transient_service(bus, argv + optind, &error);
if (r < 0) {
- log_error("Failed start transient unit: %s", error.message);
+ log_error("Failed start transient unit: %s", error.message ? error.message : strerror(-r));
sd_bus_error_free(&error);
goto fail;
}