mirror of
https://github.com/troglobit/libite.git
synced 2026-10-09 16:50:43 +07:00
The runbg() function is a delayed execvp() that has double-forked to the background (to not create zombies). It is useful for running commands in the background for APIs that need to return a reply, e.g. a NETCONF RPC to reboot the system. Compared to the original in Infix, this version double forks to reparent itself to PID 1 (init), closes all open files, including stdio. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
24 lines
413 B
C
24 lines
413 B
C
#include "check.h"
|
|
|
|
#define file "/tmp/runbg.txt"
|
|
|
|
int main(void)
|
|
{
|
|
char *cmd[] = {
|
|
"sh", "-c", "echo 'hello world' > " file, NULL
|
|
};
|
|
|
|
erase(file);
|
|
test(runbg(cmd, 200000), "Calling runbg");
|
|
|
|
if (test(fexist(file), "Verifying %s does not yet exist", file))
|
|
return 1;
|
|
|
|
test(usleep(300000), "Waiting for runbg");
|
|
|
|
if (test(!fexist(file), "Verifying %s has been created", file))
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|