Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Unified Diff: runtime/bin/process_linux.cc

Issue 8506010: Simplify SIGCLD handler on linux and mac. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/process_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_linux.cc
diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc
index 114dcd184e8ccea3690fcf228142bb1043bef80c..26bd8556e8da3635acaa30a97b7a57321e23eed1 100644
--- a/runtime/bin/process_linux.cc
+++ b/runtime/bin/process_linux.cc
@@ -85,33 +85,25 @@ static void SetChildOsErrorMessage(char* os_error_message,
void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) {
- ASSERT(process_signal == SIGCHLD);
- struct sigaction act;
- bzero(&act, sizeof(act));
- act.sa_handler = SIG_IGN;
- act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
- if (sigaction(SIGCHLD, &act, 0) != 0) {
- perror("Process start: disabling signal handler failed");
- }
- ProcessInfo* process = LookupProcess(siginfo->si_pid);
- if (process != NULL) {
- int status = 0;
- int wait_result = waitpid(siginfo->si_pid, &status, WNOHANG);
- if (wait_result == -1 || wait_result == 0) {
- perror("ExitHandler waitpid failed");
- }
- intptr_t message[2] = { siginfo->si_pid, siginfo->si_status };
- intptr_t result =
- FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message));
- if (result != sizeof(message)) {
- perror("ExitHandler notification failed");
+ int pid = 0;
+ int status = 0;
+ while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
+ int exit_code = 0;
+ // TODO(ager): Transform exit_code 255 to -1.
+ if (WIFEXITED(status)) exit_code = WEXITSTATUS(status);
+ // TODO(ager): Transform termsig to -termsig to destinguish from
+ // exit codes.
+ if (WIFSIGNALED(status)) exit_code = WTERMSIG(status);
+ ProcessInfo* process = LookupProcess(pid);
+ if (process != NULL) {
+ intptr_t message[2] = { pid, exit_code };
+ intptr_t result =
+ FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message));
+ if (result != sizeof(message)) {
+ perror("ExitHandler notification failed");
+ }
+ close(process->fd());
}
- close(process->fd());
- }
- act.sa_handler = 0;
- act.sa_sigaction = ExitHandler;
- if (sigaction(SIGCHLD, &act, 0) != 0) {
- perror("Process start: enabling signal handler failed");
}
}
« no previous file with comments | « no previous file | runtime/bin/process_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698