core/exec-invoke: use path_equal() on for stdio files
This commit is contained in:
@@ -430,8 +430,8 @@ static int setup_input(
|
||||
|
||||
assert(context->stdio_file[STDIN_FILENO]);
|
||||
|
||||
rw = (context->std_output == EXEC_OUTPUT_FILE && streq_ptr(context->stdio_file[STDIN_FILENO], context->stdio_file[STDOUT_FILENO])) ||
|
||||
(context->std_error == EXEC_OUTPUT_FILE && streq_ptr(context->stdio_file[STDIN_FILENO], context->stdio_file[STDERR_FILENO]));
|
||||
rw = (context->std_output == EXEC_OUTPUT_FILE && path_equal(context->stdio_file[STDIN_FILENO], context->stdio_file[STDOUT_FILENO])) ||
|
||||
(context->std_error == EXEC_OUTPUT_FILE && path_equal(context->stdio_file[STDIN_FILENO], context->stdio_file[STDERR_FILENO]));
|
||||
|
||||
fd = acquire_path(context->stdio_file[STDIN_FILENO], rw ? O_RDWR : O_RDONLY, 0666 & ~context->umask);
|
||||
if (fd < 0)
|
||||
@@ -466,7 +466,7 @@ static bool can_inherit_stderr_from_stdout(
|
||||
return false;
|
||||
|
||||
if (IN_SET(e, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, EXEC_OUTPUT_FILE_TRUNCATE))
|
||||
return streq_ptr(context->stdio_file[STDOUT_FILENO], context->stdio_file[STDERR_FILENO]);
|
||||
return path_equal(context->stdio_file[STDOUT_FILENO], context->stdio_file[STDERR_FILENO]);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -632,15 +632,14 @@ static int setup_output(
|
||||
case EXEC_OUTPUT_FILE:
|
||||
case EXEC_OUTPUT_FILE_APPEND:
|
||||
case EXEC_OUTPUT_FILE_TRUNCATE: {
|
||||
bool rw;
|
||||
int fd, flags;
|
||||
|
||||
assert(context->stdio_file[fileno]);
|
||||
|
||||
rw = context->std_input == EXEC_INPUT_FILE &&
|
||||
streq_ptr(context->stdio_file[fileno], context->stdio_file[STDIN_FILENO]);
|
||||
|
||||
if (rw)
|
||||
/* stdin points to the same file hence setup_input() opened it as rw already?
|
||||
* Then just duplicate it. */
|
||||
if (context->std_input == EXEC_INPUT_FILE &&
|
||||
path_equal(context->stdio_file[fileno], context->stdio_file[STDIN_FILENO]))
|
||||
return RET_NERRNO(dup2(STDIN_FILENO, fileno));
|
||||
|
||||
flags = O_WRONLY;
|
||||
|
||||
Reference in New Issue
Block a user