OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 | 27 |
28 using std::vector; | 28 using std::vector; |
29 | 29 |
30 namespace nacl { | 30 namespace nacl { |
31 | 31 |
32 SelLdrLauncher::~SelLdrLauncher() { | 32 SelLdrLauncher::~SelLdrLauncher() { |
33 CloseHandlesAfterLaunch(); | 33 CloseHandlesAfterLaunch(); |
34 if (kInvalidHandle != child_process_) { | 34 if (kInvalidHandle != child_process_) { |
35 int status; | 35 int status; |
| 36 // Ensure child process (service runtime) is kaput. NB: we might |
| 37 // close the command channel (or use the hard_shutdown RPC) rather |
| 38 // than killing the process to allow the service runtime to do |
| 39 // clean up, but the plugin should be responsible for that and we |
| 40 // shouldn't introduce any timeout wait in a dtor. Currently, |
| 41 // ServiceRuntime::Shutdown kills the subprocess before closing |
| 42 // the command channel, so we aren't providing the opportunity for |
| 43 // a more graceful shutdown. |
| 44 KillChildProcess(); |
36 waitpid(child_process_, &status, 0); | 45 waitpid(child_process_, &status, 0); |
37 } | 46 } |
38 if (kInvalidHandle != channel_) { | 47 if (kInvalidHandle != channel_) { |
39 Close(channel_); | 48 Close(channel_); |
40 } | 49 } |
41 } | 50 } |
42 | 51 |
43 | 52 |
44 nacl::string SelLdrLauncher::GetSelLdrPathName() { | 53 nacl::string SelLdrLauncher::GetSelLdrPathName() { |
45 char buffer[FILENAME_MAX]; | 54 char buffer[FILENAME_MAX]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 NaClLog(LOG_ERROR, "%s\n", argv[i]); | 114 NaClLog(LOG_ERROR, "%s\n", argv[i]); |
106 } | 115 } |
107 perror("execv"); | 116 perror("execv"); |
108 NaClExit(EXIT_FAILURE); | 117 NaClExit(EXIT_FAILURE); |
109 } | 118 } |
110 CloseHandlesAfterLaunch(); | 119 CloseHandlesAfterLaunch(); |
111 return true; | 120 return true; |
112 } | 121 } |
113 | 122 |
114 bool SelLdrLauncher::KillChildProcess() { | 123 bool SelLdrLauncher::KillChildProcess() { |
| 124 if (kInvalidHandle == child_process_) { |
| 125 // It is incorrect to use the kill syscall on kInvalidHandle as |
| 126 // the pid, since using -1 as pid is defined by POSIX.1-2001 to |
| 127 // send the signal (SIGKILL) to every process that the calling |
| 128 // process may send signals to (except for init), which is |
| 129 // Definitely Not What Was Intended for this. |
| 130 return true; |
| 131 } |
115 return 0 == kill(child_process_, SIGKILL); | 132 return 0 == kill(child_process_, SIGKILL); |
116 // We cannot set child_process_ to kInvalidHandle since we will want to wait | 133 // We cannot set child_process_ to kInvalidHandle since we will want to wait |
117 // on its exit status. | 134 // on its exit status. |
118 } | 135 } |
119 | 136 |
120 } // namespace nacl | 137 } // namespace nacl |
OLD | NEW |