mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 14:27:34 +00:00
TTYServer: Use fork+exec instead of system()
No point in spawning an extra shell process just to spawn a shell. :^)
This commit is contained in:
parent
b5da0b78eb
commit
4f4dc47ec3
1 changed files with 15 additions and 2 deletions
|
@ -1,5 +1,8 @@
|
||||||
|
#include <AK/Assertions.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -10,7 +13,17 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
dbgprintf("Running shell on %s\n", argv[1]);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue