1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/source3/tests/fcntl_lock64.c
Derrell Lipman 3a9a3ad8f9 r22731: - Fix bug #4594.
configure.in determines if -Werror-implicit-function-declaration is
  available, and if so it enables that flag if --enable-developer is
  specified.  Since the configure tests themselves did not use that flag, it
  was possible for a configure test to succeed, followed by a failed
  compilation due to a facility being available but not having a proper
  declaration in a header file.  (This bit me with readahead().)  This patch
  ensures that if implicit function declarations will kill the build, the
  feature being tested is deselected so the build will succeed.

  The autoconf manual suggests using return instead of exit in configure
  tests because the declaration for exit is often missing.  We require this
  now, since we error if prototypes are missing.  See section 5.5.1 of
  http://www.gnu.org/software/autoconf/manual/autoconf.html.  This patch makes
  these changes, because in fact, an external declaration for exit is missing
  here (and likely elsewhere).

  I've verified that the features selected (here) with the original
  configure.in and the new one are the same except for, in my case,
  readahead.  I've also confirmed that the generated Makefile is identical.

  These changes are not being applied to the 3.0.26 branch because it does not
  exhibit the initial problem this patch is supposed to solve since it doesn't
  attempt to use -Werror-implicit-function-declaration.
(This used to be commit 4d42720915)
2007-10-10 12:21:51 -05:00

101 lines
1.8 KiB
C

/* test whether 64 bit fcntl locking really works on this system */
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_SYS_FCNTL_H
#include <sys/fcntl.h>
#endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#include <errno.h>
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.fcntl64"
/* lock a byte range in a open file */
int main(int argc, char *argv[])
{
struct flock64 lock;
int fd, ret, status=1;
pid_t pid;
if (!(pid=fork())) {
sleep(2);
fd = open64(DATA, O_RDONLY);
if (fd == -1) return 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_GETLK64,&lock);
if ((ret == -1) ||
(lock.l_type == F_UNLCK)) {
/* printf("No lock conflict\n"); */
return 1;
} else {
/* printf("lock conflict\n"); */
return 0;
}
}
fd = open64(DATA, O_RDWR|O_CREAT|O_TRUNC, 0600);
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
#if defined(COMPILER_SUPPORTS_LL)
lock.l_start = 0x100000000LL;
#else
lock.l_start = 0x100000000;
#endif
lock.l_len = 4;
lock.l_pid = getpid();
/* set a 4 byte write lock */
fcntl(fd,F_SETLK64,&lock);
sys_waitpid(pid, &status, 0);
#if defined(WIFEXITED) && defined(WEXITSTATUS)
if(WIFEXITED(status)) {
status = WEXITSTATUS(status);
} else {
status = 1;
}
#else /* defined(WIFEXITED) && defined(WEXITSTATUS) */
status = (status == 0) ? 0 : 1;
#endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */
unlink(DATA);
return status;
}