From c93d527f46070c0603a268408e8a24c924b4f95b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Oct 2018 20:14:51 +0200 Subject: [PATCH 1/2] exec-util: use fflush_and_check() where appropriate --- src/basic/exec-util.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/basic/exec-util.c b/src/basic/exec-util.c index aa26902a20..32c6418482 100644 --- a/src/basic/exec-util.c +++ b/src/basic/exec-util.c @@ -268,8 +268,8 @@ static int gather_environment_generate(int fd, void *arg) { } static int gather_environment_collect(int fd, void *arg) { - char ***env = arg; _cleanup_fclose_ FILE *f = NULL; + char ***env = arg; int r; /* Write out a series of env=cescape(VAR=value) assignments to fd. */ @@ -286,8 +286,9 @@ static int gather_environment_collect(int fd, void *arg) { if (r < 0) return r; - if (ferror(f)) - return errno > 0 ? -errno : -EIO; + r = fflush_and_check(f); + if (r < 0) + return r; return 0; } From efa3f34e844d39eb143f7024eb53962a2578a2b3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Oct 2018 20:18:27 +0200 Subject: [PATCH 2/2] service: use free_and_replace() where we can --- src/core/service.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index fa2c6996ad..5f98a504d0 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -2601,10 +2601,10 @@ static int service_deserialize_exec_command(Unit *u, const char *key, const char _cleanup_free_ char *arg = NULL; r = extract_first_word(&value, &arg, NULL, EXTRACT_CUNESCAPE); + if (r < 0) + return r; if (r == 0) break; - else if (r < 0) - return r; switch (state) { case STATE_EXEC_COMMAND_TYPE: @@ -2744,10 +2744,8 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value, r = cunescape(value, 0, &t); if (r < 0) log_unit_debug_errno(u, r, "Failed to unescape status text: %s", value); - else { - free(s->status_text); - s->status_text = t; - } + else + free_and_replace(s->status_text, t); } else if (streq(key, "accept-socket")) { Unit *socket;