X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzserver.c;h=002989f037480c4a4af9edc16d215f0963705ce2;hb=3069523c17210f316ece638052eee94fce1db9e1;hp=9c2fbffec52ca97123f4e877dd8b6123ca1ff902;hpb=a6908b6d93de84a850a3e558a2e4c17f02c3d651;p=idzebra-moved-to-github.git diff --git a/index/zserver.c b/index/zserver.c index 9c2fbff..002989f 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -1,10 +1,29 @@ /* - * Copyright (C) 1995-1997, Index Data I/S + * Copyright (C) 1995-1998, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.c,v $ - * Revision 1.49 1997-09-25 14:57:23 adam + * Revision 1.54 1998-01-29 13:39:13 adam + * Compress ISAM is default. + * + * Revision 1.53 1998/01/12 15:04:09 adam + * The test option (-s) only uses read-lock (and not write lock). + * + * Revision 1.52 1997/11/18 10:05:08 adam + * Changed character map facility so that admin can specify character + * mapping files for each register type, w, p, etc. + * + * Revision 1.51 1997/10/27 14:33:06 adam + * Moved towards generic character mapping depending on "structure" + * field in abstract syntax file. Fixed a few memory leaks. Fixed + * bug with negative integers when doing searches with relational + * operators. + * + * 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 @@ -193,29 +212,12 @@ #include #include -#ifdef __linux__ -#define USE_TIMES 1 -#endif - -#ifndef USE_TIMES -#define USE_TIMES 0 -#endif - -#if USE_TIMES -#include -#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) { @@ -225,9 +227,9 @@ static int register_lock (ZServerInfo *zi) 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) { @@ -259,7 +261,7 @@ static int register_lock (ZServerInfo *zi) return -1; zi->isam = NULL; zi->isamc = NULL; - if (res_get_match (zi->res, "isam", "c", NULL)) + if (!res_get_match (zi->res, "isam", "i", NULL)) { if (!(zi->isamc = isc_open (zi->bfs, FNAME_ISAMC, 0, key_isamc_m(zi->res)))) @@ -273,7 +275,7 @@ static int register_lock (ZServerInfo *zi) return -1; } zi->zti = zebTargetInfo_open (zi->records, 0); - init_charmap (zi->res); + return 0; } @@ -282,10 +284,10 @@ static void register_unlock (ZServerInfo *zi) 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) { @@ -301,7 +303,7 @@ static void register_unlock (ZServerInfo *zi) sleep (waitSec); #endif if (zi->registerState != -1) - zebraServerUnlock (zi->registerState); + zebra_server_unlock (zi, zi->registerState); } bend_initresult *bend_init (bend_initrequest *q) @@ -320,9 +322,11 @@ bend_initresult *bend_init (bend_initrequest *q) logf (LOG_LOG, "Reading resources from %s", sob->configname); if (!(zi->res = res_open (sob->configname))) { - logf (LOG_FATAL, "Cannot open resource `%s'", sob->configname); - exit (1); + logf (LOG_FATAL, "Failed to read resources `%s'", sob->configname); + r->errcode = 1; + return r; } + 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")); @@ -334,6 +338,8 @@ bend_initresult *bend_init (bend_initrequest *q) zi->records = NULL; zi->odr = odr_createmem (ODR_ENCODE); zi->registered_sets = NULL; + zi->zebra_maps = zebra_maps_open (res_get(zi->res, "profilePath"), + zi->res); return r; } @@ -443,9 +449,8 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream, if (!(rt = recType_byName (file_type, subType))) { - logf (LOG_FATAL|LOG_ERRNO, "Retrieve: Cannot handle type %s", - file_type); - exit (1); + logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type); + return 14; } logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score); retrieveCtrl.fh = &fc; @@ -573,9 +578,11 @@ bend_scanresult *bend_scan (void *handle, bend_scanrequest *q, int *num) void bend_close (void *handle) { ZServerInfo *zi = handle; + if (zi->records) { resultSetDestroy (zi); + zebTargetInfo_close (zi->zti, 0); dict_close (zi->dict); if (zi->isam) is_close (zi->isam); @@ -584,17 +591,44 @@ void bend_close (void *handle) rec_close (&zi->records); register_unlock (zi); } + odr_destroy (zi->odr); + zebra_maps_close (zi->zebra_maps); bfs_destroy (zi->bfs); data1_destroy (zi->dh); - return; + zebra_server_lock_destroy (zi); + + res_close (zi->res); + xfree (zi); } +#ifndef WINDOWS +static void pre_init (struct statserv_options_block *sob) +{ + char *pidfile = "zebrasrv.pid"; + int fd = creat (pidfile, 0666); + + if (fd == -1) + logf (LOG_WARN|LOG_ERRNO, "creat %s", pidfile); + else + { + char pidstr[30]; + + sprintf (pidstr, "%ld", (long) getpid ()); + write (fd, pidstr, strlen(pidstr)); + close (fd); + } +} +#endif + int main (int argc, char **argv) { struct statserv_options_block *sob; sob = statserv_getcontrol (); strcpy (sob->configname, FNAME_CONFIG); +#ifndef WINDOWS + sob->pre_init = pre_init; +#endif statserv_setcontrol (sob); return statserv_main (argc, argv);