2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-12-08 16:22:55 adam
8 * Work on update while servers are running. Three lock files introduced.
9 * The servers reload their registers when necessary, but they don't
10 * reestablish result sets yet.
12 * Revision 1.1 1995/12/07 17:38:47 adam
13 * Work locking mechanisms for concurrent updates/commit.
28 static int server_lock_cmt = -1;
29 static int server_lock_org = -1;
31 int zebraServerLock (int commitPhase)
33 char pathPrefix[1024];
36 zebraLockPrefix (pathPrefix);
38 if (server_lock_cmt == -1)
40 sprintf (path, "%s%s", FNAME_COMMIT_LOCK, pathPrefix);
41 if ((server_lock_cmt = open (path, O_CREAT|O_RDWR, 0666))
44 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
47 assert (server_lock_org == -1);
49 sprintf (path, "%s%s", FNAME_ORG_LOCK, pathPrefix);
50 if ((server_lock_org = open (path, O_CREAT|O_RDWR, 0666))
53 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
59 logf (LOG_LOG, "Server locks org");
60 flock (server_lock_org, LOCK_SH);
64 logf (LOG_LOG, "Server locks cmt");
65 flock (server_lock_cmt, LOCK_SH);
70 void zebraServerUnlock (int commitPhase)
72 if (server_lock_org == -1)
76 logf (LOG_LOG, "Server unlocks org");
77 flock (server_lock_org, LOCK_UN);
81 logf (LOG_LOG, "Server unlocks cmt");
82 flock (server_lock_cmt, LOCK_UN);
86 int zebraServerLockGetState (time_t *timep)
88 char pathPrefix[1024];
94 zebraLockPrefix (pathPrefix);
96 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
97 if (stat (path, &xstat) == -1)
100 *timep = xstat.st_ctime;
102 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
103 fd = open (path, O_RDONLY);
109 if (read (fd, buf, 2) == 0)