2 * signalfd/eventfd compatibility
4 * Copyright IBM, Corp. 2008
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "qemu/thread.h"
19 #if defined(CONFIG_SIGNALFD)
20 #include <sys/signalfd.h>
23 struct sigfd_compat_info {
28 static void *sigwait_compat(void *opaque)
30 struct sigfd_compat_info *info = opaque;
36 err = sigwait(&info->mask, &sig);
44 struct qemu_signalfd_siginfo buffer;
45 memset(&buffer, 0, sizeof(buffer));
46 buffer.ssi_signo = sig;
48 if (qemu_write_full(info->fd, &buffer, sizeof(buffer)) != sizeof(buffer)) {
55 static int qemu_signalfd_compat(const sigset_t *mask)
57 struct sigfd_compat_info *info;
61 info = g_malloc(sizeof(*info));
63 if (pipe(fds) == -1) {
68 qemu_set_cloexec(fds[0]);
69 qemu_set_cloexec(fds[1]);
71 memcpy(&info->mask, mask, sizeof(*mask));
74 qemu_thread_create(&thread, "signalfd_compat", sigwait_compat, info,
75 QEMU_THREAD_DETACHED);
80 int qemu_signalfd(const sigset_t *mask)
82 #if defined(CONFIG_SIGNALFD)
85 ret = signalfd(-1, mask, SFD_CLOEXEC);
91 return qemu_signalfd_compat(mask);