2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1997-09-04 13:58:04 adam
8 * Added O_BINARY for open calls.
10 * Revision 1.6 1996/10/29 14:06:52 adam
11 * Include zebrautl.h instead of alexutil.h.
13 * Revision 1.5 1996/05/15 11:58:18 adam
14 * Changed some log messages.
16 * Revision 1.4 1996/04/10 16:01:27 quinn
17 * Fixed order of path/filename.
19 * Revision 1.3 1995/12/11 11:43:29 adam
20 * Locking based on fcntl instead of flock.
21 * Setting commitEnable removed. Command line option -n can be used to
22 * prevent commit if commit setting is defined in the configuration file.
24 * Revision 1.2 1995/12/08 16:22:55 adam
25 * Work on update while servers are running. Three lock files introduced.
26 * The servers reload their registers when necessary, but they don't
27 * reestablish result sets yet.
29 * Revision 1.1 1995/12/07 17:38:47 adam
30 * Work locking mechanisms for concurrent updates/commit.
43 static int server_lock_cmt = -1;
44 static int server_lock_org = -1;
46 int zebraServerLock (int commitPhase)
48 char pathPrefix[1024];
51 zebraLockPrefix (pathPrefix);
53 if (server_lock_cmt == -1)
55 sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
56 if ((server_lock_cmt = open (path, O_BINARY|O_CREAT|O_RDWR, 0666))
59 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
62 assert (server_lock_org == -1);
64 sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
65 if ((server_lock_org = open (path, O_BINARY|O_CREAT|O_RDWR, 0666))
68 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
74 logf (LOG_DEBUG, "Server locks org");
75 zebraLock (server_lock_org, 0);
79 logf (LOG_DEBUG, "Server locks cmt");
80 zebraLock (server_lock_cmt, 0);
85 void zebraServerUnlock (int commitPhase)
87 if (server_lock_org == -1)
91 logf (LOG_DEBUG, "Server unlocks org");
92 zebraUnlock (server_lock_org);
96 logf (LOG_DEBUG, "Server unlocks cmt");
97 zebraUnlock (server_lock_cmt);
101 int zebraServerLockGetState (time_t *timep)
103 char pathPrefix[1024];
109 zebraLockPrefix (pathPrefix);
111 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
112 if (stat (path, &xstat) == -1)
115 *timep = xstat.st_ctime;
117 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
118 fd = open (path, O_BINARY|O_RDONLY);
124 if (read (fd, buf, 2) == 0)