core: add exec_output_is_file() helper
The set of file based output types is open-coded in three places (and a fourth one is about to be added), let's define it once, next to the other ExecInput/ExecOutput predicates.
This commit is contained in:
committed by
Luca Boccassi
parent
efa16c7f31
commit
c64cb914ac
@@ -459,7 +459,7 @@ static bool can_inherit_stderr_from_stdout(const ExecContext *context) {
|
||||
if (e == EXEC_OUTPUT_NAMED_FD)
|
||||
return false;
|
||||
|
||||
if (IN_SET(e, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, EXEC_OUTPUT_FILE_TRUNCATE))
|
||||
if (exec_output_is_file(e))
|
||||
return path_equal(context->stdio_file[STDOUT_FILENO], context->stdio_file[STDERR_FILENO]);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -513,6 +513,12 @@ static inline bool exec_input_is_inheritable(ExecInput i) {
|
||||
return exec_input_is_terminal(i) || IN_SET(i, EXEC_INPUT_SOCKET, EXEC_INPUT_NAMED_FD);
|
||||
}
|
||||
|
||||
static inline bool exec_output_is_file(ExecOutput o) {
|
||||
/* The output types that refer to a regular file (StandardOutput=file:…, append:…, truncate:…), i.e.
|
||||
* that require a companion path in ExecContext.stdio_file[] */
|
||||
return IN_SET(o, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, EXEC_OUTPUT_FILE_TRUNCATE);
|
||||
}
|
||||
|
||||
int exec_spawn(
|
||||
Unit *unit,
|
||||
ExecCommand *command,
|
||||
|
||||
@@ -6541,7 +6541,7 @@ int config_parse_output_restricted(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, EXEC_OUTPUT_FILE_TRUNCATE)) {
|
||||
if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD) || exec_output_is_file(t)) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user