From 4f4dc47ec333f3eb665f664339332b4f3ce91a78 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 4 Jan 2020 12:33:34 +0100 Subject: [PATCH] TTYServer: Use fork+exec instead of system() No point in spawning an extra shell process just to spawn a shell. :^) --- Servers/TTYServer/main.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Servers/TTYServer/main.cpp b/Servers/TTYServer/main.cpp index f16c226c6d..d26fb938cb 100644 --- a/Servers/TTYServer/main.cpp +++ b/Servers/TTYServer/main.cpp @@ -1,5 +1,8 @@ +#include #include #include +#include +#include int main(int argc, char** argv) { @@ -10,7 +13,17 @@ int main(int argc, char** argv) while (true) { dbgprintf("Running shell on %s\n", argv[1]); - int rc = system("/bin/Shell"); - dbgprintf("Shell on %s exited with code %d\n", argv[1], rc); + + auto child = fork(); + if (!child) { + int rc = execl("/bin/Shell", "Shell", nullptr); + ASSERT(rc < 0); + perror("execl"); + exit(127); + } else { + int wstatus; + waitpid(child, &wstatus, 0); + dbgprintf("Shell on %s exited with code %d\n", argv[1], WEXITSTATUS(wstatus)); + } } }