From 92231f16298cb570c6f54684483948ac9aac41f2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 18 Feb 2017 23:15:16 +0100 Subject: [PATCH] add signal handler to determine if a child terminates --- tools/proxy.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/proxy.c b/tools/proxy.c index b7e08a0da..eeb54267c 100644 --- a/tools/proxy.c +++ b/tools/proxy.c @@ -230,7 +230,7 @@ static int is_hermit_available(void) ret = 1; break; } - PROXY_DEBUG("%s\n", line); + //PROXY_DEBUG("%s\n", line); } fclose(file); @@ -284,6 +284,18 @@ static void wait_hermit_available(void) close(fd); } +static void qemu_sigchld_handler(int sig) +{ + pid_t p; + int status; + + while ((p=waitpid(-1, &status, WNOHANG)) != -1) + { + fprintf(stderr, "Child %d died\n", p); + exit(1); + } +} + static int init_qemu(char *path) { int kvm, i = 0; @@ -295,6 +307,12 @@ static int init_qemu(char *path) char port_str[MAX_PATH]; char* qemu_str = "qemu-system-x86_64"; char* qemu_argv[] = {qemu_str, "-nographic", "-smp", "1", "-m", "2G", "-net", "nic,model=rtl8139", "-net", hostfwd, "-chardev", chardev_file, "-device", "pci-serial,chardev=gnc0", "-monitor", monitor_str, "-kernel", loader_path, "-initrd", path, "-append", cpufreq(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + struct sigaction sa; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = qemu_sigchld_handler; + + sigaction(SIGCHLD, &sa, NULL); str = getenv("HERMIT_CPUS"); if (str)