summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--ext/dbm/dbm.c11
2 files changed, 11 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index bc6d8cf..ec0a194 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Oct 31 22:04:54 2011 Tanaka Akira <akr@fsij.org>
+
+ * ext/dbm/dbm.c (fdbm_initialize): use O_CLOEXEC if available.
+
Mon Oct 31 21:47:48 2011 Tanaka Akira <akr@fsij.org>
* include/ruby/intern.h (rb_fd_fix_cloexec): renamed from
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 6d53960..9b52a4e 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -137,20 +137,23 @@ fdbm_initialize(int argc, VALUE *argv, VALUE obj)
FilePathValue(file);
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
if (flags & RUBY_DBM_RW_BIT) {
flags &= ~RUBY_DBM_RW_BIT;
- dbm = dbm_open(RSTRING_PTR(file), flags, mode);
+ dbm = dbm_open(RSTRING_PTR(file), flags|O_CLOEXEC, mode);
}
else {
dbm = 0;
if (mode >= 0) {
- dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT, mode);
+ dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT|O_CLOEXEC, mode);
}
if (!dbm) {
- dbm = dbm_open(RSTRING_PTR(file), O_RDWR, 0);
+ dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CLOEXEC, 0);
}
if (!dbm) {
- dbm = dbm_open(RSTRING_PTR(file), O_RDONLY, 0);
+ dbm = dbm_open(RSTRING_PTR(file), O_RDONLY|O_CLOEXEC, 0);
}
}