mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +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:
parent
829bf94de1
commit
5d7ba9640c
1 changed files with 6 additions and 0 deletions
|
@ -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));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue