From 54f74e81602df56b06b055a5e6d62c7f9ecdb8d0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 9 Jul 2016 17:59:40 +0900 Subject: [PATCH] Redirect relaunch process's stdout to /dev/null --- atom/browser/relauncher_linux.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/atom/browser/relauncher_linux.cc b/atom/browser/relauncher_linux.cc index 2fbbd47faf03..6d60b072f6d9 100644 --- a/atom/browser/relauncher_linux.cc +++ b/atom/browser/relauncher_linux.cc @@ -4,11 +4,13 @@ #include "atom/browser/relauncher.h" +#include #include #include #include #include "base/files/file_util.h" +#include "base/files/scoped_file.h" #include "base/logging.h" #include "base/posix/eintr_wrapper.h" #include "base/process/launch.h" @@ -55,9 +57,17 @@ void RelauncherSynchronizeWithParent() { int LaunchProgram(const StringVector& relauncher_args, const StringVector& argv) { + // Redirect the stdout of child process to /dev/null, otherwise after + // relaunch the child process will raise exception when writing to stdout. + base::ScopedFD devnull(HANDLE_EINTR(open("/dev/null", O_WRONLY))); + base::FileHandleMappingVector no_stdout; + no_stdout.push_back(std::make_pair(devnull.get(), STDERR_FILENO)); + no_stdout.push_back(std::make_pair(devnull.get(), STDOUT_FILENO)); + base::LaunchOptions options; options.allow_new_privs = true; options.new_process_group = true; // detach + options.fds_to_remap = &no_stdout; base::Process process = base::LaunchProcess(argv, options); return process.IsValid() ? 0 : 1; }