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

Side by Side Diff: runtime/bin/process_macos.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/process_linux.cc ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 80
81 static void SetChildOsErrorMessage(char* os_error_message, 81 static void SetChildOsErrorMessage(char* os_error_message,
82 int os_error_message_len) { 82 int os_error_message_len) {
83 SafeStrNCpy(os_error_message, strerror(errno), os_error_message_len); 83 SafeStrNCpy(os_error_message, strerror(errno), os_error_message_len);
84 } 84 }
85 85
86 86
87 void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) { 87 void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) {
88 ASSERT(process_signal == SIGCHLD); 88 int pid = 0;
89 struct sigaction act; 89 int status = 0;
90 bzero(&act, sizeof(act)); 90 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
91 act.sa_handler = SIG_IGN; 91 int exit_code = 0;
92 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO; 92 // TODO(ager): Transform exit_code 255 to -1.
93 if (sigaction(SIGCHLD, &act, 0) != 0) { 93 if (WIFEXITED(status)) exit_code = WEXITSTATUS(status);
94 perror("Process start: disabling signal handler failed"); 94 // TODO(ager): Transform termsig to -termsig to destinguish from
95 } 95 // exit codes.
96 ProcessInfo* process = LookupProcess(siginfo->si_pid); 96 if (WIFSIGNALED(status)) exit_code = WTERMSIG(status);
97 if (process != NULL) { 97 ProcessInfo* process = LookupProcess(pid);
98 int status = 0; 98 if (process != NULL) {
99 int wait_result = waitpid(siginfo->si_pid, &status, WNOHANG); 99 intptr_t message[2] = { pid, exit_code };
100 if (wait_result == -1 || wait_result == 0) { 100 intptr_t result =
101 perror("ExitHandler waitpid failed"); 101 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message));
102 if (result != sizeof(message)) {
103 perror("ExitHandler notification failed");
104 }
105 close(process->fd());
102 } 106 }
103 intptr_t message[2] = { siginfo->si_pid, siginfo->si_status };
104 intptr_t result =
105 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message));
106 if (result != sizeof(message)) {
107 perror("ExitHandler notification failed");
108 }
109 close(process->fd());
110 }
111 act.sa_handler = 0;
112 act.sa_sigaction = ExitHandler;
113 if (sigaction(SIGCHLD, &act, 0) != 0) {
114 perror("Process start: enabling signal handler failed");
115 } 107 }
116 } 108 }
117 109
118 110
119 int Process::Start(const char* path, 111 int Process::Start(const char* path,
120 char* arguments[], 112 char* arguments[],
121 intptr_t arguments_length, 113 intptr_t arguments_length,
122 intptr_t* in, 114 intptr_t* in,
123 intptr_t* out, 115 intptr_t* out,
124 intptr_t* err, 116 intptr_t* err,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (result == -1) { 327 if (result == -1) {
336 return false; 328 return false;
337 } 329 }
338 return true; 330 return true;
339 } 331 }
340 332
341 333
342 void Process::Exit(intptr_t id) { 334 void Process::Exit(intptr_t id) {
343 RemoveProcess(id); 335 RemoveProcess(id);
344 } 336 }
OLDNEW
« no previous file with comments | « runtime/bin/process_linux.cc ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698