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

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

Issue 9193014: Save and restore errno in signal handler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add Windows binary so base version is the same. 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 | « no previous file | runtime/bin/process_macos.cc » ('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) 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 static void SetChildOsErrorMessage(char* os_error_message, 82 static void SetChildOsErrorMessage(char* os_error_message,
83 int os_error_message_len) { 83 int os_error_message_len) {
84 SafeStrNCpy(os_error_message, strerror(errno), os_error_message_len); 84 SafeStrNCpy(os_error_message, strerror(errno), os_error_message_len);
85 } 85 }
86 86
87 87
88 void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) { 88 void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) {
89 int pid = 0; 89 int pid = 0;
90 int status = 0; 90 int status = 0;
91 // Save errno so it can be restored at the end.
92 int entry_errno = errno;
91 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) { 93 while ((pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, WNOHANG))) > 0) {
92 int exit_code = 0; 94 int exit_code = 0;
93 int negative = 0; 95 int negative = 0;
94 if (WIFEXITED(status)) { 96 if (WIFEXITED(status)) {
95 exit_code = WEXITSTATUS(status); 97 exit_code = WEXITSTATUS(status);
96 } 98 }
97 if (WIFSIGNALED(status)) { 99 if (WIFSIGNALED(status)) {
98 exit_code = WTERMSIG(status); 100 exit_code = WTERMSIG(status);
99 negative = 1; 101 negative = 1;
100 } 102 }
101 ProcessInfo* process = LookupProcess(pid); 103 ProcessInfo* process = LookupProcess(pid);
102 if (process != NULL) { 104 if (process != NULL) {
103 int message[3] = { pid, exit_code, negative }; 105 int message[3] = { pid, exit_code, negative };
104 intptr_t result = 106 intptr_t result =
105 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); 107 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message));
106 if (result != sizeof(message) && errno != EPIPE) { 108 if (result != sizeof(message) && errno != EPIPE) {
107 perror("ExitHandler notification failed"); 109 perror("ExitHandler notification failed");
108 } 110 }
109 TEMP_FAILURE_RETRY(close(process->fd())); 111 TEMP_FAILURE_RETRY(close(process->fd()));
110 } 112 }
111 } 113 }
114 errno = entry_errno;
112 } 115 }
113 116
114 117
115 static void ReportChildError(int exec_control_fd) { 118 static void ReportChildError(int exec_control_fd) {
116 // In the case of failure in the child process write the errno and 119 // In the case of failure in the child process write the errno and
117 // the OS error message to the exec control pipe and exit. 120 // the OS error message to the exec control pipe and exit.
118 int child_errno = errno; 121 int child_errno = errno;
119 char* os_error_message = strerror(errno); 122 char* os_error_message = strerror(errno);
120 ASSERT(sizeof(child_errno) == sizeof(errno)); 123 ASSERT(sizeof(child_errno) == sizeof(errno));
121 int bytes_written = 124 int bytes_written =
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (result == -1) { 358 if (result == -1) {
356 return false; 359 return false;
357 } 360 }
358 return true; 361 return true;
359 } 362 }
360 363
361 364
362 void Process::Exit(intptr_t id) { 365 void Process::Exit(intptr_t id) {
363 RemoveProcess(id); 366 RemoveProcess(id);
364 } 367 }
OLDNEW
« 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