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