Separate LaunchProgram from mac implementation
This commit is contained in:
parent
060829da64
commit
c3fe2dae9d
4 changed files with 77 additions and 55 deletions
|
@ -153,7 +153,7 @@ int AtomMainDelegate::RunProcess(
|
||||||
const std::string& process_type,
|
const std::string& process_type,
|
||||||
const content::MainFunctionParams& main_function_params) {
|
const content::MainFunctionParams& main_function_params) {
|
||||||
if (process_type == kRelauncherProcess)
|
if (process_type == kRelauncherProcess)
|
||||||
return relauncher::internal::RelauncherMain(main_function_params);
|
return relauncher::RelauncherMain(main_function_params);
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom/common/atom_command_line.h"
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
|
@ -115,4 +116,61 @@ bool RelaunchAppWithHelper(const std::string& helper,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
||||||
|
const std::vector<std::string>& argv = atom::AtomCommandLine::argv();
|
||||||
|
|
||||||
|
if (argv.size() < 4 || argv[1] != internal::kRelauncherTypeArg) {
|
||||||
|
LOG(ERROR) << "relauncher process invoked with unexpected arguments";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal::RelauncherSynchronizeWithParent();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
std::string relaunch_executable;
|
||||||
|
std::vector<std::string> relauncher_args;
|
||||||
|
std::vector<std::string> launch_args;
|
||||||
|
for (size_t argv_index = 2; argv_index < argv.size(); ++argv_index) {
|
||||||
|
const std::string& arg(argv[argv_index]);
|
||||||
|
if (!in_relaunch_args) {
|
||||||
|
if (arg == internal::kRelauncherArgSeparator) {
|
||||||
|
in_relaunch_args = true;
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!seen_relaunch_executable) {
|
||||||
|
LOG(ERROR) << "nothing to relaunch";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (internal::LaunchProgram(relauncher_args, relaunch_executable,
|
||||||
|
launch_args) != 0) {
|
||||||
|
LOG(ERROR) << "failed to launch program";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The application should have relaunched (or is in the process of
|
||||||
|
// relaunching). From this point on, only clean-up tasks should occur, and
|
||||||
|
// failures are tolerable.
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace relauncher
|
} // namespace relauncher
|
||||||
|
|
|
@ -64,6 +64,9 @@ bool RelaunchAppWithHelper(const std::string& helper,
|
||||||
const std::vector<std::string>& relauncher_args,
|
const std::vector<std::string>& relauncher_args,
|
||||||
const std::vector<std::string>& args);
|
const std::vector<std::string>& args);
|
||||||
|
|
||||||
|
// The entry point from ChromeMain into the relauncher process.
|
||||||
|
int RelauncherMain(const content::MainFunctionParams& main_parameters);
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// The "magic" file descriptor that the relauncher process' write side of the
|
// The "magic" file descriptor that the relauncher process' write side of the
|
||||||
|
@ -91,8 +94,9 @@ extern const char* kRelauncherArgSeparator;
|
||||||
// process and the best recovery approach is to attempt relaunch anyway.
|
// process and the best recovery approach is to attempt relaunch anyway.
|
||||||
void RelauncherSynchronizeWithParent();
|
void RelauncherSynchronizeWithParent();
|
||||||
|
|
||||||
// The entry point from ChromeMain into the relauncher process.
|
int LaunchProgram(const std::vector<std::string>& relauncher_args,
|
||||||
int RelauncherMain(const content::MainFunctionParams& main_parameters);
|
const std::string& program,
|
||||||
|
const std::vector<std::string>& argv);
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "atom/common/atom_command_line.h"
|
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/mac/mac_logging.h"
|
#include "base/mac/mac_logging.h"
|
||||||
|
@ -91,16 +90,9 @@ void RelauncherSynchronizeWithParent() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
int LaunchProgram(const std::vector<std::string>& relauncher_args,
|
||||||
const std::vector<std::string>& argv = atom::AtomCommandLine::argv();
|
const std::string& program,
|
||||||
|
const std::vector<std::string>& argv) {
|
||||||
if (argv.size() < 4 || kRelauncherTypeArg != argv[1]) {
|
|
||||||
LOG(ERROR) << "relauncher process invoked with unexpected arguments";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal::RelauncherSynchronizeWithParent();
|
|
||||||
|
|
||||||
// The capacity for relaunch_args is 4 less than argc, because it
|
// The capacity for relaunch_args is 4 less than argc, because it
|
||||||
// won't contain the argv[0] of the relauncher process, the
|
// won't contain the argv[0] of the relauncher process, the
|
||||||
// RelauncherTypeArg() at argv[1], kRelauncherArgSeparator, or the
|
// RelauncherTypeArg() at argv[1], kRelauncherArgSeparator, or the
|
||||||
|
@ -112,50 +104,22 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out what to execute, what arguments to pass it, and whether to
|
for (const std::string& arg : argv) {
|
||||||
// start it in the background.
|
|
||||||
bool in_relaunch_args = false;
|
|
||||||
bool seen_relaunch_executable = false;
|
|
||||||
std::string relaunch_executable;
|
|
||||||
const std::string relauncher_arg_separator(kRelauncherArgSeparator);
|
|
||||||
for (size_t argv_index = 2; argv_index < argv.size(); ++argv_index) {
|
|
||||||
const std::string& arg(argv[argv_index]);
|
|
||||||
|
|
||||||
// Strip any -psn_ arguments, as they apply to a specific process.
|
// Strip any -psn_ arguments, as they apply to a specific process.
|
||||||
if (arg.compare(0, strlen(kPSNArg), kPSNArg) == 0) {
|
if (arg.compare(0, strlen(kPSNArg), kPSNArg) == 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_relaunch_args && arg == relauncher_arg_separator) {
|
base::ScopedCFTypeRef<CFStringRef> arg_cf(base::SysUTF8ToCFStringRef(arg));
|
||||||
in_relaunch_args = true;
|
if (!arg_cf) {
|
||||||
} else {
|
LOG(ERROR) << "base::SysUTF8ToCFStringRef failed for " << arg;
|
||||||
if (!seen_relaunch_executable) {
|
return 1;
|
||||||
// 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 {
|
|
||||||
base::ScopedCFTypeRef<CFStringRef> arg_cf(
|
|
||||||
base::SysUTF8ToCFStringRef(arg));
|
|
||||||
if (!arg_cf) {
|
|
||||||
LOG(ERROR) << "base::SysUTF8ToCFStringRef failed for " << arg;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
CFArrayAppendValue(relaunch_args, arg_cf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
CFArrayAppendValue(relaunch_args, arg_cf);
|
||||||
|
|
||||||
if (!seen_relaunch_executable) {
|
|
||||||
LOG(ERROR) << "nothing to relaunch";
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FSRef app_fsref;
|
FSRef app_fsref;
|
||||||
if (!base::mac::FSRefFromPath(relaunch_executable, &app_fsref)) {
|
if (!base::mac::FSRefFromPath(program, &app_fsref)) {
|
||||||
LOG(ERROR) << "base::mac::FSRefFromPath failed for " << relaunch_executable;
|
LOG(ERROR) << "base::mac::FSRefFromPath failed for " << program;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,10 +139,6 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The application should have relaunched (or is in the process of
|
|
||||||
// relaunching). From this point on, only clean-up tasks should occur, and
|
|
||||||
// failures are tolerable.
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue