2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1997-09-17 12:19:15 adam
8 * Zebra version corresponds to YAZ version 1.4.
9 * Changed Zebra server so that it doesn't depend on global common_resource.
11 * Revision 1.7 1997/09/09 13:38:08 adam
12 * Partial port to WIN95/NT.
14 * Revision 1.6 1996/10/29 14:08:14 adam
15 * Uses resource lockDir instead of lockPath.
17 * Revision 1.5 1996/03/26 16:01:13 adam
18 * New setting lockPath: directory of various lock files.
20 * Revision 1.4 1995/12/13 08:46:10 adam
21 * Locking uses F_WRLCK and F_RDLCK again!
23 * Revision 1.3 1995/12/12 16:00:57 adam
24 * System call sync(2) used after update/commit.
25 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
28 * Revision 1.2 1995/12/11 11:43:29 adam
29 * Locking based on fcntl instead of flock.
30 * Setting commitEnable removed. Command line option -n can be used to
31 * prevent commit if commit setting is defined in the configuration file.
33 * Revision 1.1 1995/12/07 17:38:47 adam
34 * Work locking mechanisms for concurrent updates/commit.
42 #include <sys/types.h>
51 static char *lockDir = NULL;
53 void zebraLockPrefix (Res res, char *pathPrefix)
56 lockDir = res_get_def (res, "lockDir", "");
59 strcpy (pathPrefix, lockDir);
60 if (*pathPrefix && pathPrefix[strlen(pathPrefix)-1] != '/')
61 strcat (pathPrefix, "/");
64 static int intLock (int fd, int type, int cmd)
68 area.l_whence = SEEK_SET;
69 area.l_len = area.l_start = 0L;
70 return fcntl (fd, cmd, &area);
73 int zebraLock (int fd, int wr)
76 return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLKW);
78 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLKW);
82 int zebraLockNB (int fd, int wr)
85 return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLK);
87 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLK);
91 int zebraUnlock (int fd)
93 return intLock (fd, F_UNLCK, F_SETLKW);