]> git.ipfire.org Git - ipfire-3.x.git/blob - compat-gdbm/patches/gdbm-1.8.3-ndbmlock.patch
git: Update to 2.23.0
[ipfire-3.x.git] / compat-gdbm / patches / gdbm-1.8.3-ndbmlock.patch
1 diff -up gdbm-1.8.3/dbmopen.c.dbmlock gdbm-1.8.3/dbmopen.c
2 --- gdbm-1.8.3/dbmopen.c.dbmlock 1999-05-19 02:16:05.000000000 +0200
3 +++ gdbm-1.8.3/dbmopen.c 2011-01-03 16:17:13.847173371 +0100
4 @@ -35,6 +35,28 @@
5 #include "gdbmerrno.h"
6 #include "extern.h"
7
8 +static int
9 +get_env_bool(env_var, def)
10 + const char *env_var;
11 + int def;
12 +{
13 + const char *v = getenv(env_var);
14 + if (!v)
15 + return def;
16 +
17 + if (!strcasecmp(v, "yes") ||
18 + !strcasecmp(v, "true") ||
19 + !strcasecmp(v, "on"))
20 + return 1;
21 +
22 + if (!strcasecmp(v, "no") ||
23 + !strcasecmp(v, "false") ||
24 + !strcasecmp(v, "off"))
25 + return 0;
26 +
27 + return !!atoi(v);
28 +}
29 +
30 /* Initialize ndbm system. FILE is a pointer to the file name. In
31 standard dbm, the database is found in files called FILE.pag and
32 FILE.dir. To make gdbm compatable with dbm using the dbminit call,
33 @@ -62,7 +84,7 @@ dbm_open (file, flags, mode)
34 char* dir_file; /* Used to construct "file.dir". */
35 struct stat dir_stat; /* Stat information for "file.dir". */
36 gdbm_file_info *temp_dbf; /* Temporary file pointer storage. */
37 -
38 + int gdbm_mode = 0;
39
40 /* Prepare the correct names of "file.pag" and "file.dir". */
41 pag_file = (char *) malloc (strlen (file)+5);
42 @@ -77,26 +99,22 @@ dbm_open (file, flags, mode)
43 strcat (pag_file, ".pag");
44 strcpy (dir_file, file);
45 strcat (dir_file, ".dir");
46 -
47 +
48 + if (!get_env_bool("NDBM_LOCK", 1))
49 + gdbm_mode |= GDBM_NOLOCK;
50
51 /* Call the actual routine, saving the pointer to the file information. */
52 flags &= O_RDONLY | O_RDWR | O_CREAT | O_TRUNC;
53 if (flags == O_RDONLY)
54 - {
55 - temp_dbf = gdbm_open (pag_file, 0, GDBM_READER, 0, NULL);
56 - }
57 + gdbm_mode |= GDBM_READER;
58 else if (flags == (O_RDWR | O_CREAT))
59 - {
60 - temp_dbf = gdbm_open (pag_file, 0, GDBM_WRCREAT, mode, NULL);
61 - }
62 - else if ( (flags & O_TRUNC) == O_TRUNC)
63 - {
64 - temp_dbf = gdbm_open (pag_file, 0, GDBM_NEWDB, mode, NULL);
65 - }
66 + gdbm_mode |= GDBM_WRCREAT;
67 + else if ((flags & O_TRUNC) == O_TRUNC)
68 + gdbm_mode |= GDBM_NEWDB;
69 else
70 - {
71 - temp_dbf = gdbm_open (pag_file, 0, GDBM_WRITER, 0, NULL);
72 - }
73 + gdbm_mode |= GDBM_WRITER;
74 +
75 + temp_dbf = gdbm_open (pag_file, 0, gdbm_mode, mode, NULL);
76
77 /* Did we successfully open the file? */
78 if (temp_dbf == NULL)
79 diff -up gdbm-1.8.3/gdbm.3.dbmlock gdbm-1.8.3/gdbm.3
80 --- gdbm-1.8.3/gdbm.3.dbmlock 2011-01-03 15:59:15.684729255 +0100
81 +++ gdbm-1.8.3/gdbm.3 2011-01-03 16:17:49.957570637 +0100
82 @@ -543,7 +543,11 @@ you must link in the \fIgdbm_compat\fR l
83 .sp
84 gcc -o prog proc.c -lgdbm -lgdbm_compat
85
86 -.SH BUGS
87 +.SH "ENVIRONMENT VARIABLES"
88 +\fINDBM_LOCK\fR - When the NDBM interface is used, the database file
89 +is locked by default. Locking might degrade performance when used on a
90 +NFS share. This environment variable can be set to false to tell GDBM
91 +not to lock the database file.
92
93 .SH "SEE ALSO"
94 dbm, ndbm