summaryrefslogtreecommitdiff
path: root/src/run/run.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-07-01 00:40:56 +0200
committerLennart Poettering <lennart@poettering.net>2013-07-01 00:40:56 +0200
commit9f2e86af0600e99cff00d1c92f9bb8d38f29896a (patch)
tree92a08a391007eb6eb4731b474375652227917e78 /src/run/run.c
parent6c12b52e19640747e96f89d85422941a23dc6b29 (diff)
core: allow setting of the description string for transient units
Diffstat (limited to 'src/run/run.c')
-rw-r--r--src/run/run.c53
1 files changed, 38 insertions, 15 deletions
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;
}