2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1995-12-11 11:43:29 adam
8 * Locking based on fcntl instead of flock.
9 * Setting commitEnable removed. Command line option -n can be used to
10 * prevent commit if commit setting is defined in the configuration file.
12 * Revision 1.2 1995/12/08 16:22:55 adam
13 * Work on update while servers are running. Three lock files introduced.
14 * The servers reload their registers when necessary, but they don't
15 * reestablish result sets yet.
17 * Revision 1.1 1995/12/07 17:38:47 adam
18 * Work locking mechanisms for concurrent updates/commit.
32 static int server_lock_cmt = -1;
33 static int server_lock_org = -1;
35 int zebraServerLock (int commitPhase)
37 char pathPrefix[1024];
40 zebraLockPrefix (pathPrefix);
42 if (server_lock_cmt == -1)
44 sprintf (path, "%s%s", FNAME_COMMIT_LOCK, pathPrefix);
45 if ((server_lock_cmt = open (path, O_CREAT|O_RDWR, 0666))
48 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
51 assert (server_lock_org == -1);
53 sprintf (path, "%s%s", FNAME_ORG_LOCK, pathPrefix);
54 if ((server_lock_org = open (path, O_CREAT|O_RDWR, 0666))
57 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
63 logf (LOG_LOG, "Server locks org");
64 zebraLock (server_lock_org, 0);
68 logf (LOG_LOG, "Server locks cmt");
69 zebraLock (server_lock_cmt, 0);
74 void zebraServerUnlock (int commitPhase)
76 if (server_lock_org == -1)
80 logf (LOG_LOG, "Server unlocks org");
81 zebraUnlock (server_lock_org);
85 logf (LOG_LOG, "Server unlocks cmt");
86 zebraUnlock (server_lock_cmt);
90 int zebraServerLockGetState (time_t *timep)
92 char pathPrefix[1024];
98 zebraLockPrefix (pathPrefix);
100 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
101 if (stat (path, &xstat) == -1)
104 *timep = xstat.st_ctime;
106 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
107 fd = open (path, O_RDONLY);
113 if (read (fd, buf, 2) == 0)