aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-11-11 18:39:42 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2011-11-11 18:39:42 +0000
commitbc12482932a6771566c7dcabc53f34e6297510f2 (patch)
treeb6f3f100201a5475fecdd1df66a45b1178831457 /tests
parent894b78d5bcb7b609a3b52ce804306a63c4761282 (diff)
downloadgdbm-bc12482932a6771566c7dcabc53f34e6297510f2.tar.gz
gdbm-bc12482932a6771566c7dcabc53f34e6297510f2.tar.bz2
Implement cloexec in gdbm_reorganize. Add test cases.
* compat/dbmopen.c: Apply O_CLOEXEC for newly created dir file, if requested. * src/gdbmdefs.h (gdbm_file_info) <cloexec>: New member. * src/gdbmopen.c (gdbm_open): Initialize cloexec member. * src/gdbmreorg.c (gdbm_reorganize): Propagate cloexec bit to the new database. * tests/.cvsignore: Update. * tests/cloexec00.at: New test case. * tests/cloexec01.at: Likewise. * tests/cloexec02.at: Likewise. * tests/cloexec03.at: Likewise. * fdop.c: New auxiliary program. * g_open_ce: New test program. * g_reorg_ce: New test program. * d_creat_ce: New test program. * tests/Makefile.am: Add new test cases and test programs. * tests/testsuite.at: Include new test cases. * doc/gdbm.texinfo: Minor change.
Diffstat (limited to 'tests')
-rw-r--r--tests/.cvsignore4
-rw-r--r--tests/Makefile.am13
-rw-r--r--tests/cloexec00.at25
-rw-r--r--tests/cloexec01.at25
-rw-r--r--tests/cloexec02.at27
-rw-r--r--tests/cloexec03.at26
-rw-r--r--tests/d_creat_ce.c90
-rw-r--r--tests/fdop.c36
-rw-r--r--tests/g_open_ce.c66
-rw-r--r--tests/g_reorg_ce.c72
-rw-r--r--tests/testsuite.at7
11 files changed, 390 insertions, 1 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
index 3275961..0883563 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -2,16 +2,20 @@
.gdbinit
.libs
Makefile
Makefile.in
atconfig
atlocal
+d_creat_ce
dtdel
dtdump
dtfetch
dtload
+fdop
+g_open_ce
+g_reorg_ce
gtdel
gtdump
gtfetch
gtload
gtopt
gtver
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bfbcd9e..95d7fff 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,12 +45,16 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac $(srcdir)/Makefile.am
## ------------ ##
## Test suite. ##
## ------------ ##
TESTSUITE_AT = \
testsuite.at\
+ cloexec00.at\
+ cloexec01.at\
+ cloexec02.at\
+ cloexec03.at\
dbmcreate00.at\
dbmdel00.at\
dbmdel01.at\
dbmdel02.at\
dbmcvt.at\
dbmfetch00.at\
@@ -91,16 +95,19 @@ check-local: atconfig atlocal $(TESTSUITE)
## --------------- ##
## num2word et al. ##
## --------------- ##
if COMPAT_OPT
DBMINCLUDES = -I$(top_srcdir)/compat
- DBMPROGS = dtload dtdump dtfetch dtdel
+ DBMPROGS = dtload dtdump dtfetch dtdel d_creat_ce
endif
check_PROGRAMS = \
+ fdop\
+ g_open_ce\
+ g_reorg_ce\
gtdel\
gtdump\
gtfetch\
gtload\
gtopt\
gtver\
@@ -113,12 +120,16 @@ gtdel_LDADD = ../src/libgdbm.la
gtload_LDADD = ../src/libgdbm.la
gtdump_LDADD = ../src/libgdbm.la
gtfetch_LDADD = ../src/libgdbm.la
gtver_LDADD = ../src/libgdbm.la
gtopt_LDADD = ../src/libgdbm.la
+g_open_ce_LDADD = ../src/libgdbm.la
+g_reorg_ce_LDADD = ../src/libgdbm.la
+
dtload_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la
dtdump_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la
dtfetch_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la
dtdel_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la
+d_creat_ce_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la
diff --git a/tests/cloexec00.at b/tests/cloexec00.at
new file mode 100644
index 0000000..022b12f
--- /dev/null
+++ b/tests/cloexec00.at
@@ -0,0 +1,25 @@
+# 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([cloexec: gdbm_open])
+AT_KEYWORDS([gdbm gdbm_open cloexec cloexec00])
+
+AT_CHECK([
+g_open_ce "$abs_builddir/fdop"
+],
+0)
+
+AT_CLEANUP
diff --git a/tests/cloexec01.at b/tests/cloexec01.at
new file mode 100644
index 0000000..21baac6
--- /dev/null
+++ b/tests/cloexec01.at
@@ -0,0 +1,25 @@
+# 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([cloexec: gdbm_reorganize])
+AT_KEYWORDS([gdbm gdbm_reorganize cloexec cloexec01])
+
+AT_CHECK([
+g_reorg_ce "$abs_builddir/fdop"
+],
+0)
+
+AT_CLEANUP
diff --git a/tests/cloexec02.at b/tests/cloexec02.at
new file mode 100644
index 0000000..9d1b7e3
--- /dev/null
+++ b/tests/cloexec02.at
@@ -0,0 +1,27 @@
+# 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([cloexec: dbm_open])
+AT_KEYWORDS([ndbm dbm_open cloexec cloexec02])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+num2word 1:10 | dtload file
+d_creat_ce "$abs_builddir/fdop"
+],
+0)
+
+AT_CLEANUP
diff --git a/tests/cloexec03.at b/tests/cloexec03.at
new file mode 100644
index 0000000..5fa1c0f
--- /dev/null
+++ b/tests/cloexec03.at
@@ -0,0 +1,26 @@
+# 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([cloexec: dbm_open -creat])
+AT_KEYWORDS([ndbm dbm_open cloexec cloexec03])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+d_creat_ce "$abs_builddir/fdop" -creat
+],
+0)
+
+AT_CLEANUP
diff --git a/tests/d_creat_ce.c b/tests/d_creat_ce.c
new file mode 100644
index 0000000..6a6cff2
--- /dev/null
+++ b/tests/d_creat_ce.c
@@ -0,0 +1,90 @@
+/* This file is part of GDBM test suite.
+ 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/>.
+*/
+#include "autoconf.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <ndbm.h>
+
+char *
+ntos (int n, char *buf, size_t size)
+{
+ char *p = buf + size;
+ *--p = 0;
+ do
+ {
+ int x = n % 10;
+ *--p = '0' + x;
+ n /= 10;
+ }
+ while (n);
+ return p;
+}
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
+int
+main (int argc, char *argv[])
+{
+ DBM *d;
+ char fdbuf[2][80];
+ int i;
+ int flags = O_RDONLY;
+
+ if (argc < 2)
+ {
+ fprintf (stderr, "usage: %s PATH-TO-FDOP [-creat] [-write]\n", argv[0]);
+ return 2;
+ }
+
+ for (i = 2; i < argc; i++)
+ {
+ if (strcmp (argv[i], "-creat") == 0)
+ flags = O_RDWR|O_CREAT;
+ else if (strcmp (argv[i], "-write") == 0)
+ flags = O_RDWR;
+ else
+ {
+ fprintf (stderr, "%s: unknown option: %s\n",
+ argv[0], argv[i]);
+ return 2;
+ }
+
+ }
+
+ if (!O_CLOEXEC)
+ return 77;
+
+ d = dbm_open ("file", flags|O_CLOEXEC, 0600);
+ if (!d)
+ {
+ perror ("dbm_open");
+ return 3;
+ }
+
+ execl (argv[1], "fdop",
+ ntos (dbm_pagfno (d), fdbuf[0], sizeof (fdbuf[0])),
+ ntos (dbm_dirfno (d), fdbuf[1], sizeof (fdbuf[1])),
+ NULL);
+ return 127;
+}
+
diff --git a/tests/fdop.c b/tests/fdop.c
new file mode 100644
index 0000000..1729323
--- /dev/null
+++ b/tests/fdop.c
@@ -0,0 +1,36 @@
+/* This file is part of GDBM test suite.
+ 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/>.
+*/
+#include "autoconf.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+/* usage: fdop FD [FD...]
+ Return: false if any of the FDs is open, true otherwise.
+*/
+int
+main (int argc, char **argv)
+{
+ int fd = dup (0);
+
+ while (--argc)
+ {
+ int n = atoi (*++argv);
+ if (n < fd)
+ return 1;
+ }
+ return 0;
+}
diff --git a/tests/g_open_ce.c b/tests/g_open_ce.c
new file mode 100644
index 0000000..4f1fcd4
--- /dev/null
+++ b/tests/g_open_ce.c
@@ -0,0 +1,66 @@
+/* This file is part of GDBM test suite.
+ 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/>.
+*/
+#include "autoconf.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <gdbm.h>
+
+char *
+ntos (int n, char *buf, size_t size)
+{
+ char *p = buf + size;
+ *--p = 0;
+ do
+ {
+ int x = n % 10;
+ *--p = '0' + x;
+ n /= 10;
+ }
+ while (n);
+ return p;
+}
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
+int
+main (int argc, char *argv[])
+{
+ GDBM_FILE d;
+ char fdbuf[80];
+
+ if (argc != 2)
+ {
+ fprintf (stderr, "usage: %s PATH-TO-FDOP\n", argv[0]);
+ return 2;
+ }
+ if (!O_CLOEXEC)
+ return 77;
+ d = gdbm_open ("file.db", 0, GDBM_NEWDB|GDBM_CLOEXEC, 0600, NULL);
+ if (!d)
+ {
+ fprintf (stderr, "gdbm_open: %s\n", gdbm_strerror (gdbm_errno));
+ return 3;
+ }
+ execl (argv[1], "fdop",
+ ntos (gdbm_fdesc (d), fdbuf, sizeof (fdbuf)), NULL);
+ return 127;
+}
+
diff --git a/tests/g_reorg_ce.c b/tests/g_reorg_ce.c
new file mode 100644
index 0000000..f72afa2
--- /dev/null
+++ b/tests/g_reorg_ce.c
@@ -0,0 +1,72 @@
+/* This file is part of GDBM test suite.
+ 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/>.
+*/
+#include "autoconf.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <gdbm.h>
+
+char *
+ntos (int n, char *buf, size_t size)
+{
+ char *p = buf + size;
+ *--p = 0;
+ do
+ {
+ int x = n % 10;
+ *--p = '0' + x;
+ n /= 10;
+ }
+ while (n);
+ return p;
+}
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
+int
+main (int argc, char *argv[])
+{
+ GDBM_FILE d;
+ char fdbuf[80];
+
+ if (argc != 2)
+ {
+ fprintf (stderr, "usage: %s PATH-TO-FDOP\n", argv[0]);
+ return 2;
+ }
+ if (!O_CLOEXEC)
+ return 77;
+ d = gdbm_open ("file.db", 0, GDBM_NEWDB|GDBM_CLOEXEC, 0600, NULL);
+ if (!d)
+ {
+ fprintf (stderr, "gdbm_open: %s\n", gdbm_strerror (gdbm_errno));
+ return 3;
+ }
+ if (gdbm_reorganize (d))
+ {
+ fprintf (stderr, "gdbm_reorganize: %s\n",
+ gdbm_strerror (gdbm_errno));
+ return 3;
+ }
+ execl (argv[1], "fdop",
+ ntos (gdbm_fdesc (d), fdbuf, sizeof (fdbuf)), NULL);
+ return 127;
+}
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index a13b3fb..1e7373c 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -60,7 +60,14 @@ m4_include([dbmdel02.at])
AT_BANNER([DB options])
m4_include([setopt00.at])
m4_include([setopt01.at])
+AT_BANNER([Cloexec])
+
+m4_include([cloexec00.at])
+m4_include([cloexec01.at])
+m4_include([cloexec02.at])
+m4_include([cloexec03.at])
+
# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.