summaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
blob: c8f9d277ea8d8142b2b628f93b4fc14235fdb67b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Rexec program for system have fork() as vfork() with foregound option
 * Copyright (C) Vladminr Oleynik and many different people.
 */

#include <unistd.h>
#include "libbb.h"


#if defined(__uClinux__)
void vfork_daemon_rexec(int argc, char **argv, char *foreground_opt)
{
	char **vfork_args;
	int a = 0;

	vfork_args = xcalloc(sizeof(char *), argc + 3);
	while(*argv) {
	    vfork_args[a++] = *argv;
	    argv++;
	}
	vfork_args[a] = foreground_opt;
	execvp("/proc/self/exe", vfork_args);
	vfork_args[0] = "/bin/busybox";
	execv(vfork_args[0], vfork_args);
	bb_perror_msg_and_die("execv %s", vfork_args[0]);
}
#endif /* uClinux */