mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 21:45:20 +00:00
Terminal: Wait on the utmpupdate process to finish
This solves utmpupdate zombies hanging around until Terminal terminates.
This commit is contained in:
parent
65eef944ab
commit
4c8c149612
Notes:
sideshowbarker
2024-07-19 01:10:24 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/4c8c1496124 Pull-request: https://github.com/SerenityOS/serenity/pull/4264
1 changed files with 23 additions and 4 deletions
|
@ -55,6 +55,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static void utmp_update(const char* tty, pid_t pid, bool create)
|
static void utmp_update(const char* tty, pid_t pid, bool create)
|
||||||
|
@ -66,10 +67,28 @@ static void utmp_update(const char* tty, pid_t pid, bool create)
|
||||||
perror("fork");
|
perror("fork");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (utmpupdate_pid)
|
if (utmpupdate_pid == 0) {
|
||||||
return;
|
// Be careful here! Because fork() only clones one thread it's
|
||||||
const auto shell_pid_string = String::formatted("{}", pid);
|
// possible that we deadlock on anything involving a mutex,
|
||||||
execl("/bin/utmpupdate", "/bin/utmpupdate", "-f", "Terminal", "-p", shell_pid_string.characters(), (create ? "-c" : "-d"), tty, nullptr);
|
// including the heap! So resort to low-level APIs
|
||||||
|
char pid_str[32];
|
||||||
|
snprintf(pid_str, sizeof(pid_str), "%d", pid);
|
||||||
|
execl("/bin/utmpupdate", "/bin/utmpupdate", "-f", "Terminal", "-p", pid_str, (create ? "-c" : "-d"), tty, nullptr);
|
||||||
|
} else {
|
||||||
|
wait_again:
|
||||||
|
int status = 0;
|
||||||
|
if (waitpid(utmpupdate_pid, &status, 0) < 0) {
|
||||||
|
int err = errno;
|
||||||
|
if (err == EINTR)
|
||||||
|
goto wait_again;
|
||||||
|
perror("waitpid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
|
||||||
|
dbgln("Terminal: utmpupdate exited with status {}", WEXITSTATUS(status));
|
||||||
|
else if (WIFSIGNALED(status))
|
||||||
|
dbgln("Terminal: utmpupdate exited due to unhandled signal {}", WTERMSIG(status));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static pid_t run_command(int ptm_fd, String command)
|
static pid_t run_command(int ptm_fd, String command)
|
||||||
|
|
Loading…
Add table
Reference in a new issue