From: Tom Hughes Date: Thu, 29 Jul 2004 21:20:11 +0000 (+0000) Subject: Modified the fcntl system call so that only those reason codes which X-Git-Tag: svn/VALGRIND_2_2_0~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1afbb3fc45135a6774643b4f533dead2e455b5b5;p=thirdparty%2Fvalgrind.git Modified the fcntl system call so that only those reason codes which can block (ie F_SETLKW) are treated as blocking. This resolves the F_SETOWN problem described in bug #85969. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2535 --- diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c index 2b4f89a6bf..d6f03cffa5 100644 --- a/coregrind/vg_syscalls.c +++ b/coregrind/vg_syscalls.c @@ -2117,6 +2117,8 @@ PRE(fcntl) { /* int fcntl(int fd, int cmd, int arg); */ MAYBE_PRINTF("fcntl ( %d, %d, %d )\n",arg1,arg2,arg3); + if (arg2 == VKI_F_SETLKW) + tst->sys_flags |= MayBlock; } POST(fcntl) @@ -2156,6 +2158,8 @@ PRE(fcntl64) { /* int fcntl64(int fd, int cmd, int arg); */ MAYBE_PRINTF("fcntl64 ( %d, %d, %d )\n", arg1,arg2,arg3); + if (arg2 == VKI_F_SETLKW || arg2 == VKI_F_SETLKW64) + tst->sys_flags |= MayBlock; } POST(fcntl64) @@ -5644,12 +5648,12 @@ static const struct sys_info sys_info[] = { SYSBA(close, 0), SYSBA(dup, 0), SYSBA(dup2, 0), - SYSBA(fcntl, MayBlock), + SYSBA(fcntl, 0), SYSB_(fchdir, 0), SYSB_(fchown32, 0), SYSB_(fchown, 0), SYSB_(fchmod, 0), - SYSBA(fcntl64, MayBlock), + SYSBA(fcntl64, 0), SYSBA(fstat, 0), SYSBA(fork, 0), SYSB_(fsync, MayBlock), diff --git a/include/vg_kerneliface.h b/include/vg_kerneliface.h index 6a8c30d84d..79580fb588 100644 --- a/include/vg_kerneliface.h +++ b/include/vg_kerneliface.h @@ -546,6 +546,12 @@ struct vki_timeval { #define VKI_F_SETFD 2 /* set/clear close_on_exec */ #define VKI_F_GETFL 3 /* get file->f_flags */ #define VKI_F_SETFL 4 /* set file->f_flags */ +#define VKI_F_GETLK 5 +#define VKI_F_SETLK 6 +#define VKI_F_SETLKW 7 +#define VKI_F_GETLK64 12 /* using 'struct flock64' */ +#define VKI_F_SETLK64 13 +#define VKI_F_SETLKW64 14 /* for F_[GET|SET]FL */ #define VKI_FD_CLOEXEC 1 /* actually anything with low bit set goes */ diff --git a/none/tests/.cvsignore b/none/tests/.cvsignore index af94caa8c8..ecc0a99227 100644 --- a/none/tests/.cvsignore +++ b/none/tests/.cvsignore @@ -13,6 +13,7 @@ dastest discard exec-sigmask execve +fcntl_setown floored fork fpu_lazy_eflags diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index b929d83942..6dc2564e74 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -28,6 +28,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ discard.vgtest \ exec-sigmask.vgtest exec-sigmask.stdout.exp exec-sigmask.stderr.exp \ execve.vgtest execve.stdout.exp execve.stderr.exp \ + fcntl_setown.vgtest fcntl_setown.stdout.exp fcntl_setown.stderr.exp \ floored.stderr.exp floored.stdout.exp \ floored.vgtest \ fork.stderr.exp fork.stdout.exp fork.vgtest \ @@ -68,7 +69,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ check_PROGRAMS = \ args badseg bitfield1 bt_everything bt_literal closeall coolo_strlen \ - cpuid dastest discard exec-sigmask execve floored fork \ + cpuid dastest discard exec-sigmask execve fcntl_setown floored fork \ fpu_lazy_eflags fucomip $(INSN_TESTS) \ int munmap_exe map_unmap mremap rcl_assert rcrl readline1 \ resolv rlimit_nofile seg_override sem semlimit sha1_test \ @@ -92,6 +93,7 @@ dastest_SOURCES = dastest_c.c dastest_s.s discard_SOURCES = discard.c exec_sigmask_SOURCES = exec-sigmask.c execve_SOURCES = execve.c +fcntl_setown_SOURCES = fcntl_setown.c fork_SOURCES = fork.c floored_SOURCES = floored.c floored_LDADD = -lm diff --git a/none/tests/fcntl_setown.c b/none/tests/fcntl_setown.c new file mode 100644 index 0000000000..b0ccf64e6e --- /dev/null +++ b/none/tests/fcntl_setown.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int s; + + if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) + { + perror("socket"); + exit(1); + } + + if (fcntl(s, F_SETOWN, getpid()) < 0) + { + perror("fcntl(F_SETOWN)"); + exit(1); + } + + if (close(s) < 0) + { + perror("close"); + exit(1); + } + + exit(0); +} diff --git a/none/tests/fcntl_setown.stderr.exp b/none/tests/fcntl_setown.stderr.exp new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/none/tests/fcntl_setown.stderr.exp @@ -0,0 +1,2 @@ + + diff --git a/none/tests/fcntl_setown.stdout.exp b/none/tests/fcntl_setown.stdout.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/none/tests/fcntl_setown.vgtest b/none/tests/fcntl_setown.vgtest new file mode 100644 index 0000000000..12adeb8bf6 --- /dev/null +++ b/none/tests/fcntl_setown.vgtest @@ -0,0 +1 @@ +prog: fcntl_setown