2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1996-05-15 11:58:18 adam
8 * Changed some log messages.
10 * Revision 1.4 1996/04/10 16:01:27 quinn
11 * Fixed order of path/filename.
13 * Revision 1.3 1995/12/11 11:43:29 adam
14 * Locking based on fcntl instead of flock.
15 * Setting commitEnable removed. Command line option -n can be used to
16 * prevent commit if commit setting is defined in the configuration file.
18 * Revision 1.2 1995/12/08 16:22:55 adam
19 * Work on update while servers are running. Three lock files introduced.
20 * The servers reload their registers when necessary, but they don't
21 * reestablish result sets yet.
23 * Revision 1.1 1995/12/07 17:38:47 adam
24 * Work locking mechanisms for concurrent updates/commit.
38 static int server_lock_cmt = -1;
39 static int server_lock_org = -1;
41 int zebraServerLock (int commitPhase)
43 char pathPrefix[1024];
46 zebraLockPrefix (pathPrefix);
48 if (server_lock_cmt == -1)
50 sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
51 if ((server_lock_cmt = open (path, O_CREAT|O_RDWR, 0666))
54 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
57 assert (server_lock_org == -1);
59 sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
60 if ((server_lock_org = open (path, O_CREAT|O_RDWR, 0666))
63 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
69 logf (LOG_DEBUG, "Server locks org");
70 zebraLock (server_lock_org, 0);
74 logf (LOG_DEBUG, "Server locks cmt");
75 zebraLock (server_lock_cmt, 0);
80 void zebraServerUnlock (int commitPhase)
82 if (server_lock_org == -1)
86 logf (LOG_DEBUG, "Server unlocks org");
87 zebraUnlock (server_lock_org);
91 logf (LOG_DEBUG, "Server unlocks cmt");
92 zebraUnlock (server_lock_cmt);
96 int zebraServerLockGetState (time_t *timep)
98 char pathPrefix[1024];
104 zebraLockPrefix (pathPrefix);
106 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
107 if (stat (path, &xstat) == -1)
110 *timep = xstat.st_ctime;
112 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
113 fd = open (path, O_RDONLY);
119 if (read (fd, buf, 2) == 0)