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

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

Issue 165723007: Move signal_blocker to platform and use it by default in TEMP_FAILURE_RETRY. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tiny fix. Created 6 years, 9 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') | runtime/bin/signal_blocker.h » ('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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "bin/process.h" 8 #include "bin/process.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <fcntl.h> // NOLINT 11 #include <fcntl.h> // NOLINT
12 #include <poll.h> // NOLINT 12 #include <poll.h> // NOLINT
13 #include <signal.h> // NOLINT 13 #include <signal.h> // NOLINT
14 #include <stdio.h> // NOLINT 14 #include <stdio.h> // NOLINT
15 #include <stdlib.h> // NOLINT 15 #include <stdlib.h> // NOLINT
16 #include <string.h> // NOLINT 16 #include <string.h> // NOLINT
17 #include <unistd.h> // NOLINT 17 #include <unistd.h> // NOLINT
18 18
19 #include "bin/fdutils.h" 19 #include "bin/fdutils.h"
20 #include "bin/log.h" 20 #include "bin/log.h"
21 #include "bin/signal_blocker.h"
22 #include "bin/thread.h" 21 #include "bin/thread.h"
23 22
23 #include "platform/signal_blocker.h"
24
25
24 extern char **environ; 26 extern char **environ;
25 27
26 28
27 namespace dart { 29 namespace dart {
28 namespace bin { 30 namespace bin {
29 31
30 // ProcessInfo is used to map a process id to the file descriptor for 32 // ProcessInfo is used to map a process id to the file descriptor for
31 // the pipe used to communicate the exit code of the process to Dart. 33 // the pipe used to communicate the exit code of the process to Dart.
32 // ProcessInfo objects are kept in the static singly-linked 34 // ProcessInfo objects are kept in the static singly-linked
33 // ProcessInfoList. 35 // ProcessInfoList.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 145
144 if (!running_) { 146 if (!running_) {
145 return; 147 return;
146 } 148 }
147 149
148 // Set terminate_done_ to false, so we can use it as a guard for our 150 // Set terminate_done_ to false, so we can use it as a guard for our
149 // monitor. 151 // monitor.
150 running_ = false; 152 running_ = false;
151 153
152 // Fork to wake up waitpid. 154 // Fork to wake up waitpid.
153 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fork()) == 0) { 155 if (TEMP_FAILURE_RETRY(fork()) == 0) {
154 exit(0); 156 exit(0);
155 } 157 }
156 158
157 monitor_->Notify(); 159 monitor_->Notify();
158 160
159 while (!terminate_done_) { 161 while (!terminate_done_) {
160 monitor_->Wait(dart::Monitor::kNoTimeout); 162 monitor_->Wait(dart::Monitor::kNoTimeout);
161 } 163 }
162 } 164 }
163 165
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 344
343 char** program_environment = NULL; 345 char** program_environment = NULL;
344 if (environment != NULL) { 346 if (environment != NULL) {
345 program_environment = new char*[environment_length + 1]; 347 program_environment = new char*[environment_length + 1];
346 for (int i = 0; i < environment_length; i++) { 348 for (int i = 0; i < environment_length; i++) {
347 program_environment[i] = environment[i]; 349 program_environment[i] = environment[i];
348 } 350 }
349 program_environment[environment_length] = NULL; 351 program_environment[environment_length] = NULL;
350 } 352 }
351 353
352 pid = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fork()); 354 pid = TEMP_FAILURE_RETRY(fork());
353 if (pid < 0) { 355 if (pid < 0) {
354 SetChildOsErrorMessage(os_error_message); 356 SetChildOsErrorMessage(os_error_message);
355 delete[] program_arguments; 357 delete[] program_arguments;
356 VOID_TEMP_FAILURE_RETRY(close(read_in[0])); 358 VOID_TEMP_FAILURE_RETRY(close(read_in[0]));
357 VOID_TEMP_FAILURE_RETRY(close(read_in[1])); 359 VOID_TEMP_FAILURE_RETRY(close(read_in[1]));
358 VOID_TEMP_FAILURE_RETRY(close(read_err[0])); 360 VOID_TEMP_FAILURE_RETRY(close(read_err[0]));
359 VOID_TEMP_FAILURE_RETRY(close(read_err[1])); 361 VOID_TEMP_FAILURE_RETRY(close(read_err[1]));
360 VOID_TEMP_FAILURE_RETRY(close(write_out[0])); 362 VOID_TEMP_FAILURE_RETRY(close(write_out[0]));
361 VOID_TEMP_FAILURE_RETRY(close(write_out[1])); 363 VOID_TEMP_FAILURE_RETRY(close(write_out[1]));
362 VOID_TEMP_FAILURE_RETRY(close(exec_control[0])); 364 VOID_TEMP_FAILURE_RETRY(close(exec_control[0]));
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 if (signal == -1) return -1; 712 if (signal == -1) return -1;
711 bool found = false; 713 bool found = false;
712 for (int i = 0; i < kSignalsCount; i++) { 714 for (int i = 0; i < kSignalsCount; i++) {
713 if (kSignals[i] == signal) { 715 if (kSignals[i] == signal) {
714 found = true; 716 found = true;
715 break; 717 break;
716 } 718 }
717 } 719 }
718 if (!found) return -1; 720 if (!found) return -1;
719 int fds[2]; 721 int fds[2];
720 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(pipe(fds)) != 0) { 722 if (NO_RETRY_EXPECTED(pipe(fds)) != 0) {
721 return -1; 723 return -1;
722 } 724 }
723 if (!FDUtils::SetNonBlocking(fds[0])) { 725 if (!FDUtils::SetNonBlocking(fds[0])) {
724 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fds[0])); 726 VOID_TEMP_FAILURE_RETRY(close(fds[0]));
725 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fds[1])); 727 VOID_TEMP_FAILURE_RETRY(close(fds[1]));
726 return -1; 728 return -1;
727 } 729 }
728 ThreadSignalBlocker blocker(kSignalsCount, kSignals); 730 ThreadSignalBlocker blocker(kSignalsCount, kSignals);
729 MutexLocker lock(signal_mutex); 731 MutexLocker lock(signal_mutex);
730 SignalInfo* handler = signal_handlers; 732 SignalInfo* handler = signal_handlers;
731 bool listen = true; 733 bool listen = true;
732 while (handler != NULL) { 734 while (handler != NULL) {
733 if (handler->signal() == signal) { 735 if (handler->signal() == signal) {
734 listen = false; 736 listen = false;
735 break; 737 break;
736 } 738 }
737 handler = handler->next(); 739 handler = handler->next();
738 } 740 }
739 if (listen) { 741 if (listen) {
740 struct sigaction act; 742 struct sigaction act;
741 bzero(&act, sizeof(act)); 743 bzero(&act, sizeof(act));
742 act.sa_handler = SignalHandler; 744 act.sa_handler = SignalHandler;
743 sigemptyset(&act.sa_mask); 745 sigemptyset(&act.sa_mask);
744 for (int i = 0; i < kSignalsCount; i++) { 746 for (int i = 0; i < kSignalsCount; i++) {
745 sigaddset(&act.sa_mask, kSignals[i]); 747 sigaddset(&act.sa_mask, kSignals[i]);
746 } 748 }
747 intptr_t status = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( 749 intptr_t status = NO_RETRY_EXPECTED(sigaction(signal, &act, NULL));
748 sigaction(signal, &act, NULL));
749 if (status < 0) { 750 if (status < 0) {
750 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fds[0])); 751 VOID_TEMP_FAILURE_RETRY(close(fds[0]));
751 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fds[1])); 752 VOID_TEMP_FAILURE_RETRY(close(fds[1]));
752 return -1; 753 return -1;
753 } 754 }
754 } 755 }
755 if (signal_handlers == NULL) { 756 if (signal_handlers == NULL) {
756 signal_handlers = new SignalInfo(fds[1], signal); 757 signal_handlers = new SignalInfo(fds[1], signal);
757 } else { 758 } else {
758 new SignalInfo(fds[1], signal, signal_handlers); 759 new SignalInfo(fds[1], signal, signal_handlers);
759 } 760 }
760 return fds[0]; 761 return fds[0];
761 } 762 }
(...skipping 18 matching lines...) Expand all
780 } 781 }
781 } 782 }
782 SignalInfo* next = handler->next(); 783 SignalInfo* next = handler->next();
783 if (remove) delete handler; 784 if (remove) delete handler;
784 handler = next; 785 handler = next;
785 } 786 }
786 if (unlisten) { 787 if (unlisten) {
787 struct sigaction act; 788 struct sigaction act;
788 bzero(&act, sizeof(act)); 789 bzero(&act, sizeof(act));
789 act.sa_handler = SIG_DFL; 790 act.sa_handler = SIG_DFL;
790 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(sigaction(signal, &act, NULL)); 791 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL));
791 } 792 }
792 } 793 }
793 794
794 } // namespace bin 795 } // namespace bin
795 } // namespace dart 796 } // namespace dart
796 797
797 #endif // defined(TARGET_OS_MACOS) 798 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/process_linux.cc ('k') | runtime/bin/signal_blocker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698