summaryrefslogtreecommitdiff
path: root/src/core/dbus-execute.c
diff options
context:
space:
mode:
authorDaniel Mack <github@zonque.org>2015-10-20 10:31:38 +0200
committerDaniel Mack <github@zonque.org>2015-10-20 10:31:38 +0200
commit824b35c3859bc99b97ac5fa6e09aa34627e9bcd5 (patch)
tree266c8f9988ba8d1cab00a55b360b3f2e42096dde /src/core/dbus-execute.c
parentec566e4c7cee67ec2c39475ef08f18a9f1b80efd (diff)
parent2229f656677f0d50c507aec40cda59f66da5c949 (diff)
Merge pull request #1568 from poettering/netclass
various fixes, for various things
Diffstat (limited to 'src/core/dbus-execute.c')
-rw-r--r--src/core/dbus-execute.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index b71e5ad300..a286149b53 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -1208,8 +1208,9 @@ int bus_exec_context_set_transient_property(
_cleanup_free_ char *joined = NULL;
_cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char **l = NULL;
size_t size = 0;
- bool empty_array = true;
+ char **i;
r = sd_bus_message_enter_container(message, 'a', "(sb)");
if (r < 0)
@@ -1219,18 +1220,13 @@ int bus_exec_context_set_transient_property(
if (!f)
return -ENOMEM;
- if (mode != UNIT_CHECK) {
- char **buf;
- STRV_FOREACH(buf, c->environment_files)
- fprintf(f, "EnvironmentFile=%s\n", *buf);
- }
+ STRV_FOREACH(i, c->environment_files)
+ fprintf(f, "EnvironmentFile=%s\n", *i);
while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
const char *path;
int b;
- empty_array = false;
-
r = sd_bus_message_read(message, "sb", &path, &b);
if (r < 0)
return r;
@@ -1247,12 +1243,12 @@ int bus_exec_context_set_transient_property(
char *buf = NULL;
buf = strjoin(b ? "-" : "", path, NULL);
- if (buf == NULL)
+ if (!buf)
return -ENOMEM;
fprintf(f, "EnvironmentFile=%s\n", buf);
- r = strv_consume(&c->environment_files, buf);
+ r = strv_consume(&l, buf);
if (r < 0)
return r;
}
@@ -1260,14 +1256,22 @@ int bus_exec_context_set_transient_property(
if (r < 0)
return r;
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ return r;
- if (mode != UNIT_CHECK)
- if (empty_array) {
- strv_clear(c->environment_files);
+ if (mode != UNIT_CHECK) {
+ if (strv_isempty(l)) {
+ c->environment_files = strv_free(c->environment_files);
unit_write_drop_in_private(u, mode, name, "EnvironmentFile=\n");
- } else
+ } else {
+ r = strv_extend_strv(&c->environment_files, l, true);
+ if (r < 0)
+ return r;
+
unit_write_drop_in_private(u, mode, name, joined);
+ }
+ }
r = sd_bus_message_exit_container(message);
if (r < 0)