summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
authorDrewStratford <drewstratford@outlook.com>2019-10-31 21:49:53 +1300
committerAndreas Kling <awesomekling@gmail.com>2019-10-31 09:49:53 +0100
commit6bd1879189c2acefdb91c80400f685ea99e2b46a (patch)
treea2cc40cabf5947ff3367b710c9cb9f50c93d577c /Servers
parentb583f21e277b68c60f290379f97c7efbf55863a7 (diff)
downloadserenity-6bd1879189c2acefdb91c80400f685ea99e2b46a.zip
SystemServer: Reap dead processes. (#706)
SystemServer didn't reap its child processes. This commit adds sigchld_handler, which reaps children when appropriate.
Diffstat (limited to 'Servers')
-rw-r--r--Servers/SystemServer/main.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/Servers/SystemServer/main.cpp b/Servers/SystemServer/main.cpp
index 68974780c6..d713c5995b 100644
--- a/Servers/SystemServer/main.cpp
+++ b/Servers/SystemServer/main.cpp
@@ -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);