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
This commit is contained in:
Tom Hughes 2004-07-29 21:20:11 +00:00
parent b5f08d077f
commit 1afbb3fc45
8 changed files with 49 additions and 3 deletions

View File

@ -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),

View File

@ -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 */

View File

@ -13,6 +13,7 @@ dastest
discard
exec-sigmask
execve
fcntl_setown
floored
fork
fpu_lazy_eflags

View File

@ -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

30
none/tests/fcntl_setown.c Normal file
View File

@ -0,0 +1,30 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>
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);
}

View File

@ -0,0 +1,2 @@

View File

View File

@ -0,0 +1 @@
prog: fcntl_setown