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