2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1995-12-13 08:46:10 adam
8 * Locking uses F_WRLCK and F_RDLCK again!
10 * Revision 1.3 1995/12/12 16:00:57 adam
11 * System call sync(2) used after update/commit.
12 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
15 * Revision 1.2 1995/12/11 11:43:29 adam
16 * Locking based on fcntl instead of flock.
17 * Setting commitEnable removed. Command line option -n can be used to
18 * prevent commit if commit setting is defined in the configuration file.
20 * Revision 1.1 1995/12/07 17:38:47 adam
21 * Work locking mechanisms for concurrent updates/commit.
29 #include <sys/types.h>
35 static char *lockDir = NULL;
37 void zebraLockPrefix (char *pathPrefix)
40 lockDir = res_get_def (common_resource, "lockDir", "");
43 strcpy (pathPrefix, lockDir);
44 if (*pathPrefix && pathPrefix[strlen(pathPrefix)-1] != '/')
45 strcat (pathPrefix, "/");
48 static int intLock (int fd, int type, int cmd)
52 area.l_whence = SEEK_SET;
53 area.l_len = area.l_start = 0L;
54 return fcntl (fd, cmd, &area);
57 int zebraLock (int fd, int wr)
60 return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLKW);
62 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLKW);
66 int zebraLockNB (int fd, int wr)
69 return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLK);
71 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLK);
75 int zebraUnlock (int fd)
77 return intLock (fd, F_UNLCK, F_SETLKW);