| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 | 7 |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <sys/wait.h> | 9 #include <sys/wait.h> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "native_client/src/shared/platform/nacl_exit.h" | 23 #include "native_client/src/shared/platform/nacl_exit.h" |
| 24 #include "native_client/src/shared/platform/nacl_log.h" | 24 #include "native_client/src/shared/platform/nacl_log.h" |
| 25 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 25 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
| 26 #include "native_client/src/trusted/desc/nacl_desc_base.h" | 26 #include "native_client/src/trusted/desc/nacl_desc_base.h" |
| 27 | 27 |
| 28 | 28 |
| 29 using std::vector; | 29 using std::vector; |
| 30 | 30 |
| 31 namespace nacl { | 31 namespace nacl { |
| 32 | 32 |
| 33 SelLdrLauncher::~SelLdrLauncher() { | 33 SelLdrLauncherStandalone::~SelLdrLauncherStandalone() { |
| 34 CloseHandlesAfterLaunch(); | 34 CloseHandlesAfterLaunch(); |
| 35 #if defined(NACL_STANDALONE) | |
| 36 if (kInvalidHandle != child_process_) { | 35 if (kInvalidHandle != child_process_) { |
| 37 int status; | 36 int status; |
| 38 // Ensure child process (service runtime) is kaput. NB: we might | 37 // Ensure child process (service runtime) is kaput. NB: we might |
| 39 // close the command channel (or use the hard_shutdown RPC) rather | 38 // close the command channel (or use the hard_shutdown RPC) rather |
| 40 // than killing the process to allow the service runtime to do | 39 // than killing the process to allow the service runtime to do |
| 41 // clean up, but the plugin should be responsible for that and we | 40 // clean up, but the plugin should be responsible for that and we |
| 42 // shouldn't introduce any timeout wait in a dtor. Currently, | 41 // shouldn't introduce any timeout wait in a dtor. Currently, |
| 43 // ServiceRuntime::Shutdown kills the subprocess before closing | 42 // ServiceRuntime::Shutdown kills the subprocess before closing |
| 44 // the command channel, so we aren't providing the opportunity for | 43 // the command channel, so we aren't providing the opportunity for |
| 45 // a more graceful shutdown. | 44 // a more graceful shutdown. |
| 46 KillChildProcess(); | 45 KillChildProcess(); |
| 47 waitpid(child_process_, &status, 0); | 46 waitpid(child_process_, &status, 0); |
| 48 } | 47 } |
| 49 #endif | |
| 50 if (kInvalidHandle != channel_) { | |
| 51 Close(channel_); | |
| 52 } | |
| 53 } | 48 } |
| 54 | 49 |
| 55 | 50 |
| 56 nacl::string SelLdrLauncher::GetSelLdrPathName() { | 51 nacl::string SelLdrLauncherStandalone::GetSelLdrPathName() { |
| 57 char buffer[FILENAME_MAX]; | 52 char buffer[FILENAME_MAX]; |
| 58 GetPluginDirectory(buffer, sizeof(buffer)); | 53 GetPluginDirectory(buffer, sizeof(buffer)); |
| 59 return nacl::string(buffer) + "/sel_ldr"; | 54 return nacl::string(buffer) + "/sel_ldr"; |
| 60 } | 55 } |
| 61 | 56 |
| 62 nacl::string SelLdrLauncher::GetSelLdrBootstrapPathName() { | 57 nacl::string SelLdrLauncherStandalone::GetSelLdrBootstrapPathName() { |
| 63 #if NACL_LINUX | 58 #if NACL_LINUX |
| 64 char buffer[FILENAME_MAX]; | 59 char buffer[FILENAME_MAX]; |
| 65 GetPluginDirectory(buffer, sizeof(buffer)); | 60 GetPluginDirectory(buffer, sizeof(buffer)); |
| 66 return nacl::string(buffer) + "/nacl_helper_bootstrap"; | 61 return nacl::string(buffer) + "/nacl_helper_bootstrap"; |
| 67 #else | 62 #else |
| 68 return nacl::string(NACL_NO_FILE_PATH); | 63 return nacl::string(NACL_NO_FILE_PATH); |
| 69 #endif | 64 #endif |
| 70 } | 65 } |
| 71 | 66 |
| 72 Handle SelLdrLauncher::CreateBootstrapSocket(nacl::string* dest_fd) { | 67 Handle SelLdrLauncherStandalone::CreateBootstrapSocket(nacl::string* dest_fd) { |
| 73 Handle pair[2]; | 68 Handle pair[2]; |
| 74 if (SocketPair(pair) == -1) { | 69 if (SocketPair(pair) == -1) { |
| 75 return kInvalidHandle; | 70 return kInvalidHandle; |
| 76 } | 71 } |
| 77 | 72 |
| 78 int rc = fcntl(pair[0], F_SETFD, FD_CLOEXEC); | 73 int rc = fcntl(pair[0], F_SETFD, FD_CLOEXEC); |
| 79 CHECK(rc == 0); | 74 CHECK(rc == 0); |
| 80 close_after_launch_.push_back(pair[1]); | 75 close_after_launch_.push_back(pair[1]); |
| 81 | 76 |
| 82 *dest_fd = ToString(pair[1]); | 77 *dest_fd = ToString(pair[1]); |
| 83 return pair[0]; | 78 return pair[0]; |
| 84 } | 79 } |
| 85 | 80 |
| 86 const size_t kMaxExecArgs = 64; | 81 const size_t kMaxExecArgs = 64; |
| 87 | 82 |
| 88 #if defined(NACL_STANDALONE) | 83 bool SelLdrLauncherStandalone::StartViaCommandLine( |
| 89 bool SelLdrLauncher::StartViaCommandLine( | |
| 90 const vector<nacl::string>& prefix, | 84 const vector<nacl::string>& prefix, |
| 91 const vector<nacl::string>& sel_ldr_argv, | 85 const vector<nacl::string>& sel_ldr_argv, |
| 92 const vector<nacl::string>& app_argv) { | 86 const vector<nacl::string>& app_argv) { |
| 93 // Set up the command line. | 87 // Set up the command line. |
| 94 InitCommandLine(prefix, sel_ldr_argv, app_argv); | 88 InitCommandLine(prefix, sel_ldr_argv, app_argv); |
| 95 // complete command line setup | 89 // complete command line setup |
| 96 vector<nacl::string> command; | 90 vector<nacl::string> command; |
| 97 BuildCommandLine(&command); | 91 BuildCommandLine(&command); |
| 98 if (kMaxExecArgs <= command.size()) { | 92 if (kMaxExecArgs <= command.size()) { |
| 99 // TODO(robertm): emit error message | 93 // TODO(robertm): emit error message |
| (...skipping 22 matching lines...) Expand all Loading... |
| 122 NaClLog(LOG_ERROR, "execv failed, args were:\n"); | 116 NaClLog(LOG_ERROR, "execv failed, args were:\n"); |
| 123 for (size_t i = 0; i < command.size(); ++i) { | 117 for (size_t i = 0; i < command.size(); ++i) { |
| 124 NaClLog(LOG_ERROR, "%s\n", argv[i]); | 118 NaClLog(LOG_ERROR, "%s\n", argv[i]); |
| 125 } | 119 } |
| 126 perror("execv"); | 120 perror("execv"); |
| 127 NaClExit(EXIT_FAILURE); | 121 NaClExit(EXIT_FAILURE); |
| 128 } | 122 } |
| 129 CloseHandlesAfterLaunch(); | 123 CloseHandlesAfterLaunch(); |
| 130 return true; | 124 return true; |
| 131 } | 125 } |
| 132 #endif | |
| 133 | 126 |
| 134 bool SelLdrLauncher::KillChildProcess() { | 127 bool SelLdrLauncherStandalone::KillChildProcess() { |
| 135 #if defined(NACL_STANDALONE) | |
| 136 if (kInvalidHandle == child_process_) { | 128 if (kInvalidHandle == child_process_) { |
| 137 // It is incorrect to use the kill syscall on kInvalidHandle as | 129 // It is incorrect to use the kill syscall on kInvalidHandle as |
| 138 // the pid, since using -1 as pid is defined by POSIX.1-2001 to | 130 // the pid, since using -1 as pid is defined by POSIX.1-2001 to |
| 139 // send the signal (SIGKILL) to every process that the calling | 131 // send the signal (SIGKILL) to every process that the calling |
| 140 // process may send signals to (except for init), which is | 132 // process may send signals to (except for init), which is |
| 141 // Definitely Not What Was Intended for this. | 133 // Definitely Not What Was Intended for this. |
| 142 return true; | 134 return true; |
| 143 } | 135 } |
| 144 return 0 == kill(child_process_, SIGKILL); | 136 return 0 == kill(child_process_, SIGKILL); |
| 145 // We cannot set child_process_ to kInvalidHandle since we will want to wait | 137 // We cannot set child_process_ to kInvalidHandle since we will want to wait |
| 146 // on its exit status. | 138 // on its exit status. |
| 147 #else | |
| 148 return false; | |
| 149 #endif | |
| 150 } | 139 } |
| 151 | 140 |
| 152 } // namespace nacl | 141 } // namespace nacl |
| OLD | NEW |