aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-09-23 22:18:22 -0500
committerRob Landley <rob@landley.net>2015-09-23 22:18:22 -0500
commit847bcb63b541e4fbbfa3dccfe3022745cbe9a06a (patch)
tree35c6fb8b4bdb11e995a95919abfa682ab7c20221 /lib
parent712e163bb0956b94c27051d0175e719b92f453ad (diff)
downloadtoybox-847bcb63b541e4fbbfa3dccfe3022745cbe9a06a.tar.gz
Add xvfork() as a static inline and use it from various places.
Note: vfork(), like fork(), can return -1 if too many processes, and we should notice and fail loudly.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/lib.h b/lib/lib.h
index 2b49dc17..cbac3aa5 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -246,5 +246,17 @@ void mode_to_string(mode_t mode, char *buf);
char *basename_r(char *name);
void names_to_pid(char **names, int (*callback)(pid_t pid, char *name));
+// Returning from a function can modify a potentially shared stack,
+// so this has to always inline.
+
+static inline pid_t xvfork(void)
+{
+ pid_t p = vfork();
+
+ if (p == -1) perror_exit("vfork");
+
+ return p;
+}
+
// Functions in need of further review/cleanup
#include "lib/pending.h"