Skip to content

Commit

Permalink
Merge pull request #6412 from electron/relaunch-dev-null
Browse files Browse the repository at this point in the history
Redirect relaunch process's stdout to /dev/null
  • Loading branch information
zcbenz committed Jul 9, 2016
2 parents 1beba5b + 54f74e8 commit 187b68b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions atom/browser/relauncher_linux.cc
Expand Up @@ -4,11 +4,13 @@

#include "atom/browser/relauncher.h"

#include <fcntl.h>
#include <signal.h>
#include <sys/prctl.h>
#include <sys/signalfd.h>

#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"
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 187b68b

Please sign in to comment.