1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00: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:
Andreas Kling 2018-12-07 01:26:07 +01:00
parent 829bf94de1
commit 5d7ba9640c

View file

@ -6,6 +6,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <termios.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <AK/FileSystemPath.h> #include <AK/FileSystemPath.h>
@ -291,6 +292,9 @@ static int runcmd(char* cmd)
return 0; return 0;
} }
struct termios trm;
tcgetattr(0, &trm);
pid_t child = fork(); pid_t child = fork();
if (!child) { if (!child) {
setpgid(0, 0); 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? // Is the terminal controlling pgrp really still the PGID of the dead process?
tcsetpgrp(0, getpid()); tcsetpgrp(0, getpid());
tcsetattr(0, TCSANOW, &trm);
if (WIFEXITED(wstatus)) { if (WIFEXITED(wstatus)) {
if (WEXITSTATUS(wstatus) != 0) if (WEXITSTATUS(wstatus) != 0)
printf("Exited with status %d\n", WEXITSTATUS(wstatus)); printf("Exited with status %d\n", WEXITSTATUS(wstatus));