1 #define _FILE_OFFSET_BITS 64
12 static int brlock(int fd, int type)
17 lock.l_whence = SEEK_SET;
22 if (fcntl(fd,F_SETLKW,&lock) != 0) {
23 printf("\nFailed to get lock type=%d in %d - %s\n",
24 type, (int)getpid(), strerror(errno));
30 static int tlock_read(int fd)
32 if (brlock(fd, F_RDLCK) != 0) return -1;
34 if (brlock(fd, F_UNLCK) != 0) return -1;
38 static int tlock_write(int fd)
40 if (brlock(fd, F_WRLCK) != 0) return -1;
41 if (brlock(fd, F_UNLCK) != 0) return -1;
45 static int tlock_transaction(int fd)
47 if (brlock(fd, F_RDLCK) != 0) return -1;
48 if (brlock(fd, F_WRLCK) != 0) return -1;
49 if (brlock(fd, F_UNLCK) != 0) return -1;
55 const char *fname = "upgradetest.dat";
61 fd = open(fname, O_CREAT|O_RDWR|O_EXCL, 0600);
66 if ((pids[0]=fork()) == 0) {
70 if ((pids[0]=fork()) == 0) {
78 tlock_transaction(fd);