Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/process.h" | 5 #include "bin/process.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 while (current != NULL) { | 45 while (current != NULL) { |
| 46 if (current->pid() == pid) { | 46 if (current->pid() == pid) { |
| 47 return current; | 47 return current; |
| 48 } | 48 } |
| 49 current = current->next(); | 49 current = current->next(); |
| 50 } | 50 } |
| 51 return NULL; | 51 return NULL; |
| 52 } | 52 } |
| 53 | 53 |
| 54 | 54 |
| 55 static ProcessInfo* RemoveProcess(pid_t pid) { | 55 static void RemoveProcess(pid_t pid) { |
| 56 ProcessInfo* prev = NULL; | 56 ProcessInfo* prev = NULL; |
| 57 ProcessInfo* current = active_processes; | 57 ProcessInfo* current = active_processes; |
| 58 while (current != NULL) { | 58 while (current != NULL) { |
| 59 if (current->pid() == pid) { | 59 if (current->pid() == pid) { |
| 60 if (prev == NULL) { | 60 if (prev == NULL) { |
| 61 active_processes = current->next(); | 61 active_processes = current->next(); |
| 62 } else { | 62 } else { |
| 63 prev->set_next(current->next()); | 63 prev->set_next(current->next()); |
| 64 } | 64 } |
| 65 return current; | 65 delete current; |
| 66 return; | |
| 66 } | 67 } |
| 67 prev = current; | 68 prev = current; |
| 68 current = current->next(); | 69 current = current->next(); |
| 69 } | 70 } |
| 70 return NULL; | |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 static char* SafeStrNCpy(char* dest, const char* src, size_t n) { | 74 static char* SafeStrNCpy(char* dest, const char* src, size_t n) { |
| 75 strncpy(dest, src, n); | 75 strncpy(dest, src, n); |
| 76 dest[n - 1] = '\0'; | 76 dest[n - 1] = '\0'; |
| 77 return dest; | 77 return dest; |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 if (bytes_read != sizeof(msg)) { | 223 if (bytes_read != sizeof(msg)) { |
| 224 perror("Failed receiving notification message"); | 224 perror("Failed receiving notification message"); |
| 225 exit(1); | 225 exit(1); |
| 226 } | 226 } |
| 227 | 227 |
| 228 close(write_out[1]); | 228 close(write_out[1]); |
| 229 close(read_in[0]); | 229 close(read_in[0]); |
| 230 close(read_err[0]); | 230 close(read_err[0]); |
| 231 close(exec_control[0]); | 231 close(exec_control[0]); |
| 232 | 232 |
| 233 dup2(write_out[0], STDIN_FILENO); | 233 if (dup2(write_out[0], STDIN_FILENO) == -1) { |
|
Søren Gjesse
2011/11/29 09:39:25
Ditto.
Mads Ager (google)
2011/11/29 10:10:13
Done.
| |
| 234 perror("Failed to dup stdin"); | |
| 235 } | |
| 234 close(write_out[0]); | 236 close(write_out[0]); |
| 235 | 237 |
| 236 dup2(read_in[1], STDOUT_FILENO); | 238 if (dup2(read_in[1], STDOUT_FILENO) == -1) { |
| 239 perror("Failed to dup stdout"); | |
| 240 } | |
| 237 close(read_in[1]); | 241 close(read_in[1]); |
| 238 | 242 |
| 239 dup2(read_err[1], STDERR_FILENO); | 243 if (dup2(read_err[1], STDERR_FILENO) == -1) { |
| 244 perror("Failed to dup stderr"); | |
| 245 } | |
| 240 close(read_err[1]); | 246 close(read_err[1]); |
| 241 | 247 |
| 242 execvp(path, const_cast<char* const*>(program_arguments)); | 248 execvp(path, const_cast<char* const*>(program_arguments)); |
| 243 // In the case of failure write the errno and the OS error message | 249 // In the case of failure write the errno and the OS error message |
| 244 // to the exec control pipe. | 250 // to the exec control pipe. |
| 245 int child_errno = errno; | 251 int child_errno = errno; |
| 246 char* os_error_message = strerror(errno); | 252 char* os_error_message = strerror(errno); |
| 247 ASSERT(sizeof(child_errno) == sizeof(errno)); | 253 ASSERT(sizeof(child_errno) == sizeof(errno)); |
| 248 int bytes_written = | 254 int bytes_written = |
| 249 FDUtils::WriteToBlocking( | 255 FDUtils::WriteToBlocking( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 if (result == -1) { | 344 if (result == -1) { |
| 339 return false; | 345 return false; |
| 340 } | 346 } |
| 341 return true; | 347 return true; |
| 342 } | 348 } |
| 343 | 349 |
| 344 | 350 |
| 345 void Process::Exit(intptr_t id) { | 351 void Process::Exit(intptr_t id) { |
| 346 RemoveProcess(id); | 352 RemoveProcess(id); |
| 347 } | 353 } |
| OLD | NEW |