2 * signalfd/eventfd compatibility
4 * Copyright IBM, Corp. 2008
7 * Anthony Liguori <aliguori@us.ibm.com>
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-common.h"
18 #include "qemu/compatfd.h"
19 #include "qemu/thread.h"
21 #include <sys/syscall.h>
23 struct sigfd_compat_info
29 static void *sigwait_compat(void *opaque
)
31 struct sigfd_compat_info
*info
= opaque
;
37 err
= sigwait(&info
->mask
, &sig
);
45 struct qemu_signalfd_siginfo buffer
;
48 memset(&buffer
, 0, sizeof(buffer
));
49 buffer
.ssi_signo
= sig
;
51 while (offset
< sizeof(buffer
)) {
54 len
= write(info
->fd
, (char *)&buffer
+ offset
,
55 sizeof(buffer
) - offset
);
56 if (len
== -1 && errno
== EINTR
)
69 static int qemu_signalfd_compat(const sigset_t
*mask
)
71 struct sigfd_compat_info
*info
;
75 info
= malloc(sizeof(*info
));
81 if (pipe(fds
) == -1) {
86 qemu_set_cloexec(fds
[0]);
87 qemu_set_cloexec(fds
[1]);
89 memcpy(&info
->mask
, mask
, sizeof(*mask
));
92 qemu_thread_create(&thread
, "signalfd_compat", sigwait_compat
, info
,
93 QEMU_THREAD_DETACHED
);
98 int qemu_signalfd(const sigset_t
*mask
)
100 #if defined(CONFIG_SIGNALFD)
103 ret
= syscall(SYS_signalfd
, -1, mask
, _NSIG
/ 8);
105 qemu_set_cloexec(ret
);
110 return qemu_signalfd_compat(mask
);