mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 10:51:20 +03:00
core: be more careful when inheriting stdout fds to stderr
We need to compare the fd name/file name if we inherit an fd from stdout to stderr. Let's do that. Fixes: #10875
This commit is contained in:
parent
8d33232ef1
commit
41fc585a7a
@ -544,6 +544,30 @@ static int setup_input(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool can_inherit_stderr_from_stdout(
|
||||||
|
const ExecContext *context,
|
||||||
|
ExecOutput o,
|
||||||
|
ExecOutput e) {
|
||||||
|
|
||||||
|
assert(context);
|
||||||
|
|
||||||
|
/* Returns true, if given the specified STDERR and STDOUT output we can directly dup() the stdout fd to the
|
||||||
|
* stderr fd */
|
||||||
|
|
||||||
|
if (e == EXEC_OUTPUT_INHERIT)
|
||||||
|
return true;
|
||||||
|
if (e != o)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (e == EXEC_OUTPUT_NAMED_FD)
|
||||||
|
return streq_ptr(context->stdio_fdname[STDOUT_FILENO], context->stdio_fdname[STDERR_FILENO]);
|
||||||
|
|
||||||
|
if (IN_SET(e, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND))
|
||||||
|
return streq_ptr(context->stdio_file[STDOUT_FILENO], context->stdio_file[STDERR_FILENO]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int setup_output(
|
static int setup_output(
|
||||||
const Unit *unit,
|
const Unit *unit,
|
||||||
const ExecContext *context,
|
const ExecContext *context,
|
||||||
@ -602,7 +626,7 @@ static int setup_output(
|
|||||||
return fileno;
|
return fileno;
|
||||||
|
|
||||||
/* Duplicate from stdout if possible */
|
/* Duplicate from stdout if possible */
|
||||||
if ((e == o && e != EXEC_OUTPUT_NAMED_FD) || e == EXEC_OUTPUT_INHERIT)
|
if (can_inherit_stderr_from_stdout(context, o, e))
|
||||||
return dup2(STDOUT_FILENO, fileno) < 0 ? -errno : fileno;
|
return dup2(STDOUT_FILENO, fileno) < 0 ? -errno : fileno;
|
||||||
|
|
||||||
o = e;
|
o = e;
|
||||||
@ -693,7 +717,6 @@ static int setup_output(
|
|||||||
flags |= O_APPEND;
|
flags |= O_APPEND;
|
||||||
|
|
||||||
fd = acquire_path(context->stdio_file[fileno], flags, 0666 & ~context->umask);
|
fd = acquire_path(context->stdio_file[fileno], flags, 0666 & ~context->umask);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user