Skip to content

Commit 6018424

Browse files
UkalninsUldis Kalniņš
authored andcommitted
Only grab terminal when necessery
1 parent 784090b commit 6018424

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -994,14 +994,16 @@ void lldb_finished_handler(int signum)
994994
_exit(WEXITSTATUS(status));
995995
}
996996

997-
void bring_process_to_foreground() {
997+
pid_t bring_process_to_foreground() {
998+
pid_t fgpid = tcgetpgrp(STDIN_FILENO);
998999
if (setpgid(0, 0) == -1)
9991000
perror("setpgid failed");
10001001

10011002
signal(SIGTTOU, SIG_IGN);
10021003
if (tcsetpgrp(STDIN_FILENO, getpid()) == -1)
10031004
perror("tcsetpgrp failed");
10041005
signal(SIGTTOU, SIG_DFL);
1006+
return fgpid;
10051007
}
10061008

10071009
void setup_dummy_pipe_on_stdin(int pfd[2]) {
@@ -1051,12 +1053,12 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
10511053
signal(SIGHUP, SIG_DFL);
10521054
signal(SIGLLDB, SIG_DFL);
10531055
child = getpid();
1054-
1056+
pid_t oldfgpid = 0;
10551057
int pfd[2] = {-1, -1};
1056-
if (isatty(STDIN_FILENO))
1058+
if (interactive && isatty(STDIN_FILENO))
10571059
// If we are running on a terminal, then we need to bring process to foreground for input
10581060
// to work correctly on lldb's end.
1059-
bring_process_to_foreground();
1061+
oldfgpid = bring_process_to_foreground();
10601062
else
10611063
// If lldb is running in a non terminal environment, then it freaks out spamming "^D" and
10621064
// "quit". It seems this is caused by read() on stdin returning EOF in lldb. To hack around
@@ -1080,6 +1082,10 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
10801082

10811083
// Notify parent we're exiting
10821084
kill(parent, SIGLLDB);
1085+
1086+
if (oldfgpid) {
1087+
tcsetpgrp(STDIN_FILENO, oldfgpid);
1088+
}
10831089
// Pass lldb exit code
10841090
_exit(WEXITSTATUS(status));
10851091
} else if (pid > 0) {

0 commit comments

Comments
 (0)