core: allow setting of the description string for transient units
This commit is contained in:
parent
6c12b52e19
commit
9f2e86af06
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -148,10 +156,6 @@ static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
|
|||
static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_bus_error *error, sd_bus_message **reply) {
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_close_container(m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_close_container(m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue