00001
00002
00003 #if defined(HAVE_UNISTD_H)
00004 #include <unistd.h>
00005 #endif
00006
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <sys/types.h>
00010
00011 #ifdef HAVE_FCNTL_H
00012 #include <fcntl.h>
00013 #endif
00014
00015 #ifdef HAVE_SYS_FCNTL_H
00016 #include <sys/fcntl.h>
00017 #endif
00018
00019 #include <errno.h>
00020
00021 static int sys_waitpid(pid_t pid,int *status,int options)
00022 {
00023 #ifdef HAVE_WAITPID
00024 return waitpid(pid,status,options);
00025 #else
00026 return wait4(pid, status, options, NULL);
00027 #endif
00028 }
00029
00030 #define DATA "conftest.fcntl64"
00031
00032
00033 int main(int argc, char *argv[])
00034 {
00035 struct flock64 lock;
00036 int fd, ret, status=1;
00037 pid_t pid;
00038
00039 if (!(pid=fork())) {
00040 sleep(2);
00041 fd = open64(DATA, O_RDONLY);
00042
00043 if (fd == -1) exit(1);
00044
00045 lock.l_type = F_WRLCK;
00046 lock.l_whence = SEEK_SET;
00047 lock.l_start = 0;
00048 lock.l_len = 4;
00049 lock.l_pid = getpid();
00050
00051 lock.l_type = F_WRLCK;
00052
00053
00054 ret = fcntl(fd,F_GETLK64,&lock);
00055
00056 if ((ret == -1) ||
00057 (lock.l_type == F_UNLCK)) {
00058
00059 exit(1);
00060 } else {
00061
00062 exit(0);
00063 }
00064 }
00065
00066 fd = open64(DATA, O_RDWR|O_CREAT|O_TRUNC, 0600);
00067
00068 lock.l_type = F_WRLCK;
00069 lock.l_whence = SEEK_SET;
00070 #if defined(COMPILER_SUPPORTS_LL)
00071 lock.l_start = 0x100000000LL;
00072 #else
00073 lock.l_start = 0x100000000;
00074 #endif
00075 lock.l_len = 4;
00076 lock.l_pid = getpid();
00077
00078
00079 fcntl(fd,F_SETLK64,&lock);
00080
00081 sys_waitpid(pid, &status, 0);
00082
00083 #if defined(WIFEXITED) && defined(WEXITSTATUS)
00084 if(WIFEXITED(status)) {
00085 status = WEXITSTATUS(status);
00086 } else {
00087 status = 1;
00088 }
00089 #else
00090 status = (status == 0) ? 0 : 1;
00091 #endif
00092
00093 unlink(DATA);
00094
00095 exit(status);
00096 }