summaryrefslogtreecommitdiff
path: root/ext/sdbm/_sdbm.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-27 21:07:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-27 21:07:23 +0000
commit509ed0d94fea08f9e08767ddfa8564b9f9237c88 (patch)
tree05780444277623c0739f9a7e5b3e4ff3878646df /ext/sdbm/_sdbm.c
parenta5a7e2cd91173f12eb0007f8a55f36b84a3fab13 (diff)
* ext/sdbm/_sdbm.c (sdbm_prep): set FD_CLOEXEC flags for file
descriptors. (fd_set_cloexec): new function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/sdbm/_sdbm.c')
-rw-r--r--ext/sdbm/_sdbm.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/ext/sdbm/_sdbm.c b/ext/sdbm/_sdbm.c
index 64cda29437c..07903ca9b15 100644
--- a/ext/sdbm/_sdbm.c
+++ b/ext/sdbm/_sdbm.c
@@ -178,6 +178,29 @@ sdbm_open(register char *file, register int flags, register int mode)
return db;
}
+static int
+fd_set_cloexec(int fd)
+{
+ /* MinGW don't have F_GETFD and FD_CLOEXEC. [ruby-core:40281] */
+#ifdef F_GETFD
+ int flags, ret;
+ flags = fcntl(fd, F_GETFD); /* should not fail except EBADF. */
+ if (flags == -1) {
+ return -1;
+ }
+ if (2 < fd) {
+ if (!(flags & FD_CLOEXEC)) {
+ flags |= FD_CLOEXEC;
+ ret = fcntl(fd, F_SETFD, flags);
+ if (ret == -1) {
+ return -1;
+ }
+ }
+ }
+#endif
+ return 0;
+}
+
DBM *
sdbm_prep(char *dirname, char *pagname, int flags, int mode)
{
@@ -209,7 +232,9 @@ sdbm_prep(char *dirname, char *pagname, int flags, int mode)
flags |= O_BINARY;
if ((db->pagf = open(pagname, flags, mode)) == -1) goto err;
+ if (fd_set_cloexec(db->pagf) == -1) goto err;
if ((db->dirf = open(dirname, flags, mode)) == -1) goto err;
+ if (fd_set_cloexec(db->dirf) == -1) goto err;
/*
* need the dirfile size to establish max bit number.
*/