| OLD | NEW |
| 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/platform.h" | 5 #include "bin/platform.h" |
| 6 | 6 |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 | 11 |
| 12 bool Platform::Initialize() { | 12 bool Platform::Initialize() { |
| 13 // Turn off the signal handler for SIGPIPE as it causes the process | 13 // Turn off the signal handler for SIGPIPE as it causes the process |
| 14 // to terminate on writing to a closed pipe. Without the signal | 14 // to terminate on writing to a closed pipe. Without the signal |
| 15 // handler error EPIPE is set instead. | 15 // handler error EPIPE is set instead. |
| 16 struct sigaction act; | 16 struct sigaction act; |
| 17 bzero(&act, sizeof(act)); | 17 bzero(&act, sizeof(act)); |
| 18 act.sa_handler = SIG_IGN; | 18 act.sa_handler = SIG_IGN; |
| 19 if (sigaction(SIGPIPE, &act, 0) != 0) { | 19 if (sigaction(SIGPIPE, &act, 0) != 0) { |
| 20 perror("Setting signal handler failed"); | 20 perror("Setting signal handler failed"); |
| 21 return false; | 21 return false; |
| 22 } | 22 } |
| 23 // Unblock SIGCHLD as waiting on spawned child process depends |
| 24 // on successful interception of this signal. |
| 25 sigset_t newset; |
| 26 sigemptyset(&newset); |
| 27 sigaddset(&newset, SIGCHLD); |
| 28 if (sigprocmask(SIG_UNBLOCK, &newset, NULL) != 0) { |
| 29 perror("Unblocking SIGCHLD signal failed"); |
| 30 } |
| 23 return true; | 31 return true; |
| 24 } | 32 } |
| 25 | 33 |
| 26 | 34 |
| 27 int Platform::NumberOfProcessors() { | 35 int Platform::NumberOfProcessors() { |
| 28 return sysconf(_SC_NPROCESSORS_ONLN); | 36 return sysconf(_SC_NPROCESSORS_ONLN); |
| 29 } | 37 } |
| 30 | 38 |
| 31 | 39 |
| 32 const char* Platform::OperatingSystem() { | 40 const char* Platform::OperatingSystem() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 54 } | 62 } |
| 55 | 63 |
| 56 | 64 |
| 57 char* Platform::StrError(int error_code) { | 65 char* Platform::StrError(int error_code) { |
| 58 static const int kBufferSize = 1024; | 66 static const int kBufferSize = 1024; |
| 59 char* error = static_cast<char*>(malloc(kBufferSize)); | 67 char* error = static_cast<char*>(malloc(kBufferSize)); |
| 60 error[0] = '\0'; | 68 error[0] = '\0'; |
| 61 strerror_r(error_code, error, kBufferSize); | 69 strerror_r(error_code, error, kBufferSize); |
| 62 return error; | 70 return error; |
| 63 } | 71 } |
| OLD | NEW |