mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 01:41:59 -05:00
sh: Restore termios after a child process exits.
This avoids the annoying situation that occurs when a spawned process messes with the termios and then doesn't exit cleanly.
This commit is contained in:
parent
829bf94de1
commit
5d7ba9640c
1 changed files with 6 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <AK/FileSystemPath.h>
|
||||
|
@ -291,6 +292,9 @@ static int runcmd(char* cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct termios trm;
|
||||
tcgetattr(0, &trm);
|
||||
|
||||
pid_t child = fork();
|
||||
if (!child) {
|
||||
setpgid(0, 0);
|
||||
|
@ -318,6 +322,8 @@ static int runcmd(char* cmd)
|
|||
// Is the terminal controlling pgrp really still the PGID of the dead process?
|
||||
tcsetpgrp(0, getpid());
|
||||
|
||||
tcsetattr(0, TCSANOW, &trm);
|
||||
|
||||
if (WIFEXITED(wstatus)) {
|
||||
if (WEXITSTATUS(wstatus) != 0)
|
||||
printf("Exited with status %d\n", WEXITSTATUS(wstatus));
|
||||
|
|
Loading…
Reference in a new issue