Skip to content

Commit 661efae

Browse files
Ukalninsgabebear
andcommitted
Only grab terminal when necessery and restore when done (#414)
* Only grab terminal when necessery * #414 bring to foreground also in noninteractive mode Co-authored-by: Gabe Giosia <gabe@ghearing.com>
1 parent b789f9b commit 661efae

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,14 +1083,16 @@ void lldb_finished_handler(int signum)
10831083
_exit(WEXITSTATUS(status));
10841084
}
10851085

1086-
void bring_process_to_foreground() {
1086+
pid_t bring_process_to_foreground() {
1087+
pid_t fgpid = tcgetpgrp(STDIN_FILENO);
10871088
if (setpgid(0, 0) == -1)
10881089
perror("setpgid failed");
10891090

10901091
signal(SIGTTOU, SIG_IGN);
10911092
if (tcsetpgrp(STDIN_FILENO, getpid()) == -1)
10921093
perror("tcsetpgrp failed");
10931094
signal(SIGTTOU, SIG_DFL);
1095+
return fgpid;
10941096
}
10951097

10961098
void setup_dummy_pipe_on_stdin(int pfd[2]) {
@@ -1140,12 +1142,12 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
11401142
signal(SIGHUP, SIG_DFL);
11411143
signal(SIGLLDB, SIG_DFL);
11421144
child = getpid();
1143-
1145+
pid_t oldfgpid = 0;
11441146
int pfd[2] = {-1, -1};
11451147
if (isatty(STDIN_FILENO))
11461148
// If we are running on a terminal, then we need to bring process to foreground for input
11471149
// to work correctly on lldb's end.
1148-
bring_process_to_foreground();
1150+
oldfgpid = bring_process_to_foreground();
11491151
else
11501152
// If lldb is running in a non terminal environment, then it freaks out spamming "^D" and
11511153
// "quit". It seems this is caused by read() on stdin returning EOF in lldb. To hack around
@@ -1169,6 +1171,10 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
11691171

11701172
// Notify parent we're exiting
11711173
kill(parent, SIGLLDB);
1174+
1175+
if (oldfgpid) {
1176+
tcsetpgrp(STDIN_FILENO, oldfgpid);
1177+
}
11721178
// Pass lldb exit code
11731179
_exit(WEXITSTATUS(status));
11741180
} else if (pid > 0) {

0 commit comments

Comments
 (0)