aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-11-10 22:27:18 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2011-11-10 22:27:18 +0000
commit902a2e4bb5aa53241898ae34dcf7aafb29df7b7e (patch)
tree8ccc38229f02ecf7ae264712e829ba5ae64e5912
parent3556dd6310425a2c175e66a9ba6f7d5f61304302 (diff)
downloadgdbm-902a2e4bb5aa53241898ae34dcf7aafb29df7b7e.tar.gz
gdbm-902a2e4bb5aa53241898ae34dcf7aafb29df7b7e.tar.bz2
Fix handling of NDBM databases in read-only mode.
* compat/dbmopen.c (ndbm_open_dir_file0): Open dir file in read-only mode if the database is being opened as GDBM_READER. * tests/dbmcvt.at: New file. * tests/dbmfetch02.at: New file. * tests/dbmfetch03.at: New file. * tests/Makefile.am (TESTSUITE_AT): Add new files. * tests/testsuite.at: Include new testcases.
-rw-r--r--ChangeLog12
-rw-r--r--THANKS1
-rw-r--r--compat/dbmopen.c2
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/dbmcvt.at34
-rw-r--r--tests/dbmfetch02.at32
-rw-r--r--tests/dbmfetch03.at36
-rw-r--r--tests/testsuite.at4
8 files changed, 123 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a7ef7dc..e6f9515 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-11-11 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Fix handling of NDBM databases in read-only mode.
+
+ * compat/dbmopen.c (ndbm_open_dir_file0): Open dir file in
+ read-only mode if the database is being opened as GDBM_READER.
+ * tests/dbmcvt.at: New file.
+ * tests/dbmfetch02.at: New file.
+ * tests/dbmfetch03.at: New file.
+ * tests/Makefile.am (TESTSUITE_AT): Add new files.
+ * tests/testsuite.at: Include new testcases.
+
2011-10-05 Sergey Poznyakoff <gray@gnu.org.ua>
Fix bug #150.
diff --git a/THANKS b/THANKS
index 628a636..56cc573 100644
--- a/THANKS
+++ b/THANKS
@@ -5,3 +5,4 @@ suggesting various improvements or submitting actual code. Here is a list
of these people. Help us keep it complete and exempt of errors.
Matthew Burgess <matthew@linuxfromscratch.org>
+Tanaka Akira <akr@fsij.org>
diff --git a/compat/dbmopen.c b/compat/dbmopen.c
index 9e66acc..0125903 100644
--- a/compat/dbmopen.c
+++ b/compat/dbmopen.c
@@ -104,7 +104,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
}
else
{
- fd = open (file_name, O_RDWR);
+ fd = open (file_name, mode == GDBM_READER ? O_RDONLY : O_RDWR);
if (fd == -1)
{
gdbm_errno = GDBM_FILE_OPEN_ERROR;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6075c38..bfbcd9e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,8 +52,11 @@ TESTSUITE_AT = \
dbmdel00.at\
dbmdel01.at\
dbmdel02.at\
+ dbmcvt.at\
dbmfetch00.at\
dbmfetch01.at\
+ dbmfetch02.at\
+ dbmfetch03.at\
create00.at\
delete00.at\
delete01.at\
diff --git a/tests/dbmcvt.at b/tests/dbmcvt.at
new file mode 100644
index 0000000..c314c8e
--- /dev/null
+++ b/tests/dbmcvt.at
@@ -0,0 +1,34 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([converting a 1.8-style database])
+AT_KEYWORDS([dbm fetch cvt])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+num2word 1:10 | dtload test
+rm test.dir
+ln test.pag test.dir
+dtfetch test 6
+cmp test.pag test.dir >/dev/null 2>&1 && exit 1
+exit 0
+],
+[0],
+[six
+])
+
+AT_CLEANUP
+
diff --git a/tests/dbmfetch02.at b/tests/dbmfetch02.at
new file mode 100644
index 0000000..c581a22
--- /dev/null
+++ b/tests/dbmfetch02.at
@@ -0,0 +1,32 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([fetch from a read-only database])
+AT_KEYWORDS([dbm fetch fetch02 dbmfetch02])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+num2word 1:10 | dtload test
+chmod -w test.dir test.pag
+dtfetch test 6 10
+],
+[0],
+[six
+ten
+])
+
+AT_CLEANUP
+
diff --git a/tests/dbmfetch03.at b/tests/dbmfetch03.at
new file mode 100644
index 0000000..b1e149b
--- /dev/null
+++ b/tests/dbmfetch03.at
@@ -0,0 +1,36 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([fetch from a read-only 1.8-style database])
+AT_KEYWORDS([dbm fetch fetch03 dbmfetch03])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+mkdir dir
+cd dir
+num2word 1:10 | dtload test
+rm test.dir
+ln test.pag test.dir
+chmod -w test.dir test.pag .
+dtfetch test 6 10
+],
+[0],
+[six
+ten
+])
+
+AT_CLEANUP
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index a7827c2..a13b3fb 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -47,8 +47,12 @@ AT_BANNER([Compatibility library (dbm/ndbm)])
m4_include([dbmcreate00.at])
+m4_include([dbmcvt.at])
+
m4_include([dbmfetch00.at])
m4_include([dbmfetch01.at])
+m4_include([dbmfetch02.at])
+m4_include([dbmfetch03.at])
m4_include([dbmdel00.at])
m4_include([dbmdel01.at])

Return to:

Send suggestions and report system problems to the System administrator.