aboutsummaryrefslogtreecommitdiff
path: root/compat
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 /compat
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 'compat')
-rw-r--r--compat/dbmopen.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/compat/dbmopen.c b/compat/dbmopen.c
index 4ae55d9..7a5127e 100644
--- a/compat/dbmopen.c
+++ b/compat/dbmopen.c
@@ -63,6 +63,11 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
int fd = -1;
struct stat st, pagst;
unsigned char dirbuf[DEF_DIR_SIZE];
+ int flags = (mode & GDBM_OPENMASK) == GDBM_READER ?
+ O_RDONLY : O_RDWR;
+
+ if (mode & GDBM_CLOEXEC)
+ flags |= O_CLOEXEC;
if (fstat (pagfd, &pagst))
{
@@ -104,12 +109,6 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
}
else
{
- int flags = (mode & GDBM_OPENMASK) == GDBM_READER ?
- O_RDONLY : O_RDWR;
-
- if (mode & GDBM_CLOEXEC)
- flags |= O_CLOEXEC;
-
fd = open (file_name, flags);
if (fd == -1)
{
@@ -142,7 +141,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
}
/* File does not exist. Create it. */
- fd = open (file_name, O_RDWR | O_CREAT, pagst.st_mode & 0777);
+ fd = open (file_name, flags | O_CREAT, pagst.st_mode & 0777);
if (fd >= 0)
{
putint (dirbuf, GDBM_DIR_MAGIC);

Return to:

Send suggestions and report system problems to the System administrator.