pkubat / rpms / gdbm

Forked from rpms/gdbm 6 years ago
Clone
Karel Klic 0cb4139
diff -up gdbm-1.8.3/dbmopen.c.dbmlock gdbm-1.8.3/dbmopen.c
Karel Klic 0cb4139
--- gdbm-1.8.3/dbmopen.c.dbmlock	1999-05-19 02:16:05.000000000 +0200
Karel Klic 0cb4139
+++ gdbm-1.8.3/dbmopen.c	2011-01-03 16:17:13.847173371 +0100
Karel Klic 0cb4139
@@ -35,6 +35,28 @@
Karel Klic 0cb4139
 #include "gdbmerrno.h"
Karel Klic 0cb4139
 #include "extern.h"
Karel Klic 0cb4139
 
Karel Klic 0cb4139
+static int
Karel Klic 0cb4139
+get_env_bool(env_var, def)
Karel Klic 0cb4139
+      const char *env_var;
Karel Klic 0cb4139
+      int def;
Karel Klic 0cb4139
+{
Karel Klic 0cb4139
+  const char *v = getenv(env_var);
Karel Klic 0cb4139
+  if (!v)
Karel Klic 0cb4139
+    return def;
Karel Klic 0cb4139
+
Karel Klic 0cb4139
+  if (!strcasecmp(v, "yes") ||
Karel Klic 0cb4139
+      !strcasecmp(v, "true") ||
Karel Klic 0cb4139
+      !strcasecmp(v, "on"))
Karel Klic 0cb4139
+    return 1;
Karel Klic 0cb4139
+
Karel Klic 0cb4139
+  if (!strcasecmp(v, "no") ||
Karel Klic 0cb4139
+      !strcasecmp(v, "false") ||
Karel Klic 0cb4139
+      !strcasecmp(v, "off"))
Karel Klic 0cb4139
+    return 0;
Karel Klic 0cb4139
+
Karel Klic 0cb4139
+  return !!atoi(v);
Karel Klic 0cb4139
+}
Karel Klic 0cb4139
+
Karel Klic 0cb4139
 /* Initialize ndbm system.  FILE is a pointer to the file name.  In
Karel Klic 0cb4139
    standard dbm, the database is found in files called FILE.pag and
Karel Klic 0cb4139
    FILE.dir.  To make gdbm compatable with dbm using the dbminit call,
Karel Klic 0cb4139
@@ -62,7 +84,7 @@ dbm_open (file, flags, mode)
Karel Klic 0cb4139
   char* dir_file;	    /* Used to construct "file.dir". */
Karel Klic 0cb4139
   struct stat dir_stat;	    /* Stat information for "file.dir". */
Karel Klic 0cb4139
   gdbm_file_info *temp_dbf;  /* Temporary file pointer storage. */
Karel Klic 0cb4139
-
Karel Klic 0cb4139
+  int gdbm_mode = 0;
Karel Klic 0cb4139
 
Karel Klic 0cb4139
   /* Prepare the correct names of "file.pag" and "file.dir". */
Karel Klic 0cb4139
   pag_file = (char *) malloc (strlen (file)+5);
Karel Klic 0cb4139
@@ -77,26 +99,22 @@ dbm_open (file, flags, mode)
Karel Klic 0cb4139
   strcat (pag_file, ".pag");
Karel Klic 0cb4139
   strcpy (dir_file, file);
Karel Klic 0cb4139
   strcat (dir_file, ".dir");
Karel Klic 0cb4139
-  
Karel Klic 0cb4139
+
Karel Klic 0cb4139
+  if (!get_env_bool("NDBM_LOCK", 1))
Karel Klic 0cb4139
+      gdbm_mode |= GDBM_NOLOCK;
Karel Klic 0cb4139
 
Karel Klic 0cb4139
   /* Call the actual routine, saving the pointer to the file information. */
Karel Klic 0cb4139
   flags &= O_RDONLY | O_RDWR | O_CREAT | O_TRUNC;
Karel Klic 0cb4139
   if (flags == O_RDONLY)
Karel Klic 0cb4139
-    {
Karel Klic 0cb4139
-      temp_dbf = gdbm_open (pag_file, 0, GDBM_READER, 0, NULL);
Karel Klic 0cb4139
-    }
Karel Klic 0cb4139
+    gdbm_mode |= GDBM_READER;
Karel Klic 0cb4139
   else if (flags == (O_RDWR | O_CREAT))
Karel Klic 0cb4139
-    {
Karel Klic 0cb4139
-      temp_dbf = gdbm_open (pag_file, 0, GDBM_WRCREAT, mode, NULL);
Karel Klic 0cb4139
-    }
Karel Klic 0cb4139
-  else if ( (flags & O_TRUNC) == O_TRUNC)
Karel Klic 0cb4139
-    {
Karel Klic 0cb4139
-      temp_dbf = gdbm_open (pag_file, 0, GDBM_NEWDB, mode, NULL);
Karel Klic 0cb4139
-    }
Karel Klic 0cb4139
+    gdbm_mode |= GDBM_WRCREAT;
Karel Klic 0cb4139
+  else if ((flags & O_TRUNC) == O_TRUNC)
Karel Klic 0cb4139
+    gdbm_mode |= GDBM_NEWDB;
Karel Klic 0cb4139
   else
Karel Klic 0cb4139
-    {
Karel Klic 0cb4139
-      temp_dbf = gdbm_open (pag_file, 0, GDBM_WRITER, 0, NULL);
Karel Klic 0cb4139
-    }
Karel Klic 0cb4139
+    gdbm_mode |= GDBM_WRITER;
Karel Klic 0cb4139
+
Karel Klic 0cb4139
+  temp_dbf = gdbm_open (pag_file, 0, gdbm_mode, mode, NULL);
Karel Klic 0cb4139
 
Karel Klic 0cb4139
   /* Did we successfully open the file? */
Karel Klic 0cb4139
   if (temp_dbf == NULL)
Karel Klic 0cb4139
diff -up gdbm-1.8.3/gdbm.3.dbmlock gdbm-1.8.3/gdbm.3
Karel Klic 0cb4139
--- gdbm-1.8.3/gdbm.3.dbmlock	2011-01-03 15:59:15.684729255 +0100
Karel Klic 0cb4139
+++ gdbm-1.8.3/gdbm.3	2011-01-03 16:17:49.957570637 +0100
Karel Klic 0cb4139
@@ -543,7 +543,11 @@ you must link in the \fIgdbm_compat\fR l
Karel Klic 0cb4139
 .sp
Karel Klic 0cb4139
 	gcc -o prog proc.c -lgdbm -lgdbm_compat
Karel Klic 0cb4139
 
Karel Klic 0cb4139
-.SH BUGS
Karel Klic 0cb4139
+.SH "ENVIRONMENT VARIABLES"
Karel Klic 0cb4139
+\fINDBM_LOCK\fR - When the NDBM interface is used, the database file
Karel Klic 0cb4139
+is locked by default. Locking might degrade performance when used on a
Karel Klic 0cb4139
+NFS share. This environment variable can be set to false to tell GDBM
Karel Klic 0cb4139
+not to lock the database file.
Karel Klic 0cb4139
 
Karel Klic 0cb4139
 .SH "SEE ALSO"
Karel Klic 0cb4139
 dbm, ndbm