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

Side by Side Diff: runtime/bin/process_macos.cc

Issue 9225019: Fix race condition between signal handler and main thread. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 months 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') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) { 92 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) {
93 int exit_code = 0; 93 int exit_code = 0;
94 int negative = 0; 94 int negative = 0;
95 if (WIFEXITED(status)) { 95 if (WIFEXITED(status)) {
96 exit_code = WEXITSTATUS(status); 96 exit_code = WEXITSTATUS(status);
97 } 97 }
98 if (WIFSIGNALED(status)) { 98 if (WIFSIGNALED(status)) {
99 exit_code = WTERMSIG(status); 99 exit_code = WTERMSIG(status);
100 negative = 1; 100 negative = 1;
101 } 101 }
102 // Lookup the process and extract all needed information from
103 // it. The WriteToBlocking call below can cause the deletion of
104 // the process object (because this signal handler can be running
105 // on an arbitrary thread, not just the main thread) so we cannot
106 // touch it after that call.
102 ProcessInfo* process = LookupProcess(pid); 107 ProcessInfo* process = LookupProcess(pid);
108 intptr_t exit_code_fd = process->fd();
103 if (process != NULL) { 109 if (process != NULL) {
104 int message[3] = { pid, exit_code, negative }; 110 int message[3] = { pid, exit_code, negative };
105 intptr_t result = 111 intptr_t result =
106 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); 112 FDUtils::WriteToBlocking(exit_code_fd, &message, sizeof(message));
107 if (result != sizeof(message) && errno != EPIPE) { 113 if (result != sizeof(message) && errno != EPIPE) {
108 perror("ExitHandler notification failed"); 114 perror("ExitHandler notification failed");
109 } 115 }
110 TEMP_FAILURE_RETRY(close(process->fd())); 116 TEMP_FAILURE_RETRY(close(exit_code_fd));
111 } 117 }
112 } 118 }
113 errno = entry_errno; 119 errno = entry_errno;
114 } 120 }
115 121
116 122
117 static void ReportChildError(int exec_control_fd) { 123 static void ReportChildError(int exec_control_fd) {
118 // In the case of failure in the child process write the errno and 124 // In the case of failure in the child process write the errno and
119 // the OS error message to the exec control pipe and exit. 125 // the OS error message to the exec control pipe and exit.
120 int child_errno = errno; 126 int child_errno = errno;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 if (result == -1) { 363 if (result == -1) {
358 return false; 364 return false;
359 } 365 }
360 return true; 366 return true;
361 } 367 }
362 368
363 369
364 void Process::Exit(intptr_t id) { 370 void Process::Exit(intptr_t id) {
365 RemoveProcess(id); 371 RemoveProcess(id);
366 } 372 }
OLDNEW
« no previous file with comments | « runtime/bin/process_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698