* Sebastian Hammer, Adam Dickmeiss
*
* $Log: index.h,v $
- * Revision 1.53 1997-09-25 14:54:43 adam
+ * Revision 1.54 1997-09-29 09:08:36 adam
+ * Revised locking system to be thread safe for the server.
+ *
+ * Revision 1.53 1997/09/25 14:54:43 adam
* WIN32 files lock support.
*
* Revision 1.52 1997/09/22 12:39:06 adam
void rec_prstat (void);
-void zebraLockPrefix (Res res, char *pathPrefix);
-
void zebraIndexLockMsg (const char *str);
void zebraIndexUnlock (void);
void zebraIndexLock (BFiles bfs, int commitNow, const char *rval);
int zebra_lock_nb (ZebraLockHandle h);
int zebra_unlock (ZebraLockHandle h);
int zebra_lock_fd (ZebraLockHandle h);
+void zebra_lock_prefix (Res res, char *dst);
void init_charmap(Res res);
const char **map_chrs_input(void *vp, const char **from, int len);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lockidx.c,v $
- * Revision 1.12 1997-09-25 14:54:43 adam
+ * Revision 1.13 1997-09-29 09:08:36 adam
+ * Revised locking system to be thread safe for the server.
+ *
+ * Revision 1.12 1997/09/25 14:54:43 adam
* WIN32 files lock support.
*
* Revision 1.11 1997/09/17 12:19:15 adam
int zebraIndexWait (int commitPhase)
{
- char pathPrefix[1024];
- char path[1024];
ZebraLockHandle h;
-
- zebraLockPrefix (common_resource, pathPrefix);
if (server_lock_cmt)
zebra_unlock (server_lock_cmt);
else
{
- sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
+ char path[1024];
+
+ zebra_lock_prefix (common_resource, path);
+ strcat (path, FNAME_COMMIT_LOCK);
server_lock_cmt = zebra_lock_create (path, 1);
if (!server_lock_cmt)
{
zebra_unlock (server_lock_org);
else
{
- sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
+ char path[1024];
+
+ zebra_lock_prefix (common_resource, path);
+ strcat (path, FNAME_ORG_LOCK);
server_lock_org = zebra_lock_create (path, 1);
if (!server_lock_org)
{
void zebraIndexLockMsg (const char *str)
{
char path[1024];
- char pathPrefix[1024];
int l, r, fd;
assert (server_lock_main);
logf (LOG_FATAL|LOG_ERRNO, "write lock file");
exit (1);
}
- zebraLockPrefix (common_resource, pathPrefix);
- sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
+ zebra_lock_prefix (common_resource, path);
+ strcat (path, FNAME_TOUCH_TIME);
fd = creat (path, 0666);
close (fd);
}
void zebraIndexUnlock (void)
{
char path[1024];
- char pathPrefix[1024];
-
- zebraLockPrefix (common_resource, pathPrefix);
- sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
+
+ zebra_lock_prefix (common_resource, path);
+ strcat (path, FNAME_MAIN_LOCK);
unlink (path);
}
void zebraIndexLock (BFiles bfs, int commitNow, const char *rval)
{
char path[1024];
- char pathPrefix[1024];
char buf[256];
int r;
if (server_lock_main)
return ;
- zebraLockPrefix (common_resource, pathPrefix);
- sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
+
+ zebra_lock_prefix (common_resource, path);
+ strcat (path, FNAME_MAIN_LOCK);
while (1)
{
server_lock_main = zebra_lock_create (path, 2);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: locksrv.c,v $
- * Revision 1.9 1997-09-25 14:54:43 adam
+ * Revision 1.10 1997-09-29 09:08:36 adam
+ * Revised locking system to be thread safe for the server.
+ *
+ * Revision 1.9 1997/09/25 14:54:43 adam
* WIN32 files lock support.
*
* Revision 1.8 1997/09/17 12:19:15 adam
#include "zserver.h"
-static ZebraLockHandle server_lock_cmt = NULL;
-static ZebraLockHandle server_lock_org = NULL;
+int zebra_server_lock_init (ZServerInfo *zi)
+{
+ char path_prefix[1024];
+
+ assert (zi->res);
+ zi->server_lock_cmt = NULL;
+ zi->server_lock_org = NULL;
+
+ zebra_lock_prefix (zi->res, path_prefix);
+ zi->server_path_prefix = xmalloc (strlen(path_prefix)+1);
+ strcpy (zi->server_path_prefix, path_prefix);
-int zebraServerLock (Res res, int commitPhase)
+ logf (LOG_DEBUG, "Locking system initialized");
+ return 0;
+}
+
+int zebra_server_lock_destroy (ZServerInfo *zi)
{
- char pathPrefix[1024];
- char path[1024];
-
- zebraLockPrefix (res, pathPrefix);
+ xfree (zi->server_path_prefix);
+ zebra_lock_destroy (zi->server_lock_cmt);
+ zebra_lock_destroy (zi->server_lock_org);
+ logf (LOG_DEBUG, "Locking system destroyed");
+ return 0;
+}
- if (!server_lock_cmt)
+int zebra_server_lock (ZServerInfo *zi, int commitPhase)
+{
+ if (!zi->server_lock_cmt)
{
- sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
- if (!(server_lock_cmt = zebra_lock_create (path, 0)))
+ char path[1024];
+
+ strcpy (path, zi->server_path_prefix);
+ strcat (path, FNAME_COMMIT_LOCK);
+ if (!(zi->server_lock_cmt = zebra_lock_create (path, 0)))
{
logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
return -1;
}
- assert (server_lock_org == NULL);
+ assert (zi->server_lock_org == NULL);
- sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
- if (!(server_lock_org = zebra_lock_create (path, 0)))
+ strcpy (path, zi->server_path_prefix);
+ strcat (path, FNAME_ORG_LOCK);
+ if (!(zi->server_lock_org = zebra_lock_create (path, 0)))
{
logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
return -1;
if (commitPhase)
{
logf (LOG_DEBUG, "Server locks org");
- zebra_lock (server_lock_org);
+ zebra_lock (zi->server_lock_org);
}
else
{
logf (LOG_DEBUG, "Server locks cmt");
- zebra_lock (server_lock_cmt);
+ zebra_lock (zi->server_lock_cmt);
}
return 0;
}
-void zebraServerUnlock (int commitPhase)
+void zebra_server_unlock (ZServerInfo *zi, int commitPhase)
{
- if (server_lock_org == NULL)
+ if (zi->server_lock_org == NULL)
return;
if (commitPhase)
{
logf (LOG_DEBUG, "Server unlocks org");
- zebra_unlock (server_lock_org);
+ zebra_unlock (zi->server_lock_org);
}
else
{
logf (LOG_DEBUG, "Server unlocks cmt");
- zebra_unlock (server_lock_cmt);
+ zebra_unlock (zi->server_lock_cmt);
}
}
-int zebraServerLockGetState (Res res, time_t *timep)
+int zebra_server_lock_get_state (ZServerInfo *zi, time_t *timep)
{
- char pathPrefix[1024];
char path[1024];
char buf[256];
int fd;
struct stat xstat;
- zebraLockPrefix (res, pathPrefix);
-
- sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
+ strcpy (path, zi->server_path_prefix);
+ strcat (path, FNAME_TOUCH_TIME);
if (stat (path, &xstat) == -1)
*timep = 1;
else
*timep = xstat.st_ctime;
-
- sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
+
+ strcpy (path, zi->server_path_prefix);
+ strcat (path, FNAME_MAIN_LOCK);
fd = open (path, O_BINARY|O_RDONLY);
if (fd == -1)
{
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lockutil.c,v $
- * Revision 1.9 1997-09-25 14:54:43 adam
+ * Revision 1.10 1997-09-29 09:08:36 adam
+ * Revised locking system to be thread safe for the server.
+ *
+ * Revision 1.9 1997/09/25 14:54:43 adam
* WIN32 files lock support.
*
* Revision 1.8 1997/09/17 12:19:15 adam
#include "index.h"
-static char *lockDir = NULL;
-
struct zebra_lock_info {
int fd;
int excl_flag;
xfree (h);
}
-void zebraLockPrefix (Res res, char *pathPrefix)
+void zebra_lock_prefix (Res res, char *path)
{
- if (!lockDir)
- lockDir = res_get_def (res, "lockDir", "");
- assert (lockDir);
-
- strcpy (pathPrefix, lockDir);
- if (*pathPrefix && pathPrefix[strlen(pathPrefix)-1] != '/')
- strcat (pathPrefix, "/");
+ char *lock_dir = res_get_def (res, "lockDir", "");
+
+ strcpy (path, lock_dir);
+ if (*path && path[strlen(path)-1] != '/')
+ strcat (path, "/");
}
#ifdef WINDOWS
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.c,v $
- * Revision 1.49 1997-09-25 14:57:23 adam
+ * Revision 1.50 1997-09-29 09:08:36 adam
+ * Revised locking system to be thread safe for the server.
+ *
+ * Revision 1.49 1997/09/25 14:57:23 adam
* Windows NT port.
*
* Revision 1.48 1997/09/17 12:19:19 adam
#include <recctrl.h>
#include <dmalloc.h>
-#ifdef __linux__
-#define USE_TIMES 1
-#endif
-
-#ifndef USE_TIMES
-#define USE_TIMES 0
-#endif
-
-#if USE_TIMES
-#include <sys/times.h>
-#endif
#include "zserver.h"
-
-#if USE_TIMES
-static struct tms tms1;
-static struct tms tms2;
-#endif
-
static int register_lock (ZServerInfo *zi)
{
time_t lastChange;
- int state = zebraServerLockGetState(zi->res, &lastChange);
+ int state = zebra_server_lock_get_state(zi, &lastChange);
switch (state)
{
default:
state = 0;
}
- zebraServerLock (zi->res, state);
+ zebra_server_lock (zi, state);
#if USE_TIMES
- times (&tms1);
+ times (&zi->tms1);
#endif
if (zi->registerState == state)
{
static int waitSec = -1;
#if USE_TIMES
- times (&tms2);
+ times (&zi->tms2);
logf (LOG_LOG, "user/system: %ld/%ld",
- (long) (tms2.tms_utime - tms1.tms_utime),
- (long) (tms2.tms_stime - tms1.tms_stime));
+ (long) (zi->tms2.tms_utime - zi->tms1.tms_utime),
+ (long) (zi->tms2.tms_stime - zi->tms1.tms_stime));
#endif
if (waitSec == -1)
{
sleep (waitSec);
#endif
if (zi->registerState != -1)
- zebraServerUnlock (zi->registerState);
+ zebra_server_unlock (zi, zi->registerState);
}
bend_initresult *bend_init (bend_initrequest *q)
logf (LOG_FATAL, "Cannot open resource `%s'", sob->configname);
exit (1);
}
+ zebra_server_lock_init (zi);
zi->dh = data1_create ();
zi->bfs = bfs_create (res_get (zi->res, "register"));
bf_lockDir (zi->bfs, res_get (zi->res, "lockDir"));
}
bfs_destroy (zi->bfs);
data1_destroy (zi->dh);
+ zebra_server_lock_destroy (zi);
return;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.h,v $
- * Revision 1.24 1997-09-17 12:19:19 adam
+ * Revision 1.25 1997-09-29 09:08:36 adam
+ * Revised locking system to be thread safe for the server.
+ *
+ * Revision 1.24 1997/09/17 12:19:19 adam
* Zebra version corresponds to YAZ version 1.4.
* Changed Zebra server so that it doesn't depend on global common_resource.
*
*
*/
+
+#ifndef USE_TIMES
+#ifdef __linux__
+#define USE_TIMES 1
+#else
+#define USE_TIMES 0
+#endif
+#endif
+
+#if USE_TIMES
+#include <sys/times.h>
+#endif
+
#include <backend.h>
#include <rset.h>
data1_attset *registered_sets;
BFiles bfs;
Res res;
+
+ ZebraLockHandle server_lock_cmt;
+ ZebraLockHandle server_lock_org;
+ char *server_path_prefix;
+#ifdef USE_TIMES
+ struct tms tms1;
+ struct tms tms2;
+#endif
} ZServerInfo;
int rpn_search (ZServerInfo *zi,
void resultSetSysnoDel (ZServerInfo *zi, ZServerSetSysno *records, int num);
void zlog_rpn (Z_RPNQuery *rpn);
-int zebraServerLock (Res res, int lockCommit);
-void zebraServerUnlock (int commitPhase);
-int zebraServerLockGetState (Res res, time_t *timep);
+int zebra_server_lock_init (ZServerInfo *zi);
+int zebra_server_lock_destroy (ZServerInfo *zi);
+int zebra_server_lock (ZServerInfo *zi, int lockCommit);
+void zebra_server_unlock (ZServerInfo *zi, int commitPhase);
+int zebra_server_lock_get_state (ZServerInfo *zi, time_t *timep);
typedef struct attent
{