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/thread.h"
19 #include <sys/syscall.h>
21 struct sigfd_compat_info
27 static void *sigwait_compat(void *opaque
)
29 struct sigfd_compat_info
*info
= opaque
;
35 err
= sigwait(&info
->mask
, &sig
);
43 struct qemu_signalfd_siginfo buffer
;
46 memset(&buffer
, 0, sizeof(buffer
));
47 buffer
.ssi_signo
= sig
;
49 while (offset
< sizeof(buffer
)) {
52 len
= write(info
->fd
, (char *)&buffer
+ offset
,
53 sizeof(buffer
) - offset
);
54 if (len
== -1 && errno
== EINTR
)
67 static int qemu_signalfd_compat(const sigset_t
*mask
)
69 struct sigfd_compat_info
*info
;
73 info
= malloc(sizeof(*info
));
79 if (pipe(fds
) == -1) {
84 qemu_set_cloexec(fds
[0]);
85 qemu_set_cloexec(fds
[1]);
87 memcpy(&info
->mask
, mask
, sizeof(*mask
));
90 qemu_thread_create(&thread
, "signalfd_compat", sigwait_compat
, info
,
91 QEMU_THREAD_DETACHED
);
96 int qemu_signalfd(const sigset_t
*mask
)
98 #if defined(CONFIG_SIGNALFD)
101 ret
= syscall(SYS_signalfd
, -1, mask
, _NSIG
/ 8);
103 qemu_set_cloexec(ret
);
108 return qemu_signalfd_compat(mask
);