| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 7 | 7 |
| 8 #include "bin/process.h" | 8 #include "bin/process.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 if (kSignals[i] == signal) { | 667 if (kSignals[i] == signal) { |
| 668 found = true; | 668 found = true; |
| 669 break; | 669 break; |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 if (!found) return -1; | 672 if (!found) return -1; |
| 673 int fds[2]; | 673 int fds[2]; |
| 674 if (pipe(fds) != 0) { | 674 if (pipe(fds) != 0) { |
| 675 return -1; | 675 return -1; |
| 676 } | 676 } |
| 677 if (!FDUtils::SetNonBlocking(fds[0])) { | |
| 678 VOID_TEMP_FAILURE_RETRY(close(fds[0])); | |
| 679 VOID_TEMP_FAILURE_RETRY(close(fds[1])); | |
| 680 return -1; | |
| 681 } | |
| 682 ThreadSignalBlocker blocker(kSignalsCount, kSignals); | 677 ThreadSignalBlocker blocker(kSignalsCount, kSignals); |
| 683 MutexLocker lock(signal_mutex); | 678 MutexLocker lock(signal_mutex); |
| 684 SignalInfo* handler = signal_handlers; | 679 SignalInfo* handler = signal_handlers; |
| 685 bool listen = true; | 680 bool listen = true; |
| 686 while (handler != NULL) { | 681 while (handler != NULL) { |
| 687 if (handler->signal() == signal) { | 682 if (handler->signal() == signal) { |
| 688 listen = false; | 683 listen = false; |
| 689 break; | 684 break; |
| 690 } | 685 } |
| 691 handler = handler->next(); | 686 handler = handler->next(); |
| 692 } | 687 } |
| 693 if (listen) { | 688 if (listen) { |
| 694 struct sigaction act; | 689 struct sigaction act; |
| 695 bzero(&act, sizeof(act)); | 690 bzero(&act, sizeof(act)); |
| 696 act.sa_handler = SignalHandler; | 691 act.sa_handler = SignalHandler; |
| 697 sigemptyset(&act.sa_mask); | 692 sigemptyset(&act.sa_mask); |
| 698 for (int i = 0; i < kSignalsCount; i++) { | 693 for (int i = 0; i < kSignalsCount; i++) { |
| 699 sigaddset(&act.sa_mask, kSignals[i]); | 694 sigaddset(&act.sa_mask, kSignals[i]); |
| 700 } | 695 } |
| 701 int status = sigaction(signal, &act, NULL); | 696 int status = sigaction(signal, &act, NULL); |
| 702 if (status < 0) { | 697 if (status < 0) { |
| 698 int err = errno; |
| 703 VOID_TEMP_FAILURE_RETRY(close(fds[0])); | 699 VOID_TEMP_FAILURE_RETRY(close(fds[0])); |
| 704 VOID_TEMP_FAILURE_RETRY(close(fds[1])); | 700 VOID_TEMP_FAILURE_RETRY(close(fds[1])); |
| 701 errno = err; |
| 705 return -1; | 702 return -1; |
| 706 } | 703 } |
| 707 } | 704 } |
| 708 if (signal_handlers == NULL) { | 705 if (signal_handlers == NULL) { |
| 709 signal_handlers = new SignalInfo(fds[1], signal); | 706 signal_handlers = new SignalInfo(fds[1], signal); |
| 710 } else { | 707 } else { |
| 711 new SignalInfo(fds[1], signal, signal_handlers); | 708 new SignalInfo(fds[1], signal, signal_handlers); |
| 712 } | 709 } |
| 713 return fds[0]; | 710 return fds[0]; |
| 714 } | 711 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 739 bzero(&act, sizeof(act)); | 736 bzero(&act, sizeof(act)); |
| 740 act.sa_handler = SIG_DFL; | 737 act.sa_handler = SIG_DFL; |
| 741 sigaction(signal, &act, NULL); | 738 sigaction(signal, &act, NULL); |
| 742 } | 739 } |
| 743 } | 740 } |
| 744 | 741 |
| 745 } // namespace bin | 742 } // namespace bin |
| 746 } // namespace dart | 743 } // namespace dart |
| 747 | 744 |
| 748 #endif // defined(TARGET_OS_LINUX) | 745 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |