From b80a30ba2aa284cf2f901d60a17e53cd8f1aea28 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 11 Apr 2022 14:42:18 +0200 Subject: [PATCH] Redirect STDERR to /dev/null in process spawn --- src/common/process.cpp | 2 ++ src/common/process.h | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/process.cpp b/src/common/process.cpp index 0419e4d6..c8fa8013 100644 --- a/src/common/process.cpp +++ b/src/common/process.cpp @@ -127,6 +127,8 @@ Process::StringResult Process::spawn_get_stdout_line() { posix_spawn_file_actions_t actions; posix_spawn_file_actions_init(&actions); posix_spawn_file_actions_adddup2(&actions, output_pipe[1], STDOUT_FILENO); + posix_spawn_file_actions_addopen(&actions, STDERR_FILENO, "/dev/null", + O_WRONLY | O_APPEND, 0); posix_spawn_file_actions_addclose(&actions, output_pipe[0]); posix_spawn_file_actions_addclose(&actions, output_pipe[1]); diff --git a/src/common/process.h b/src/common/process.h index 3743109e..66dac02f 100644 --- a/src/common/process.h +++ b/src/common/process.h @@ -158,10 +158,11 @@ class Process { inline void environment(ProcessEnvironment env) { env_ = std::move(env); } /** - * Spawn the process, leave STDIN and STDERR alone, and return the first - * line (without the trailing linefeed) of STDOUT. The first output line - * will still be returned even if the process exits with a non-zero exit - * code. Uses `posix_spawn()`, leaves file descriptors in tact. + * Spawn the process, leave STDIN, redirect STDERR to `/dev/null`, and + * return the first line (without the trailing linefeed) of STDOUT. The + * first output line will still be returned even if the process exits with a + * non-zero exit code. Uses `posix_spawn()`, leaves file descriptors in + * tact. */ StringResult spawn_get_stdout_line();