diff options
| author | Laurent Vivier | 2015-10-02 14:48:09 +0200 |
|---|---|---|
| committer | Riku Voipio | 2016-01-08 10:36:12 +0100 |
| commit | e36800c91a74b656b4b4c74483863950cf9ec202 (patch) | |
| tree | a4490654ca15328ea55eebd6d2f38eb29da443ef /include/exec/user | |
| parent | Merge remote-tracking branch 'remotes/berrange/tags/pull-crypto-fixes-2015-12... (diff) | |
| download | qemu-e36800c91a74b656b4b4c74483863950cf9ec202.tar.gz qemu-e36800c91a74b656b4b4c74483863950cf9ec202.tar.xz qemu-e36800c91a74b656b4b4c74483863950cf9ec202.zip | |
linux-user: add signalfd/signalfd4 syscalls
This patch introduces a system very similar to the one used in the kernel
to attach specific functions to a given file descriptor.
In this case, we attach a specific "host_to_target()" translator to the fd
returned by signalfd() to be able to byte-swap the signalfd_siginfo
structure provided by read().
This patch allows to execute the example program given by
man signalfd(2):
#include <sys/signalfd.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
int
main(int argc, char *argv[])
{
sigset_t mask;
int sfd;
struct signalfd_siginfo fdsi;
ssize_t s;
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGQUIT);
/* Block signals so that they aren't handled
according to their default dispositions */
if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
handle_error("sigprocmask");
sfd = signalfd(-1, &mask, 0);
if (sfd == -1)
handle_error("signalfd");
for (;;) {
s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
if (s != sizeof(struct signalfd_siginfo))
handle_error("read");
if (fdsi.ssi_signo == SIGINT) {
printf("Got SIGINT\n");
} else if (fdsi.ssi_signo == SIGQUIT) {
printf("Got SIGQUIT\n");
exit(EXIT_SUCCESS);
} else {
printf("Read unexpected signal\n");
}
}
}
$ ./signalfd_demo
^CGot SIGINT
^CGot SIGINT
^\Got SIGQUIT
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'include/exec/user')
0 files changed, 0 insertions, 0 deletions
