hush/libbb/vfork.and.run.c
Stephen Heumann 051b79efc1 Move all the source files to 15-character ProDOS-compatible file names.
Dmake gets confused if you use over-15-character file names, so they needed to be shortened to get it to work. While I was at it, I also switched _ to . in the filenames so they're fully ProDOS compatible.

The shell/hush_test directory (not needed to build the code) still uses ProDOS-incompatible file names.
2014-11-02 22:11:07 -06:00

31 lines
621 B
C

#include <unistd.h>
#include "libbb.h"
/* Like vfork, but calls fn(arg) in the child instead of returning.
* This is designed to match the semantics of GNO's fork2 call.
*/
#ifndef __GNO__
pid_t vfork_and_run(void (*fn)(void*) NORETURN, void *arg) {
pid_t pid = vfork();
if (pid == 0) {
fn(arg);
}
return pid;
}
#else
pid_t vfork_and_run(void (*fn)(void*) NORETURN, void *arg) {
return fork2((fn), 1024, 0, "hush (forked)", 2, (arg));
}
#endif
pid_t xvfork_and_run(void (*fn)(void*) NORETURN, void *arg) {
pid_t pid = vfork_and_run(fn, arg);
if (pid < 0)
bb_perror_msg_and_die("vfork");
return pid;
}