Improve process launch handle sharing API.

https://codereview.chromium.org/2950153002
This commit is contained in:
Aleksei Kuzmin 2017-12-08 11:39:51 +03:00 committed by Cheng Zhao
parent da7fc54e37
commit f5d207f8f0
2 changed files with 4 additions and 8 deletions

View file

@ -60,14 +60,13 @@ int LaunchProgram(const StringVector& relauncher_args,
// 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;
options.fds_to_remap.push_back(std::make_pair(devnull.get(), STDERR_FILENO));
options.fds_to_remap.push_back(std::make_pair(devnull.get(), STDOUT_FILENO));
base::Process process = base::LaunchProcess(argv, options);
return process.IsValid() ? 0 : 1;
}