2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 1997-09-25 14:54:43 adam
8 * WIN32 files lock support.
10 * Revision 1.8 1997/09/17 12:19:15 adam
11 * Zebra version corresponds to YAZ version 1.4.
12 * Changed Zebra server so that it doesn't depend on global common_resource.
14 * Revision 1.7 1997/09/04 13:58:04 adam
15 * Added O_BINARY for open calls.
17 * Revision 1.6 1996/10/29 14:06:52 adam
18 * Include zebrautl.h instead of alexutil.h.
20 * Revision 1.5 1996/05/15 11:58:18 adam
21 * Changed some log messages.
23 * Revision 1.4 1996/04/10 16:01:27 quinn
24 * Fixed order of path/filename.
26 * Revision 1.3 1995/12/11 11:43:29 adam
27 * Locking based on fcntl instead of flock.
28 * Setting commitEnable removed. Command line option -n can be used to
29 * prevent commit if commit setting is defined in the configuration file.
31 * Revision 1.2 1995/12/08 16:22:55 adam
32 * Work on update while servers are running. Three lock files introduced.
33 * The servers reload their registers when necessary, but they don't
34 * reestablish result sets yet.
36 * Revision 1.1 1995/12/07 17:38:47 adam
37 * Work locking mechanisms for concurrent updates/commit.
54 static ZebraLockHandle server_lock_cmt = NULL;
55 static ZebraLockHandle server_lock_org = NULL;
57 int zebraServerLock (Res res, int commitPhase)
59 char pathPrefix[1024];
62 zebraLockPrefix (res, pathPrefix);
66 sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
67 if (!(server_lock_cmt = zebra_lock_create (path, 0)))
69 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
72 assert (server_lock_org == NULL);
74 sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
75 if (!(server_lock_org = zebra_lock_create (path, 0)))
77 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
83 logf (LOG_DEBUG, "Server locks org");
84 zebra_lock (server_lock_org);
88 logf (LOG_DEBUG, "Server locks cmt");
89 zebra_lock (server_lock_cmt);
94 void zebraServerUnlock (int commitPhase)
96 if (server_lock_org == NULL)
100 logf (LOG_DEBUG, "Server unlocks org");
101 zebra_unlock (server_lock_org);
105 logf (LOG_DEBUG, "Server unlocks cmt");
106 zebra_unlock (server_lock_cmt);
110 int zebraServerLockGetState (Res res, time_t *timep)
112 char pathPrefix[1024];
118 zebraLockPrefix (res, pathPrefix);
120 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
121 if (stat (path, &xstat) == -1)
124 *timep = xstat.st_ctime;
126 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
127 fd = open (path, O_BINARY|O_RDONLY);
133 if (read (fd, buf, 2) == 0)