diff --git a/atom/browser/relauncher.cc b/atom/browser/relauncher.cc index 557725e6af73..dce4f46b9a75 100644 --- a/atom/browser/relauncher.cc +++ b/atom/browser/relauncher.cc @@ -34,8 +34,7 @@ const CharType* kRelauncherArgSeparator = FILE_PATH_LITERAL("---"); } // namespace internal -bool RelaunchApp(const base::FilePath& app, - const StringVector& args) { +bool RelaunchApp(const base::FilePath& app, const StringVector& args) { // Use the currently-running application's helper process. The automatic // update feature is careful to leave the currently-running version alone, // so this is safe even if the relaunch is the result of an update having @@ -160,10 +159,9 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { // Figure out what to execute, what arguments to pass it, and whether to // start it in the background. bool in_relaunch_args = false; - bool seen_relaunch_executable = false; StringType relaunch_executable; StringVector relauncher_args; - StringVector launch_args; + StringVector launch_argv; for (size_t argv_index = 2; argv_index < argv.size(); ++argv_index) { const StringType& arg(argv[argv_index]); if (!in_relaunch_args) { @@ -173,26 +171,16 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { relauncher_args.push_back(arg); } } else { - if (!seen_relaunch_executable) { - // The first argument after kRelauncherBackgroundArg is the path to - // the executable file or .app bundle directory. The Launch Services - // interface wants this separate from the rest of the arguments. In - // the relaunched process, this path will still be visible at argv[0]. - relaunch_executable.assign(arg); - seen_relaunch_executable = true; - } else { - launch_args.push_back(arg); - } + launch_argv.push_back(arg); } } - if (!seen_relaunch_executable) { + if (launch_argv.empty()) { LOG(ERROR) << "nothing to relaunch"; return 1; } - if (internal::LaunchProgram(relauncher_args, relaunch_executable, - launch_args) != 0) { + if (internal::LaunchProgram(relauncher_args, launch_argv) != 0) { LOG(ERROR) << "failed to launch program"; return 1; } diff --git a/atom/browser/relauncher.h b/atom/browser/relauncher.h index 6b725263f8b3..f6722f946d2a 100644 --- a/atom/browser/relauncher.h +++ b/atom/browser/relauncher.h @@ -59,8 +59,7 @@ using StringVector = base::CommandLine::StringVector; // successfully. Returns true on success, although some failures can occur // after this function returns true if, for example, they occur within the // relauncher process. Returns false when the relaunch definitely failed. -bool RelaunchApp(const base::FilePath& app, - const StringVector& args); +bool RelaunchApp(const base::FilePath& app, const StringVector& args); // Identical to RelaunchApp, but uses |helper| as the path to the relauncher // process, and allows additional arguments to be supplied to the relauncher @@ -113,7 +112,6 @@ StringType GetWaitEventName(base::ProcessId pid); void RelauncherSynchronizeWithParent(); int LaunchProgram(const StringVector& relauncher_args, - const StringType& program, const StringVector& argv); } // namespace internal diff --git a/atom/browser/relauncher_linux.cc b/atom/browser/relauncher_linux.cc index 8a3c3050df50..2fbbd47faf03 100644 --- a/atom/browser/relauncher_linux.cc +++ b/atom/browser/relauncher_linux.cc @@ -53,14 +53,8 @@ void RelauncherSynchronizeWithParent() { HANDLE_EINTR(read(usr2_fd, &si, sizeof(si))); } -int LaunchProgram(const std::vector& relauncher_args, - const std::string& program, - const std::vector& args) { - std::vector argv; - argv.reserve(1 + args.size()); - argv.push_back(program); - argv.insert(argv.end(), args.begin(), args.end()); - +int LaunchProgram(const StringVector& relauncher_args, + const StringVector& argv) { base::LaunchOptions options; options.allow_new_privs = true; options.new_process_group = true; // detach diff --git a/atom/browser/relauncher_mac.cc b/atom/browser/relauncher_mac.cc index a537e311ce1f..ef26f8441df6 100644 --- a/atom/browser/relauncher_mac.cc +++ b/atom/browser/relauncher_mac.cc @@ -4,8 +4,6 @@ #include "atom/browser/relauncher.h" -#include - #include #include #include @@ -13,9 +11,8 @@ #include "base/files/file_util.h" #include "base/logging.h" +#include "base/process/launch.h" #include "base/mac/mac_logging.h" -#include "base/mac/mac_util.h" -#include "base/mac/scoped_cftyperef.h" #include "base/posix/eintr_wrapper.h" #include "base/strings/sys_string_conversions.h" @@ -23,16 +20,6 @@ namespace relauncher { namespace internal { -namespace { - -// The beginning of the "process serial number" argument that Launch Services -// sometimes inserts into command lines. A process serial number is only valid -// for a single process, so any PSN arguments will be stripped from command -// lines during relaunch to avoid confusion. -const char kPSNArg[] = "-psn_"; - -} // namespace - void RelauncherSynchronizeWithParent() { base::ScopedFD relauncher_sync_fd(kRelauncherSyncFD); @@ -90,56 +77,12 @@ void RelauncherSynchronizeWithParent() { } } -int LaunchProgram(const std::vector& relauncher_args, - const std::string& program, - const std::vector& argv) { - // The capacity for relaunch_args is 4 less than argc, because it - // won't contain the argv[0] of the relauncher process, the - // RelauncherTypeArg() at argv[1], kRelauncherArgSeparator, or the - // executable path of the process to be launched. - base::ScopedCFTypeRef relaunch_args( - CFArrayCreateMutable(NULL, argv.size() - 4, &kCFTypeArrayCallBacks)); - if (!relaunch_args) { - LOG(ERROR) << "CFArrayCreateMutable"; - return 1; - } - - for (const std::string& arg : argv) { - // Strip any -psn_ arguments, as they apply to a specific process. - if (arg.compare(0, strlen(kPSNArg), kPSNArg) == 0) - continue; - - base::ScopedCFTypeRef arg_cf(base::SysUTF8ToCFStringRef(arg)); - if (!arg_cf) { - LOG(ERROR) << "base::SysUTF8ToCFStringRef failed for " << arg; - return 1; - } - CFArrayAppendValue(relaunch_args, arg_cf); - } - - FSRef app_fsref; - if (!base::mac::FSRefFromPath(program, &app_fsref)) { - LOG(ERROR) << "base::mac::FSRefFromPath failed for " << program; - return 1; - } - - LSApplicationParameters ls_parameters = { - 0, // version - kLSLaunchDefaults | kLSLaunchAndDisplayErrors | kLSLaunchNewInstance, - &app_fsref, - NULL, // asyncLaunchRefCon - NULL, // environment - relaunch_args, - NULL // initialEvent - }; - - OSStatus status = LSOpenApplication(&ls_parameters, NULL); - if (status != noErr) { - OSSTATUS_LOG(ERROR, status) << "LSOpenApplication"; - return 1; - } - - return 0; +int LaunchProgram(const StringVector& relauncher_args, + const StringVector& argv) { + base::LaunchOptions options; + options.new_process_group = true; // detach + base::Process process = base::LaunchProcess(argv, options); + return process.IsValid() ? 0 : 1; } } // namespace internal diff --git a/atom/browser/relauncher_win.cc b/atom/browser/relauncher_win.cc index 4c31466eb699..bb7617f29cb4 100644 --- a/atom/browser/relauncher_win.cc +++ b/atom/browser/relauncher_win.cc @@ -65,11 +65,10 @@ void RelauncherSynchronizeWithParent() { } int LaunchProgram(const StringVector& relauncher_args, - const StringType& program, - const StringVector& args) { + const StringVector& argv) { base::LaunchOptions options; - base::Process process = base::LaunchProcess( - program + L" " + base::JoinString(args, L" "), options); + base::Process process = + base::LaunchProcess(base::JoinString(args, L" "), options); return process.IsValid() ? 0 : 1; }