Extra generic handle for the character mapping routines.
[idzebra-moved-to-github.git] / index / lockidx.c
index 286bd41..10be062 100644 (file)
@@ -4,7 +4,17 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: lockidx.c,v $
- * Revision 1.8  1997-02-12 20:39:46  adam
+ * Revision 1.11  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.10  1997/09/09 13:38:07  adam
+ * Partial port to WIN95/NT.
+ *
+ * Revision 1.9  1997/09/04 13:58:04  adam
+ * Added O_BINARY for open calls.
+ *
+ * Revision 1.8  1997/02/12 20:39:46  adam
  * Implemented options -f <n> that limits the log to the first <n>
  * records.
  * Changed some log messages also.
  */
 #include <stdio.h>
 #include <assert.h>
+#ifdef WINDOWS
+#include <io.h>
+#else
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
@@ -56,12 +70,13 @@ int zebraIndexWait (int commitPhase)
     char path[1024];
     int fd;
     
-    zebraLockPrefix (pathPrefix);
+    zebraLockPrefix (common_resource, pathPrefix);
 
     if (server_lock_cmt == -1)
     {
         sprintf (path, "%s%s", pathPrefix, FNAME_COMMIT_LOCK);
-        if ((server_lock_cmt = open (path, O_CREAT|O_RDWR|O_SYNC, 0666))
+        if ((server_lock_cmt = open (path, O_BINARY|O_CREAT|O_RDWR|O_SYNC,
+                                     0666))
             == -1)
         {
             logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
@@ -73,7 +88,8 @@ int zebraIndexWait (int commitPhase)
     if (server_lock_org == -1)
     {
         sprintf (path, "%s%s", pathPrefix, FNAME_ORG_LOCK);
-        if ((server_lock_org = open (path, O_CREAT|O_RDWR|O_SYNC, 0666))
+        if ((server_lock_org = open (path, O_BINARY|O_CREAT|O_RDWR|O_SYNC,
+                                     0666))
             == -1)
         {
             logf (LOG_FATAL|LOG_ERRNO, "create %s", path);
@@ -123,7 +139,7 @@ void zebraIndexLockMsg (const char *str)
         logf (LOG_FATAL|LOG_ERRNO, "write lock file");
         exit (1);
     }
-    zebraLockPrefix (pathPrefix);
+    zebraLockPrefix (common_resource, pathPrefix);
     sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME);
     fd = creat (path, 0666);
     close (fd);
@@ -134,12 +150,12 @@ void zebraIndexUnlock (void)
     char path[1024];
     char pathPrefix[1024];
 
-    zebraLockPrefix (pathPrefix);
+    zebraLockPrefix (common_resource, pathPrefix);
     sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
     unlink (path);
 }
 
-void zebraIndexLock (int commitNow)
+void zebraIndexLock (BFiles bfs, int commitNow, const char *rval)
 {
     char path[1024];
     char pathPrefix[1024];
@@ -148,14 +164,14 @@ void zebraIndexLock (int commitNow)
 
     if (lock_fd != -1)
         return ;
-    zebraLockPrefix (pathPrefix);
+    zebraLockPrefix (common_resource, pathPrefix);
     sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK);
     while (1)
     {
-        lock_fd = open (path, O_CREAT|O_RDWR|O_EXCL, 0666);
+        lock_fd = open (path, O_BINARY|O_CREAT|O_RDWR|O_EXCL, 0666);
         if (lock_fd == -1)
         {
-            lock_fd = open (path, O_RDWR);
+            lock_fd = open (path, O_BINARY|O_RDWR);
             if (lock_fd == -1) 
             {
                 if (errno == ENOENT)
@@ -200,7 +216,7 @@ void zebraIndexLock (int commitNow)
                     logf (LOG_WARN, "previous transaction didn't"
                           " reach commit");
                     close (lock_fd);
-                    bf_commitClean ();
+                    bf_commitClean (bfs, rval);
                     unlink (path);
                     continue;
                 }
@@ -208,7 +224,7 @@ void zebraIndexLock (int commitNow)
                 {
                     logf (LOG_WARN, "commit file wan't deleted after commit");
                     close (lock_fd);
-                    bf_commitClean ();
+                    bf_commitClean (bfs, rval);
                     unlink (path);
                     continue;
                 }