From: Lennart Poettering Date: Thu, 26 Oct 2017 18:06:42 +0000 (+0200) Subject: core: clean up config_parse_exec_input() a bit X-Git-Tag: v236~181^2~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9bd6a50e90427dd120d0c9495b50fda2f72887b6;p=thirdparty%2Fsystemd.git core: clean up config_parse_exec_input() a bit Mostly coding style fixes, but most importantly, initialize c->std_input only after we know the free_and_strdup() invocation succeeded, so that we don't leave half-initialized fields around on failure. --- diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index e52f608db71..a3950b8d725 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -833,16 +833,18 @@ int config_parse_socket_bindtodevice( DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output literal specifier"); -int config_parse_exec_input(const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { +int config_parse_exec_input( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + ExecContext *c = data; const char *name; int r; @@ -859,19 +861,25 @@ int config_parse_exec_input(const char *unit, log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name, ignoring: %s", name); return 0; } - c->std_input = EXEC_INPUT_NAMED_FD; + r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], name); if (r < 0) - log_oom(); - return r; + return log_oom(); + + c->std_input = EXEC_INPUT_NAMED_FD; } else { - ExecInput ei = exec_input_from_string(rvalue); - if (ei == _EXEC_INPUT_INVALID) + ExecInput ei; + + ei = exec_input_from_string(rvalue); + if (ei < 0) { log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse input specifier, ignoring: %s", rvalue); - else - c->std_input = ei; - return 0; + return 0; + } + + c->std_input = ei; } + + return 0; } int config_parse_exec_output(const char *unit,