X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=index%2Flocksrv.c;h=304dc88a2c936264f6ce646edf7b5fb630ecb3ae;hb=c5ef994b26d692fbfecc3ac97f69e4bf7bd0fcea;hp=903334e8b6efb252518a193428c7d47fb090ab92;hpb=37a0daf2cf9d12c9b62fce9975e56bc86bc858b2;p=idzebra-moved-to-github.git diff --git a/index/locksrv.c b/index/locksrv.c index 903334e..304dc88 100644 --- a/index/locksrv.c +++ b/index/locksrv.c @@ -1,10 +1,23 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: locksrv.c,v $ - * Revision 1.5 1996-05-15 11:58:18 adam + * Revision 1.9 1997-09-25 14:54:43 adam + * WIN32 files lock support. + * + * Revision 1.8 1997/09/17 12:19:15 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.7 1997/09/04 13:58:04 adam + * Added O_BINARY for open calls. + * + * Revision 1.6 1996/10/29 14:06:52 adam + * Include zebrautl.h instead of alexutil.h. + * + * Revision 1.5 1996/05/15 11:58:18 adam * Changed some log messages. * * Revision 1.4 1996/04/10 16:01:27 quinn @@ -26,39 +39,40 @@ */ #include #include +#ifdef WINDOWS +#include +#else #include +#endif #include #include #include #include -#include #include "zserver.h" -static int server_lock_cmt = -1; -static int server_lock_org = -1; +static ZebraLockHandle server_lock_cmt = NULL; +static ZebraLockHandle server_lock_org = NULL; -int zebraServerLock (int commitPhase) +int zebraServerLock (Res res, int commitPhase) { char pathPrefix[1024]; char path[1024]; - zebraLockPrefix (pathPrefix); + zebraLockPrefix (res, pathPrefix); - if (server_lock_cmt == -1) + if (!server_lock_cmt) { sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK); - if ((server_lock_cmt = open (path, O_CREAT|O_RDWR, 0666)) - == -1) + if (!(server_lock_cmt = zebra_lock_create (path, 0))) { logf (LOG_FATAL|LOG_ERRNO, "create %s", path); return -1; } - assert (server_lock_org == -1); + assert (server_lock_org == NULL); sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK); - if ((server_lock_org = open (path, O_CREAT|O_RDWR, 0666)) - == -1) + if (!(server_lock_org = zebra_lock_create (path, 0))) { logf (LOG_FATAL|LOG_ERRNO, "create %s", path); return -1; @@ -67,33 +81,33 @@ int zebraServerLock (int commitPhase) if (commitPhase) { logf (LOG_DEBUG, "Server locks org"); - zebraLock (server_lock_org, 0); + zebra_lock (server_lock_org); } else { logf (LOG_DEBUG, "Server locks cmt"); - zebraLock (server_lock_cmt, 0); + zebra_lock (server_lock_cmt); } return 0; } void zebraServerUnlock (int commitPhase) { - if (server_lock_org == -1) + if (server_lock_org == NULL) return; if (commitPhase) { logf (LOG_DEBUG, "Server unlocks org"); - zebraUnlock (server_lock_org); + zebra_unlock (server_lock_org); } else { logf (LOG_DEBUG, "Server unlocks cmt"); - zebraUnlock (server_lock_cmt); + zebra_unlock (server_lock_cmt); } } -int zebraServerLockGetState (time_t *timep) +int zebraServerLockGetState (Res res, time_t *timep) { char pathPrefix[1024]; char path[1024]; @@ -101,7 +115,7 @@ int zebraServerLockGetState (time_t *timep) int fd; struct stat xstat; - zebraLockPrefix (pathPrefix); + zebraLockPrefix (res, pathPrefix); sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME); if (stat (path, &xstat) == -1) @@ -110,7 +124,7 @@ int zebraServerLockGetState (time_t *timep) *timep = xstat.st_ctime; sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK); - fd = open (path, O_RDONLY); + fd = open (path, O_BINARY|O_RDONLY); if (fd == -1) { *buf = 0;