From: Thomas Veerman Date: Thu, 10 Jan 2013 15:31:30 +0000 (+0000) Subject: VFS: add ability to open files O_CLOEXEC X-Git-Tag: v3.3.0~1119 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/static/gitweb.css?a=commitdiff_plain;h=fd610ba1b08b5886880f3081451f19b0362d0fa4;p=minix.git VFS: add ability to open files O_CLOEXEC .adjust libc to make use of it (undo __minix diff) Change-Id: I90a1aa219fcd1b12b6bc60e72176f326eac8184a --- diff --git a/lib/libc/citrus/citrus_mmap.c b/lib/libc/citrus/citrus_mmap.c index 3f338faf7..53dc65930 100644 --- a/lib/libc/citrus/citrus_mmap.c +++ b/lib/libc/citrus/citrus_mmap.c @@ -46,10 +46,6 @@ __RCSID("$NetBSD: citrus_mmap.c,v 1.4 2011/10/15 23:00:01 christos Exp $"); #include "citrus_region.h" #include "citrus_mmap.h" -#if defined(__minix) && !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - int _citrus_map_file(struct _citrus_region * __restrict r, const char * __restrict path) diff --git a/lib/libc/db/recno/rec_open.c b/lib/libc/db/recno/rec_open.c index fa5237572..cc1863fa1 100644 --- a/lib/libc/db/recno/rec_open.c +++ b/lib/libc/db/recno/rec_open.c @@ -70,15 +70,8 @@ __rec_open(const char *fname, int flags, mode_t mode, const RECNOINFO *openinfo, dbp = NULL; /* Open the user's file -- if this fails, we're done. */ if (fname != NULL) { -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif if ((rfd = open(fname, flags | O_CLOEXEC, mode)) == -1) return NULL; -#if O_CLOEXEC == 0 - if (fcntl(rfd, F_SETFD, FD_CLOEXEC) == -1) - goto err; -#endif } /* Create a btree in memory (backed by disk). */ diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 16af0d43b..b83b0ab72 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -213,9 +213,6 @@ fts_open(char * const *argv, int options, * and ".." are all fairly nasty problems. Note, if we can't get the * descriptor we run anyway, just more slowly. */ -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif if (!ISSET(FTS_NOCHDIR)) { if ((sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) SET(FTS_NOCHDIR); diff --git a/lib/libc/gen/initdir.c b/lib/libc/gen/initdir.c index 2a6e74dcf..8c1785153 100644 --- a/lib/libc/gen/initdir.c +++ b/lib/libc/gen/initdir.c @@ -42,10 +42,6 @@ __RCSID("$NetBSD: initdir.c,v 1.3 2012/03/13 21:13:36 christos Exp $"); #include #include -#if !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - #endif #include "reentrant.h" diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 2229dfdef..787f513ce 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -45,10 +45,6 @@ __RCSID("$NetBSD: opendir.c,v 1.38 2011/10/15 23:00:01 christos Exp $"); #include #include -#if !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - #endif #include "extern.h" @@ -94,12 +90,6 @@ __opendir2(const char *name, int flags) if ((fd = open(name, O_RDONLY | O_NONBLOCK | O_CLOEXEC)) == -1) return NULL; -#if defined(__minix) - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { - close(fd); - return NULL; - } -#endif /* defined(__minix) */ return __opendir_common(fd, name, flags); } diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c index aa58d8493..593e34631 100644 --- a/lib/libc/gen/popen.c +++ b/lib/libc/gen/popen.c @@ -59,10 +59,6 @@ __RCSID("$NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $"); #include "env.h" #include "reentrant.h" -#if defined(__minix) && !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - #ifdef __weak_alias __weak_alias(popen,_popen) __weak_alias(pclose,_pclose) diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c index a0a2d5a4a..1892d02e5 100644 --- a/lib/libc/stdio/flags.c +++ b/lib/libc/stdio/flags.c @@ -49,10 +49,6 @@ __RCSID("$NetBSD: flags.c,v 1.16 2012/03/15 18:22:30 christos Exp $"); #include "reentrant.h" #include "local.h" -#if defined(__minix) && !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - /* * Return the (stdio) flags for a given mode. Store the flags * to be passed to an open() syscall through *optr. diff --git a/lib/libc/sys/adjtime.c b/lib/libc/sys/adjtime.c index b45f516b5..1f96c7306 100644 --- a/lib/libc/sys/adjtime.c +++ b/lib/libc/sys/adjtime.c @@ -49,10 +49,6 @@ __RCSID("$NetBSD: adjtime.c,v 1.12 2011/10/15 23:00:02 christos Exp $"); #include -#if defined(__minix) && !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - extern int __clockctl_fd; int ____adjtime50(const struct timeval *, struct timeval *); diff --git a/lib/libc/sys/clock_settime.c b/lib/libc/sys/clock_settime.c index 203347dbd..a1770d7bb 100644 --- a/lib/libc/sys/clock_settime.c +++ b/lib/libc/sys/clock_settime.c @@ -51,10 +51,6 @@ __RCSID("$NetBSD: clock_settime.c,v 1.12 2011/10/15 23:00:02 christos Exp $"); #include -#if defined(__minix) && !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - extern int __clockctl_fd; int ____clock_settime50(clockid_t, const struct timespec *); diff --git a/lib/libc/sys/ntp_adjtime.c b/lib/libc/sys/ntp_adjtime.c index d0ef35fb9..efe0ddb86 100644 --- a/lib/libc/sys/ntp_adjtime.c +++ b/lib/libc/sys/ntp_adjtime.c @@ -55,10 +55,6 @@ __RCSID("$NetBSD: ntp_adjtime.c,v 1.13 2012/03/20 16:26:12 matt Exp $"); __weak_alias(ntp_adjtime,_ntp_adjtime) #endif -#if defined(__minix) && !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - extern int __clockctl_fd; int __ntp_adjtime(struct timex *); diff --git a/lib/libc/sys/settimeofday.c b/lib/libc/sys/settimeofday.c index 12f131b75..2bc29b43d 100644 --- a/lib/libc/sys/settimeofday.c +++ b/lib/libc/sys/settimeofday.c @@ -51,10 +51,6 @@ __RCSID("$NetBSD: settimeofday.c,v 1.14 2011/10/15 23:00:02 christos Exp $"); #include #include -#if defined(__minix) && !defined(O_CLOEXEC) -#define O_CLOEXEC 0 -#endif - int __clockctl_fd = -1; int ____settimeofday50(const struct timeval *, const void *); diff --git a/servers/vfs/open.c b/servers/vfs/open.c index fc726955b..91e6713b0 100644 --- a/servers/vfs/open.c +++ b/servers/vfs/open.c @@ -160,6 +160,8 @@ int common_open(char path[PATH_MAX], int oflags, mode_t omode) filp->filp_count = 1; filp->filp_vno = vp; filp->filp_flags = oflags; + if (oflags & O_CLOEXEC) + FD_SET(scratch(fp).file.fd_nr, &fp->fp_cloexec_set); /* Only do the normal open code if we didn't just create the file. */ if (exist) { diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h index 695b715a6..fcfaa9ad5 100644 --- a/sys/sys/fcntl.h +++ b/sys/sys/fcntl.h @@ -72,6 +72,7 @@ #define O_REOPEN 010000 /* automatically re-open device after driver * restart */ +#define O_CLOEXEC 020000 /* close on exec */ #ifndef __minix /* NOT SUPPORTED! */