From 64578c0589a3a741f81fb55c16eeb882128da00b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 1998 03:08:05 +0000 Subject: merge from the autoconf2 branch to the main branch (This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21) --- source3/tests/fcntl_lock.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 source3/tests/fcntl_lock.c (limited to 'source3/tests/fcntl_lock.c') diff --git a/source3/tests/fcntl_lock.c b/source3/tests/fcntl_lock.c new file mode 100644 index 0000000000..c54479434e --- /dev/null +++ b/source3/tests/fcntl_lock.c @@ -0,0 +1,78 @@ +/* test whether fcntl locking works on this system */ + +#include +#include + +#ifdef HAVE_FCNTL_H +#include +#endif + +#ifdef HAVE_SYS_FCNTL_H +#include +#endif + +#include + +static int sys_waitpid(pid_t pid,int *status,int options) +{ +#ifdef HAVE_WAITPID + return waitpid(pid,status,options); +#else /* USE_WAITPID */ + return wait4(pid, status, options, NULL); +#endif /* USE_WAITPID */ +} + +#define DATA "conftest.fcntl" + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +/* lock a byte range in a open file */ +int main(int argc, char *argv[]) +{ + struct flock lock; + int fd, pid, ret, status=1; + + if (!(pid=fork())) { + sleep(2); + fd = open(DATA, O_RDONLY); + + if (fd == -1) exit(1); + + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 4; + lock.l_pid = getpid(); + + lock.l_type = F_WRLCK; + + /* check if a lock applies */ + ret = fcntl(fd,F_GETLK,&lock); + + if ((ret == -1) || + (lock.l_type == F_UNLCK)) { + exit(1); + } else { + exit(0); + } + } + + fd = open(DATA, O_RDWR|O_CREAT|O_TRUNC, 0600); + + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 4; + lock.l_pid = getpid(); + + /* set a 4 byte write lock */ + fcntl(fd,F_SETLK,&lock); + + sys_waitpid(pid, &status, 0); + + unlink(DATA); + + exit(status); +} -- cgit