summaryrefslogtreecommitdiff
path: root/src/core/dbus-execute.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-02-05 02:02:00 +0100
committerLennart Poettering <lennart@poettering.net>2014-02-05 02:03:10 +0100
commitc7040b5d1c2c148f12b6a5eef3dfce1661805131 (patch)
treedc82be22b8c2ee12913b6723ddf148f8fadeb917 /src/core/dbus-execute.c
parent7b1796403ae1ed0c3299867874cc82ed3ed413a6 (diff)
core: allow User=, Group=, Nice=, Environment=, Type= to be passed when creating a transient service
Diffstat (limited to 'src/core/dbus-execute.c')
-rw-r--r--src/core/dbus-execute.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index edf84f89fd..d2bbda2dba 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -30,6 +30,7 @@
#include "execute.h"
#include "dbus-execute.h"
#include "capability.h"
+#include "env-util.h"
BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput);
@@ -513,3 +514,126 @@ int bus_property_get_exec_command_list(
return sd_bus_message_close_container(reply);
}
+
+int bus_exec_context_set_transient_property(
+ Unit *u,
+ ExecContext *c,
+ const char *name,
+ sd_bus_message *message,
+ UnitSetPropertiesMode mode,
+ sd_bus_error *error) {
+
+ int r;
+
+ assert(u);
+ assert(c);
+ assert(name);
+ assert(message);
+
+ if (streq(name, "User")) {
+ const char *uu;
+
+ r = sd_bus_message_read(message, "s", &uu);
+ if (r < 0)
+ return r;
+
+ if (mode != UNIT_CHECK) {
+
+ if (isempty(uu)) {
+ free(c->user);
+ c->user = NULL;
+ } else {
+ char *t;
+
+ t = strdup(uu);
+ if (!t)
+ return -ENOMEM;
+
+ free(c->user);
+ c->user = t;
+ }
+
+ unit_write_drop_in_private_format(u, mode, name, "User=%s\n", uu);
+ }
+
+ return 1;
+
+ } else if (streq(name, "Group")) {
+ const char *gg;
+
+ r = sd_bus_message_read(message, "s", &gg);
+ if (r < 0)
+ return r;
+
+ if (mode != UNIT_CHECK) {
+
+ if (isempty(gg)) {
+ free(c->group);
+ c->group = NULL;
+ } else {
+ char *t;
+
+ t = strdup(gg);
+ if (!t)
+ return -ENOMEM;
+
+ free(c->group);
+ c->group = t;
+ }
+
+ unit_write_drop_in_private_format(u, mode, name, "Group=%s\n", gg);
+ }
+
+ return 1;
+
+ } else if (streq(name, "Nice")) {
+ int n;
+
+ r = sd_bus_message_read(message, "i", &n);
+ if (r < 0)
+ return r;
+
+ if (n < PRIO_MIN || n >= PRIO_MAX)
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Nice value out of range");
+
+ if (mode != UNIT_CHECK) {
+ c->nice = n;
+ unit_write_drop_in_private_format(u, mode, name, "Nice=%i\n", n);
+ }
+
+ return 1;
+
+ } else if (streq(name, "Environment")) {
+
+ _cleanup_strv_free_ char **l = NULL;
+
+ r = sd_bus_message_read_strv(message, &l);
+ if (r < 0)
+ return r;
+
+ if (!strv_env_is_valid(l))
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
+
+ if (mode != UNIT_CHECK) {
+ _cleanup_free_ char *joined;
+ char **e;
+
+ e = strv_env_merge(2, c->environment, l);
+ if (!e)
+ return -ENOMEM;
+
+ strv_free(c->environment);
+ c->environment = e;
+
+ joined = strv_join(c->environment, " ");
+ if (!joined)
+ return -ENOMEM;
+
+ unit_write_drop_in_private_format(u, mode, name, "Environment=%s\n", joined);
+ }
+
+ return 1;
+ }
+
+ return 0;
+}