tests/fcntl_lock64.c

ソースコードを見る。

関数

static int sys_waitpid (pid_t pid, int *status, int options)
int main (int argc, char *argv[])


関数

static int sys_waitpid ( pid_t  pid,
int *  status,
int  options 
) [static]

fcntl_lock64.c21 行で定義されています。

00022 {
00023 #ifdef HAVE_WAITPID
00024   return waitpid(pid,status,options);
00025 #else /* USE_WAITPID */
00026   return wait4(pid, status, options, NULL);
00027 #endif /* USE_WAITPID */
00028 }

int main ( int  argc,
char *  argv[] 
)

fcntl_lock64.c33 行で定義されています。

参照先 fdstatussys_waitpid().

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                 /* check if a lock applies */
00054                 ret = fcntl(fd,F_GETLK64,&lock);
00055 
00056                 if ((ret == -1) ||
00057                     (lock.l_type == F_UNLCK)) {
00058 /*            printf("No lock conflict\n"); */
00059                         exit(1);
00060                 } else {
00061 /*            printf("lock conflict\n"); */
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         /* set a 4 byte write lock */
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 /* defined(WIFEXITED) && defined(WEXITSTATUS) */
00090         status = (status == 0) ? 0 : 1;
00091 #endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */
00092 
00093         unlink(DATA);
00094 
00095         exit(status);
00096 }


Sambaに対してSat Aug 29 21:24:31 2009に生成されました。  doxygen 1.4.7