summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibC/stdlib.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp
index 89cafd8e8c..dcade0b816 100644
--- a/Libraries/LibC/stdlib.cpp
+++ b/Libraries/LibC/stdlib.cpp
@@ -263,12 +263,18 @@ void srandom(unsigned seed)
int system(const char* command)
{
+ if (!command)
+ return 1;
+
auto child = fork();
+ if (child < 0)
+ return -1;
+
if (!child) {
int rc = execl("/bin/sh", "sh", "-c", command, nullptr);
- if (rc < 0)
- perror("execl");
- exit(0);
+ ASSERT(rc < 0);
+ perror("execl");
+ exit(127);
}
int wstatus;
waitpid(child, &wstatus, 0);