diff --git a/ChangeLog b/ChangeLog index bc6d8cfe58..ec0a19442d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Oct 31 22:04:54 2011 Tanaka Akira + + * ext/dbm/dbm.c (fdbm_initialize): use O_CLOEXEC if available. + Mon Oct 31 21:47:48 2011 Tanaka Akira * include/ruby/intern.h (rb_fd_fix_cloexec): renamed from diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index 6d5396066d..9b52a4eac2 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); } }