| 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" |
| 6 |
| 5 #include <errno.h> | 7 #include <errno.h> |
| 6 #include <fcntl.h> | 8 #include <fcntl.h> |
| 7 #include <signal.h> | 9 #include <signal.h> |
| 8 #include <stdio.h> | 10 #include <stdio.h> |
| 9 #include <stdlib.h> | 11 #include <stdlib.h> |
| 10 #include <string.h> | 12 #include <string.h> |
| 11 #include <unistd.h> | 13 #include <unistd.h> |
| 12 | 14 |
| 13 #include "bin/fdutils.h" | 15 #include "bin/fdutils.h" |
| 14 #include "bin/process.h" | |
| 15 #include "bin/set.h" | |
| 16 | 16 |
| 17 | 17 |
| 18 class ProcessInfo { | 18 class ProcessInfo { |
| 19 public: | 19 public: |
| 20 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } | 20 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } |
| 21 | 21 |
| 22 pid_t pid() { return pid_; } | 22 pid_t pid() { return pid_; } |
| 23 intptr_t fd() { return fd_; } | 23 intptr_t fd() { return fd_; } |
| 24 ProcessInfo* next() { return next_; } | 24 ProcessInfo* next() { return next_; } |
| 25 void set_next(ProcessInfo* next) { next_ = next; } | 25 void set_next(ProcessInfo* next) { next_ = next; } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ASSERT(process_signal == SIGCHLD); | 88 ASSERT(process_signal == SIGCHLD); |
| 89 struct sigaction act; | 89 struct sigaction act; |
| 90 bzero(&act, sizeof(act)); | 90 bzero(&act, sizeof(act)); |
| 91 act.sa_handler = SIG_IGN; | 91 act.sa_handler = SIG_IGN; |
| 92 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO; | 92 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO; |
| 93 if (sigaction(SIGCHLD, &act, 0) != 0) { | 93 if (sigaction(SIGCHLD, &act, 0) != 0) { |
| 94 perror("Process start: disabling signal handler failed"); | 94 perror("Process start: disabling signal handler failed"); |
| 95 } | 95 } |
| 96 ProcessInfo* process = LookupProcess(siginfo->si_pid); | 96 ProcessInfo* process = LookupProcess(siginfo->si_pid); |
| 97 if (process != NULL) { | 97 if (process != NULL) { |
| 98 int status = 0; |
| 99 int wait_result = waitpid(siginfo->si_pid, &status, WNOHANG); |
| 100 if (wait_result == -1 || wait_result == 0) { |
| 101 perror("ExitHandler waitpid failed"); |
| 102 } |
| 98 intptr_t message[2] = { siginfo->si_pid, siginfo->si_status }; | 103 intptr_t message[2] = { siginfo->si_pid, siginfo->si_status }; |
| 99 intptr_t result = | 104 intptr_t result = |
| 100 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); | 105 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); |
| 101 if (result != sizeof(message)) { | 106 if (result != sizeof(message)) { |
| 102 perror("ExitHandler notification failed"); | 107 perror("ExitHandler notification failed"); |
| 103 } | 108 } |
| 104 close(process->fd()); | 109 close(process->fd()); |
| 105 } | 110 } |
| 106 act.sa_handler = 0; | 111 act.sa_handler = 0; |
| 107 act.sa_sigaction = ExitHandler; | 112 act.sa_sigaction = ExitHandler; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if (result == -1) { | 335 if (result == -1) { |
| 331 return false; | 336 return false; |
| 332 } | 337 } |
| 333 return true; | 338 return true; |
| 334 } | 339 } |
| 335 | 340 |
| 336 | 341 |
| 337 void Process::Exit(intptr_t id) { | 342 void Process::Exit(intptr_t id) { |
| 338 RemoveProcess(id); | 343 RemoveProcess(id); |
| 339 } | 344 } |
| OLD | NEW |