commit c09d58a66ff792a639ec64e51f658ef3277a7441
parent c56ea52bd1002ff2b1cb6b69c298dddf2292ee87
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 17 May 2022 22:09:09 +0200
libc: Add _waitpid() syscall
_waitpid() is implemented in bsd and linux systems using _wait4()
syscall.
Diffstat:
14 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/include/bits/darwin/sys.h b/include/bits/darwin/sys.h
@@ -27,3 +27,4 @@ extern pid_t _getpid(void);
extern int _kill(pid_t, int);
extern int _sigaction(int, struct sigaction *, struct sigaction *);
extern pid_t _wait4(pid_t, int *, int, struct rusage *);
+extern pid_t _waitpid(pid_t, int *, int);
diff --git a/include/bits/dragonfly/sys.h b/include/bits/dragonfly/sys.h
@@ -27,3 +27,4 @@ extern pid_t _getpid(void);
extern int _kill(pid_t, int);
extern int _sigaction(int, struct sigaction *, struct sigaction *);
extern pid_t _wait4(pid_t, int *, int, struct rusage *);
+extern pid_t _waitpid(pid_t, int *, int);
diff --git a/include/bits/linux/sys.h b/include/bits/linux/sys.h
@@ -27,3 +27,4 @@ extern pid_t _getpid(void);
extern int _kill(pid_t, int);
extern int _sigaction(int, struct sigaction *, struct sigaction *);
extern pid_t _wait4(pid_t, int *, int, struct rusage *);
+extern pid_t _waitpid(pid_t, int *, int);
diff --git a/include/bits/netbsd/sys.h b/include/bits/netbsd/sys.h
@@ -27,3 +27,4 @@ extern pid_t _getpid(void);
extern int _kill(pid_t, int);
extern int _sigaction(int, struct sigaction *, struct sigaction *);
extern pid_t _wait4(pid_t, int *, int, struct rusage *);
+extern pid_t _waitpid(pid_t, int *, int);
diff --git a/include/bits/openbsd/sys.h b/include/bits/openbsd/sys.h
@@ -27,3 +27,4 @@ extern pid_t _getpid(void);
extern int _kill(pid_t, int);
extern int _sigaction(int, struct sigaction *, struct sigaction *);
extern pid_t _wait4(pid_t, int *, int, struct rusage *);
+extern pid_t _waitpid(pid_t, int *, int);
diff --git a/src/libc/arch/Makefile b/src/libc/arch/Makefile
@@ -15,11 +15,14 @@ DIRS =\
linux\
posix\
-POSIX =\
+BSD =\
netbsd\
openbsd\
darwin\
dragonfly\
+
+POSIX =\
+ $(BSD)\
linux\
include $(PROJECTDIR)/scripts/rules.mk
@@ -30,3 +33,4 @@ NODEP = 1
all: $(ARCH) $(SYS)
$(POSIX): posix
+$(BSD): bsd
diff --git a/src/libc/arch/bsd/Makefile b/src/libc/arch/bsd/Makefile
@@ -0,0 +1,11 @@
+.POSIX:
+PROJECTDIR = ../../../..
+include $(PROJECTDIR)/scripts/rules.mk
+include ../../rules.mk
+
+OBJS=\
+ _waitpid.$O\
+
+all: $(OBJS)
+
+include deps.mk
diff --git a/src/libc/arch/bsd/_waitpid.c b/src/libc/arch/bsd/_waitpid.c
@@ -0,0 +1,9 @@
+#include <stddef.h>
+
+#include <sys.h>
+
+int
+_waitpid(pid_t pid, int *status, int options)
+{
+ return _wait4(pid, status, options, NULL);
+}
diff --git a/src/libc/arch/bsd/deps.mk b/src/libc/arch/bsd/deps.mk
@@ -0,0 +1 @@
+#deps
diff --git a/src/libc/arch/linux/Makefile b/src/libc/arch/linux/Makefile
@@ -7,6 +7,7 @@ OBJS=\
_brk.$O\
_getheap.$O\
_sigaction.$O\
+ _waitpid.$O\
all: $(OBJS)
diff --git a/src/libc/arch/linux/_waitpid.c b/src/libc/arch/linux/_waitpid.c
@@ -0,0 +1 @@
+#include "../bsd/_waitpid.c"
diff --git a/src/libc/objs/amd64-linux.mk b/src/libc/objs/amd64-linux.mk
@@ -34,6 +34,7 @@ OBJS =\
arch/linux/_brk.$O\
arch/linux/_getheap.$O\
arch/linux/_sigaction.$O\
+ arch/linux/_waitpid.$O\
arch/posix/_open.$O\
arch/posix/_systime.$O\
arch/posix/_tzone.$O\
diff --git a/src/libc/objs/amd64-netbsd.mk b/src/libc/objs/amd64-netbsd.mk
@@ -26,6 +26,7 @@ OBJS =\
arch/amd64/strchr.$O\
arch/amd64/strcmp.$O\
arch/amd64/strcpy.$O\
+ arch/bsd/_waitpid.$O\
arch/netbsd/_sigaction.$O\
arch/posix/_getheap.$O\
arch/posix/_open.$O\
diff --git a/src/libc/objs/amd64-openbsd.mk b/src/libc/objs/amd64-openbsd.mk
@@ -26,6 +26,7 @@ OBJS =\
arch/amd64/strchr.$O\
arch/amd64/strcmp.$O\
arch/amd64/strcpy.$O\
+ arch/bsd/_waitpid.$O\
arch/posix/_getheap.$O\
arch/posix/_open.$O\
arch/posix/_systime.$O\