mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
slirp: Avoid zombie processes after fork_exec
Slirp uses fork_exec for spawning service processes, and QEMU uses this for running smbd. As SIGCHLD is not handled, these processes become zombies on termination. Fix this by installing a proper signal handler, but also make sure we disable the signal while waiting on forked network setup/shutdown scripts. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Mark McLoughlin <markmc@redhat.com>
This commit is contained in:
parent
c27ff60871
commit
7c3370d4fe
2 changed files with 44 additions and 27 deletions
58
net.c
58
net.c
|
@ -1134,38 +1134,46 @@ static int tap_open(char *ifname, int ifname_size)
|
|||
|
||||
static int launch_script(const char *setup_script, const char *ifname, int fd)
|
||||
{
|
||||
sigset_t oldmask, mask;
|
||||
int pid, status;
|
||||
char *args[3];
|
||||
char **parg;
|
||||
|
||||
/* try to launch network script */
|
||||
pid = fork();
|
||||
if (pid >= 0) {
|
||||
if (pid == 0) {
|
||||
int open_max = sysconf (_SC_OPEN_MAX), i;
|
||||
for (i = 0; i < open_max; i++)
|
||||
if (i != STDIN_FILENO &&
|
||||
i != STDOUT_FILENO &&
|
||||
i != STDERR_FILENO &&
|
||||
i != fd)
|
||||
close(i);
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &mask, &oldmask);
|
||||
|
||||
parg = args;
|
||||
*parg++ = (char *)setup_script;
|
||||
*parg++ = (char *)ifname;
|
||||
*parg++ = NULL;
|
||||
execv(setup_script, args);
|
||||
_exit(1);
|
||||
}
|
||||
while (waitpid(pid, &status, 0) != pid);
|
||||
if (!WIFEXITED(status) ||
|
||||
WEXITSTATUS(status) != 0) {
|
||||
fprintf(stderr, "%s: could not launch network script\n",
|
||||
setup_script);
|
||||
return -1;
|
||||
/* try to launch network script */
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
int open_max = sysconf(_SC_OPEN_MAX), i;
|
||||
|
||||
for (i = 0; i < open_max; i++) {
|
||||
if (i != STDIN_FILENO &&
|
||||
i != STDOUT_FILENO &&
|
||||
i != STDERR_FILENO &&
|
||||
i != fd) {
|
||||
close(i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
parg = args;
|
||||
*parg++ = (char *)setup_script;
|
||||
*parg++ = (char *)ifname;
|
||||
*parg++ = NULL;
|
||||
execv(setup_script, args);
|
||||
_exit(1);
|
||||
} else if (pid > 0) {
|
||||
while (waitpid(pid, &status, 0) != pid) {
|
||||
/* loop */
|
||||
}
|
||||
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "%s: could not launch network script\n", setup_script);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int net_tap_init(VLANState *vlan, const char *model,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue