diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-11-11 18:39:42 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-11-11 18:39:42 +0000 |
commit | bc12482932a6771566c7dcabc53f34e6297510f2 (patch) | |
tree | b6f3f100201a5475fecdd1df66a45b1178831457 /src | |
parent | 894b78d5bcb7b609a3b52ce804306a63c4761282 (diff) | |
download | gdbm-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 'src')
-rw-r--r-- | src/gdbmdefs.h | 3 | ||||
-rw-r--r-- | src/gdbmopen.c | 8 | ||||
-rw-r--r-- | src/gdbmreorg.c | 3 |
3 files changed, 12 insertions, 2 deletions
diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h index b5922e3..519d688 100644 --- a/src/gdbmdefs.h +++ b/src/gdbmdefs.h @@ -156,6 +156,9 @@ struct gdbm_file_info { /* Whether or not we're allowing mmap() use. */ unsigned memory_mapping :1; + + /* Whether the database was open with GDBM_CLOEXEC flag */ + unsigned cloexec :1; /* Type of file locking in use. */ enum { LOCKING_NONE = 0, LOCKING_FLOCK, LOCKING_LOCKF, diff --git a/src/gdbmopen.c b/src/gdbmopen.c index ddd82e2..67db9c2 100644 --- a/src/gdbmopen.c +++ b/src/gdbmopen.c @@ -122,7 +122,13 @@ gdbm_open (const char *file, int block_size, int flags, int mode, dbf->file_locking = FALSE; } if (flags & GDBM_CLOEXEC) - fbits = O_CLOEXEC; + { + fbits = O_CLOEXEC; + dbf->cloexec = TRUE; + } + else + dbf->cloexec = FALSE; + /* Open the file. */ need_trunc = FALSE; switch (flags & GDBM_OPENMASK) diff --git a/src/gdbmreorg.c b/src/gdbmreorg.c index 5fc0d68..cc2a929 100644 --- a/src/gdbmreorg.c +++ b/src/gdbmreorg.c @@ -102,7 +102,8 @@ gdbm_reorganize (GDBM_FILE dbf) new_name[len] = '#'; /* Open the new database. */ - new_dbf = gdbm_open (new_name, dbf->header->block_size, GDBM_WRCREAT, + new_dbf = gdbm_open (new_name, dbf->header->block_size, + GDBM_WRCREAT | (dbf->cloexec ? GDBM_CLOEXEC : 0), fileinfo.st_mode, dbf->fatal_err); if (new_dbf == NULL) |