X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=os-posix.c;h=5c437ca12ca1b66cb515cbebd770a201ae2e91ed;hb=9e07bdf816b186632cda9651ac29bba76d299c03;hp=38c29d1afe42ff3b2e7fc28f938e5798a2551053;hpb=2d8418ba8a3ab976fd7f9749f24aab8408643a02;p=mirror_qemu.git diff --git a/os-posix.c b/os-posix.c index 38c29d1afe..5c437ca12c 100644 --- a/os-posix.c +++ b/os-posix.c @@ -31,6 +31,7 @@ /*needed for MAP_POPULATE before including qemu-options.h */ #include #include +#include #include /* Needed early for CONFIG_BSD etc. */ @@ -43,10 +44,6 @@ #include #endif -#ifdef CONFIG_EVENTFD -#include -#endif - static struct passwd *user_pwd; static const char *chroot_dir; static int daemonize; @@ -61,14 +58,9 @@ void os_setup_early_signal_handling(void) sigaction(SIGPIPE, &act, NULL); } -static void termsig_handler(int signal) -{ - qemu_system_shutdown_request(); -} - -static void sigchld_handler(int signal) +static void termsig_handler(int signal, siginfo_t *info, void *c) { - waitpid(-1, NULL, WNOHANG); + qemu_system_killed(info->si_signo, info->si_pid); } void os_setup_signal_handling(void) @@ -76,14 +68,11 @@ void os_setup_signal_handling(void) struct sigaction act; memset(&act, 0, sizeof(act)); - act.sa_handler = termsig_handler; + act.sa_sigaction = termsig_handler; + act.sa_flags = SA_SIGINFO; sigaction(SIGINT, &act, NULL); sigaction(SIGHUP, &act, NULL); sigaction(SIGTERM, &act, NULL); - - act.sa_handler = sigchld_handler; - act.sa_flags = SA_NOCLDSTOP; - sigaction(SIGCHLD, &act, NULL); } /* Find a likely location for support files using the location of the binary. @@ -134,12 +123,12 @@ char *os_find_datadir(const char *argv0) max_len = strlen(dir) + MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1; - res = qemu_mallocz(max_len); + res = g_malloc0(max_len); snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX); if (access(res, R_OK)) { snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX); if (access(res, R_OK)) { - qemu_free(res); + g_free(res); res = NULL; } } @@ -206,6 +195,11 @@ static void change_process_uid(void) fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid); exit(1); } + if (initgroups(user_pwd->pw_name, user_pwd->pw_gid) < 0) { + fprintf(stderr, "Failed to initgroups(\"%s\", %d)\n", + user_pwd->pw_name, user_pwd->pw_gid); + exit(1); + } if (setuid(user_pwd->pw_uid) < 0) { fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid); exit(1); @@ -334,34 +328,6 @@ void os_set_line_buffering(void) setvbuf(stdout, NULL, _IOLBF, 0); } -/* - * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set. - */ -int qemu_eventfd(int fds[2]) -{ -#ifdef CONFIG_EVENTFD - int ret; - - ret = eventfd(0, 0); - if (ret >= 0) { - fds[0] = ret; - qemu_set_cloexec(ret); - if ((fds[1] = dup(ret)) == -1) { - close(ret); - return -1; - } - qemu_set_cloexec(fds[1]); - return 0; - } - - if (errno != ENOSYS) { - return -1; - } -#endif - - return qemu_pipe(fds); -} - int qemu_create_pidfile(const char *filename) { char buffer[128]; @@ -373,12 +339,15 @@ int qemu_create_pidfile(const char *filename) return -1; } if (lockf(fd, F_TLOCK, 0) == -1) { + close(fd); return -1; } - len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid()); + len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid()); if (write(fd, buffer, len) != len) { + close(fd); return -1; } + close(fd); return 0; }