diff options
Diffstat (limited to 'source/Host/posix/ProcessLauncherPosixFork.cpp')
| -rw-r--r-- | source/Host/posix/ProcessLauncherPosixFork.cpp | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/source/Host/posix/ProcessLauncherPosixFork.cpp b/source/Host/posix/ProcessLauncherPosixFork.cpp index ac1d9011c2b7..46ce3e3d224f 100644 --- a/source/Host/posix/ProcessLauncherPosixFork.cpp +++ b/source/Host/posix/ProcessLauncherPosixFork.cpp @@ -38,17 +38,12 @@ using namespace lldb; using namespace lldb_private; -static void FixupEnvironment(Args &env) { +static void FixupEnvironment(Environment &env) { #ifdef __ANDROID__ // If there is no PATH variable specified inside the environment then set the // path to /system/bin. It is required because the default path used by // execve() is wrong on android. - static const char *path = "PATH="; - for (auto &entry : env.entries()) { - if (entry.ref.startswith(path)) - return; - } - env.AppendArgument(llvm::StringRef("PATH=/system/bin")); + env.try_emplace("PATH", "/system/bin"); #endif } @@ -95,10 +90,6 @@ static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd, static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd, const ProcessLaunchInfo &info) { - // Do not inherit setgid powers. - if (setgid(getgid()) != 0) - ExitWithError(error_fd, "setgid"); - if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) { if (setpgid(0, 0) != 0) ExitWithError(error_fd, "setpgid"); @@ -132,23 +123,26 @@ static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd, ExitWithError(error_fd, "chdir"); DisableASLRIfRequested(error_fd, info); - Args env = info.GetEnvironmentEntries(); + Environment env = info.GetEnvironment(); FixupEnvironment(env); - const char **envp = env.GetConstArgumentVector(); + Environment::Envp envp = env.getEnvp(); - // Clear the signal mask to prevent the child from being affected by - // any masking done by the parent. + // Clear the signal mask to prevent the child from being affected by any + // masking done by the parent. sigset_t set; if (sigemptyset(&set) != 0 || pthread_sigmask(SIG_SETMASK, &set, nullptr) != 0) ExitWithError(error_fd, "pthread_sigmask"); if (info.GetFlags().Test(eLaunchFlagDebug)) { + // Do not inherit setgid powers. + if (setgid(getgid()) != 0) + ExitWithError(error_fd, "setgid"); + // HACK: // Close everything besides stdin, stdout, and stderr that has no file // action to avoid leaking. Only do this when debugging, as elsewhere we - // actually rely on - // passing open descriptors to child processes. + // actually rely on passing open descriptors to child processes. for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd) if (!info.GetFileActionForFD(fd) && fd != error_fd) close(fd); @@ -159,26 +153,20 @@ static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd, } // Execute. We should never return... - execve(argv[0], const_cast<char *const *>(argv), - const_cast<char *const *>(envp)); + execve(argv[0], const_cast<char *const *>(argv), envp); #if defined(__linux__) if (errno == ETXTBSY) { - // On android M and earlier we can get this error because the adb deamon can - // hold a write - // handle on the executable even after it has finished uploading it. This - // state lasts - // only a short time and happens only when there are many concurrent adb - // commands being - // issued, such as when running the test suite. (The file remains open when - // someone does - // an "adb shell" command in the fork() child before it has had a chance to - // exec.) Since - // this state should clear up quickly, wait a while and then give it one - // more go. + // On android M and earlier we can get this error because the adb deamon + // can hold a write handle on the executable even after it has finished + // uploading it. This state lasts only a short time and happens only when + // there are many concurrent adb commands being issued, such as when + // running the test suite. (The file remains open when someone does an "adb + // shell" command in the fork() child before it has had a chance to exec.) + // Since this state should clear up quickly, wait a while and then give it + // one more go. usleep(50000); - execve(argv[0], const_cast<char *const *>(argv), - const_cast<char *const *>(envp)); + execve(argv[0], const_cast<char *const *>(argv), envp); } #endif |
