2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1996-10-29 14:06:52 adam
8 * Include zebrautl.h instead of alexutil.h.
10 * Revision 1.5 1996/05/15 11:58:18 adam
11 * Changed some log messages.
13 * Revision 1.4 1996/04/10 16:01:27 quinn
14 * Fixed order of path/filename.
16 * Revision 1.3 1995/12/11 11:43:29 adam
17 * Locking based on fcntl instead of flock.
18 * Setting commitEnable removed. Command line option -n can be used to
19 * prevent commit if commit setting is defined in the configuration file.
21 * Revision 1.2 1995/12/08 16:22:55 adam
22 * Work on update while servers are running. Three lock files introduced.
23 * The servers reload their registers when necessary, but they don't
24 * reestablish result sets yet.
26 * Revision 1.1 1995/12/07 17:38:47 adam
27 * Work locking mechanisms for concurrent updates/commit.
40 static int server_lock_cmt = -1;
41 static int server_lock_org = -1;
43 int zebraServerLock (int commitPhase)
45 char pathPrefix[1024];
48 zebraLockPrefix (pathPrefix);
50 if (server_lock_cmt == -1)
52 sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
53 if ((server_lock_cmt = open (path, O_CREAT|O_RDWR, 0666))
56 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
59 assert (server_lock_org == -1);
61 sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
62 if ((server_lock_org = open (path, O_CREAT|O_RDWR, 0666))
65 logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
71 logf (LOG_DEBUG, "Server locks org");
72 zebraLock (server_lock_org, 0);
76 logf (LOG_DEBUG, "Server locks cmt");
77 zebraLock (server_lock_cmt, 0);
82 void zebraServerUnlock (int commitPhase)
84 if (server_lock_org == -1)
88 logf (LOG_DEBUG, "Server unlocks org");
89 zebraUnlock (server_lock_org);
93 logf (LOG_DEBUG, "Server unlocks cmt");
94 zebraUnlock (server_lock_cmt);
98 int zebraServerLockGetState (time_t *timep)
100 char pathPrefix[1024];
106 zebraLockPrefix (pathPrefix);
108 sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
109 if (stat (path, &xstat) == -1)
112 *timep = xstat.st_ctime;
114 sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
115 fd = open (path, O_RDONLY);
121 if (read (fd, buf, 2) == 0)