eventfd2: fix flags decoding

* configure.ac (AC_CHECK_HEADERS): Add sys/eventfd.h.
* eventfd.c: Include <fcntl.h>.
[HAVE_SYS_EVENTFD_H] Include <sys/eventfd.h>.
Include "xlat/efd_flags.h".
(do_eventfd): Use efd_flags for flags decoding.
* xlat/efd_flags.in: New file.
* tests/eventfd.c: New file.
* tests/eventfd.expected: Likewise.
* tests/eventfd.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add eventfd.
(TESTS): Add eventfd.test.
(EXTRA_DIST): Add eventfd.expected.
* tests/.gitignore: Add eventfd.
This commit is contained in:
Дмитрий Левин 2015-08-01 21:08:13 +00:00
parent 00cc35079e
commit c8cba990a2
8 changed files with 47 additions and 1 deletions

View File

@ -268,6 +268,7 @@ AC_CHECK_HEADERS(m4_normalize([
stropts.h
sys/conf.h
sys/epoll.h
sys/eventfd.h
sys/fanotify.h
sys/ioctl.h
sys/reg.h

View File

@ -1,4 +1,10 @@
#include "defs.h"
#include <fcntl.h>
#ifdef HAVE_SYS_EVENTFD_H
# include <sys/eventfd.h>
#endif
#include "xlat/efd_flags.h"
static int
do_eventfd(struct tcb *tcp, int flags_arg)
@ -6,7 +12,7 @@ do_eventfd(struct tcb *tcp, int flags_arg)
tprintf("%u", (unsigned int) tcp->u_arg[0]);
if (flags_arg >= 0) {
tprints(", ");
printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
printflags(efd_flags, tcp->u_arg[flags_arg], "EFD_???");
}
return RVAL_DECODED | RVAL_FD;

1
tests/.gitignore vendored
View File

@ -1,5 +1,6 @@
bpf
caps
eventfd
execve
execveat
fanotify_mark

View File

@ -11,6 +11,7 @@ AM_CPPFLAGS = -I$(top_builddir)/$(OS)/$(ARCH) \
check_PROGRAMS = \
bpf \
caps \
eventfd \
execve \
execveat \
fanotify_mark \
@ -71,6 +72,7 @@ TESTS = \
bpf.test \
caps.test \
dumpio.test \
eventfd.test \
execve.test \
execveat.test \
fanotify_mark.test \
@ -129,6 +131,7 @@ AM_TEST_LOG_FLAGS = STRACE_ARCH=$(ARCH) $(srcdir)/run.sh
EXTRA_DIST = init.sh run.sh match.awk \
caps.awk \
dumpio.expected \
eventfd.expected \
execve.expected \
execve-v.expected \
execveat.expected \

19
tests/eventfd.c Normal file
View File

@ -0,0 +1,19 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <fcntl.h>
#include <unistd.h>
#include <sys/syscall.h>
int
main(void)
{
#ifdef __NR_eventfd2
(void) close(0);
return syscall(__NR_eventfd2, -1L, 1 | O_CLOEXEC | O_NONBLOCK) == 0 ?
0 : 77;
#else
return 77;
#endif
}

2
tests/eventfd.expected Normal file
View File

@ -0,0 +1,2 @@
eventfd2(4294967295, EFD_SEMAPHORE|EFD_CLOEXEC|EFD_NONBLOCK) = 0
+++ exited with 0 +++

11
tests/eventfd.test Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
# Check eventfd2 syscall decoding.
. "${srcdir=.}/init.sh"
run_prog
run_strace -e eventfd2 $args
match_diff
exit 0

3
xlat/efd_flags.in Normal file
View File

@ -0,0 +1,3 @@
EFD_SEMAPHORE 1
EFD_CLOEXEC O_CLOEXEC
EFD_NONBLOCK O_NONBLOCK