2 * Copyright (C) 1994-1996, 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/04 13:58:04 adam
12 * Added O_BINARY for open calls.
14 * Revision 1.6 1996/10/29 14:06:52 adam
15 * Include zebrautl.h instead of alexutil.h.
17 * Revision 1.5 1996/05/15 11:58:18 adam
18 * Changed some log messages.
20 * Revision 1.4 1996/04/10 16:01:27 quinn
21 * Fixed order of path/filename.
23 * Revision 1.3 1995/12/11 11:43:29 adam
24 * Locking based on fcntl instead of flock.
25 * Setting commitEnable removed. Command line option -n can be used to
26 * prevent commit if commit setting is defined in the configuration file.
28 * Revision 1.2 1995/12/08 16:22:55 adam
29 * Work on update while servers are running. Three lock files introduced.
30 * The servers reload their registers when necessary, but they don't
31 * reestablish result sets yet.
33 * Revision 1.1 1995/12/07 17:38:47 adam
34 * Work locking mechanisms for concurrent updates/commit.
47 static int server_lock_cmt = -1;
48 static int server_lock_org = -1;
50 int zebraServerLock (Res res, int commitPhase)
52 char pathPrefix[1024];
55 zebraLockPrefix (res, pathPrefix);
57 if (server_lock_cmt == -1)
59 sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
60 if ((server_lock_cmt = open (path, O_BINARY|O_CREAT|O_RDWR, 0666))
63 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
66 assert (server_lock_org == -1);
68 sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
69 if ((server_lock_org = open (path, O_BINARY|O_CREAT|O_RDWR, 0666))
72 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
78 logf (LOG_DEBUG, "Server locks org");
79 zebraLock (server_lock_org, 0);
83 logf (LOG_DEBUG, "Server locks cmt");
84 zebraLock (server_lock_cmt, 0);
89 void zebraServerUnlock (int commitPhase)
91 if (server_lock_org == -1)
95 logf (LOG_DEBUG, "Server unlocks org");
96 zebraUnlock (server_lock_org);
100 logf (LOG_DEBUG, "Server unlocks cmt");
101 zebraUnlock (server_lock_cmt);
105 int zebraServerLockGetState (Res res, time_t *timep)
107 char pathPrefix[1024];
113 zebraLockPrefix (res, pathPrefix);
115 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
116 if (stat (path, &xstat) == -1)
119 *timep = xstat.st_ctime;
121 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
122 fd = open (path, O_BINARY|O_RDONLY);
128 if (read (fd, buf, 2) == 0)