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