2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1996-04-10 16:01:27 quinn
8 * Fixed order of path/filename.
10 * Revision 1.3 1995/12/11 11:43:29 adam
11 * Locking based on fcntl instead of flock.
12 * Setting commitEnable removed. Command line option -n can be used to
13 * prevent commit if commit setting is defined in the configuration file.
15 * Revision 1.2 1995/12/08 16:22:55 adam
16 * Work on update while servers are running. Three lock files introduced.
17 * The servers reload their registers when necessary, but they don't
18 * reestablish result sets yet.
20 * Revision 1.1 1995/12/07 17:38:47 adam
21 * Work locking mechanisms for concurrent updates/commit.
35 static int server_lock_cmt = -1;
36 static int server_lock_org = -1;
38 int zebraServerLock (int commitPhase)
40 char pathPrefix[1024];
43 zebraLockPrefix (pathPrefix);
45 if (server_lock_cmt == -1)
47 sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
48 if ((server_lock_cmt = open (path, O_CREAT|O_RDWR, 0666))
51 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
54 assert (server_lock_org == -1);
56 sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
57 if ((server_lock_org = open (path, O_CREAT|O_RDWR, 0666))
60 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
66 logf (LOG_LOG, "Server locks org");
67 zebraLock (server_lock_org, 0);
71 logf (LOG_LOG, "Server locks cmt");
72 zebraLock (server_lock_cmt, 0);
77 void zebraServerUnlock (int commitPhase)
79 if (server_lock_org == -1)
83 logf (LOG_LOG, "Server unlocks org");
84 zebraUnlock (server_lock_org);
88 logf (LOG_LOG, "Server unlocks cmt");
89 zebraUnlock (server_lock_cmt);
93 int zebraServerLockGetState (time_t *timep)
95 char pathPrefix[1024];
101 zebraLockPrefix (pathPrefix);
103 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
104 if (stat (path, &xstat) == -1)
107 *timep = xstat.st_ctime;
109 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
110 fd = open (path, O_RDONLY);
116 if (read (fd, buf, 2) == 0)