summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2021-12-13 18:43:39 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-12-16 02:10:47 -0800
commit11578c623c3208cf79c1d03f63f38a482a2a207f (patch)
tree9b70eb38a4de6e5589bf3a8d87d990367fd211bf
parent123e49994d05c105421db10baa3a109bb57d0fa7 (diff)
downloadserenity-11578c623c3208cf79c1d03f63f38a482a2a207f.zip
LibCore: Add waitpid() wrapper that return ErrorOr<pid_t>
-rw-r--r--Userland/Libraries/LibCore/System.cpp8
-rw-r--r--Userland/Libraries/LibCore/System.h2
2 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp
index 54a04e9002..4014830411 100644
--- a/Userland/Libraries/LibCore/System.cpp
+++ b/Userland/Libraries/LibCore/System.cpp
@@ -380,4 +380,12 @@ ErrorOr<pid_t> posix_spawnp(StringView const path, posix_spawn_file_actions_t* c
return child_pid;
}
+ErrorOr<pid_t> waitpid(pid_t waitee, int* wstatus, int options)
+{
+ pid_t pid = ::waitpid(waitee, wstatus, options);
+ if (pid < 0)
+ return Error::from_syscall("waitpid"sv, -errno);
+ return pid;
+}
+
}
diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h
index e9d8dd8b8e..32d4beb711 100644
--- a/Userland/Libraries/LibCore/System.h
+++ b/Userland/Libraries/LibCore/System.h
@@ -13,6 +13,7 @@
#include <signal.h>
#include <spawn.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <termios.h>
#include <time.h>
@@ -53,5 +54,6 @@ ErrorOr<struct passwd> getpwnam(StringView name);
ErrorOr<struct group> getgrnam(StringView name);
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts);
ErrorOr<pid_t> posix_spawnp(StringView const path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]);
+ErrorOr<pid_t> waitpid(pid_t waitee, int* wstatus, int options);
}