mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 06:37:36 +00:00
SystemServer: Reap dead processes. (#706)
SystemServer didn't reap its child processes. This commit adds sigchld_handler, which reaps children when appropriate.
This commit is contained in:
parent
b583f21e27
commit
6bd1879189
1 changed files with 13 additions and 1 deletions
|
@ -3,13 +3,23 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
//#define SPAWN_MULTIPLE_VIRTUAL_CONSOLES
|
||||
|
||||
void sigchld_handler(int)
|
||||
{
|
||||
int status = 0;
|
||||
pid_t pid = waitpid(-1, &status, WNOHANG);
|
||||
if (pid)
|
||||
dbg() << "reaped pid " << pid;
|
||||
}
|
||||
|
||||
void start_process(const String& program, const Vector<String>& arguments, int prio, const char* tty = nullptr)
|
||||
{
|
||||
pid_t pid = 0;
|
||||
|
@ -45,7 +55,7 @@ void start_process(const String& program, const Vector<String>& arguments, int p
|
|||
char* progv[256];
|
||||
progv[0] = const_cast<char*>(program.characters());
|
||||
for (int i = 0; i < arguments.size() && i < 254; i++)
|
||||
progv[i+1] = const_cast<char*>(arguments[i].characters());
|
||||
progv[i + 1] = const_cast<char*>(arguments[i].characters());
|
||||
progv[arguments.size() + 1] = nullptr;
|
||||
ret = execv(progv[0], progv);
|
||||
if (ret < 0) {
|
||||
|
@ -100,6 +110,8 @@ int main(int, char**)
|
|||
setgid(100);
|
||||
setuid(100);
|
||||
|
||||
signal(SIGCHLD, sigchld_handler);
|
||||
|
||||
start_process("/bin/LookupServer", {}, lowest_prio);
|
||||
start_process("/bin/WindowServer", {}, highest_prio);
|
||||
start_process("/bin/AudioServer", {}, highest_prio);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue