+static int register_lock (ZServerInfo *zi)
+{
+ time_t lastChange;
+ int state = zebraServerLockGetState(&lastChange);
+
+ switch (state)
+ {
+ case 'c':
+ state = 1;
+ break;
+ default:
+ state = 0;
+ }
+ zebraServerLock (state);
+ if (zi->registerState == state)
+ {
+ if (zi->registerChange >= lastChange)
+ return 0;
+ logf (LOG_LOG, "Register completely updated since last access");
+ }
+ else if (zi->registerState == -1)
+ logf (LOG_LOG, "Reading register using state %d pid=%ld", state,
+ (long) getpid());
+ else
+ logf (LOG_LOG, "Register has changed state from %d to %d",
+ zi->registerState, state);
+ zi->registerChange = lastChange;
+ if (zi->records)
+ {
+ dict_close (zi->wordDict);
+ is_close (zi->wordIsam);
+ rec_close (&zi->records);
+ }
+ bf_cache (state);
+ zi->registerState = state;
+ zi->records = rec_open (0);
+ if (!(zi->wordDict = dict_open (FNAME_WORD_DICT, 40, 0)))
+ return -1;
+ if (!(zi->wordIsam = is_open (FNAME_WORD_ISAM, key_compare, 0,
+ sizeof (struct it_key))))
+ return -1;
+ return 0;
+}
+
+static void register_unlock (ZServerInfo *zi)
+{
+ static int waitSec = -1;
+
+ if (waitSec == -1)
+ {
+ char *s = res_get (common_resource, "debugRequestWait");
+ if (s)
+ waitSec = atoi (s);
+ else
+ waitSec = 0;
+ }
+ if (waitSec > 0)
+ sleep (waitSec);
+ if (zi->registerState != -1)
+ zebraServerUnlock (zi->registerState);
+}
+