Skip to content

Commit 52afcba

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ VM ] Fixed issue where process was suspended at exit when backgrounded.
Restoring console state when backgrounded causes SIGTTOU to be raised by tcsetattr, which has the affect of suspending the process instead of allowing it to complete. Blocking SIGTTOU results in tcsetattr failing gracefully and the process running to completion. Change-Id: I605dccbdbf311697881e5729e4fd64f1d60ed6b1 Reviewed-on: https://dart-review.googlesource.com/48823 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent cdc696f commit 52afcba

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

runtime/bin/platform_android.cc

+11
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ bool Platform::Initialize() {
4747
return false;
4848
}
4949

50+
// tcsetattr raises SIGTTOU if we try to set console attributes when
51+
// backgrounded, which suspends the process. Ignoring the signal prevents
52+
// us from being suspended and lets us fail gracefully instead.
53+
sigset_t signal_mask;
54+
sigemptyset(&signal_mask);
55+
sigaddset(&signal_mask, SIGTTOU);
56+
if (sigprocmask(SIG_BLOCK, &signal_mask, NULL) < 0) {
57+
perror("Setting signal handler failed");
58+
return false;
59+
}
60+
5061
act.sa_flags = SA_SIGINFO;
5162
act.sa_sigaction = &segv_handler;
5263
if (sigemptyset(&act.sa_mask) != 0) {

runtime/bin/platform_linux.cc

+11
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ bool Platform::Initialize() {
4747
return false;
4848
}
4949

50+
// tcsetattr raises SIGTTOU if we try to set console attributes when
51+
// backgrounded, which suspends the process. Ignoring the signal prevents
52+
// us from being suspended and lets us fail gracefully instead.
53+
sigset_t signal_mask;
54+
sigemptyset(&signal_mask);
55+
sigaddset(&signal_mask, SIGTTOU);
56+
if (sigprocmask(SIG_BLOCK, &signal_mask, NULL) < 0) {
57+
perror("Setting signal handler failed");
58+
return false;
59+
}
60+
5061
act.sa_flags = SA_SIGINFO;
5162
act.sa_sigaction = &segv_handler;
5263
if (sigemptyset(&act.sa_mask) != 0) {

runtime/bin/platform_macos.cc

+12
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ bool Platform::Initialize() {
5454
perror("Setting signal handler failed");
5555
return false;
5656
}
57+
58+
// tcsetattr raises SIGTTOU if we try to set console attributes when
59+
// backgrounded, which suspends the process. Ignoring the signal prevents
60+
// us from being suspended and lets us fail gracefully instead.
61+
sigset_t signal_mask;
62+
sigemptyset(&signal_mask);
63+
sigaddset(&signal_mask, SIGTTOU);
64+
if (sigprocmask(SIG_BLOCK, &signal_mask, NULL) < 0) {
65+
perror("Setting signal handler failed");
66+
return false;
67+
}
68+
5769
act.sa_flags = SA_SIGINFO;
5870
act.sa_sigaction = &segv_handler;
5971
if (sigemptyset(&act.sa_mask) != 0) {

0 commit comments

Comments
 (0)