diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-05 22:04:36 +0200 |
---|---|---|
committer | Austin Foxley <austinf@cetoncorp.com> | 2009-09-18 11:21:25 -0700 |
commit | 12b4c6b14c197397b47122c1a6c60e179d83376f (patch) | |
tree | 2a9021b36d03c76c55bfced8fbb221fa814dbf08 /libc/misc/utmp/utent.c | |
parent | 2b5155d358188649cc7a6653b5968b514fbfe9cf (diff) | |
download | uClibc-alpine-12b4c6b14c197397b47122c1a6c60e179d83376f.tar.bz2 uClibc-alpine-12b4c6b14c197397b47122c1a6c60e179d83376f.tar.xz |
CLOEXEC: use open(CLOEXEC) if exist; do not check fcntl(FD_CLOEXEC) failure
text data bss dec hex filename
- 370 0 0 370 172 libc/misc/dirent/opendir.o
+ 366 0 0 366 16e libc/misc/dirent/opendir.o
- 375 4 0 379 17b libc/pwd_grp/lckpwdf.o
+ 356 4 0 360 168 libc/pwd_grp/lckpwdf.o
- 248 0 0 248 f8 librt/shm.o
+ 209 0 0 209 d1 librt/shm.o
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Diffstat (limited to 'libc/misc/utmp/utent.c')
-rw-r--r-- | libc/misc/utmp/utent.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index dc3110fe9..eca2ba14e 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -38,36 +38,43 @@ static const char *static_ut_name = default_file_name; static void __setutent(void) { if (static_fd < 0) { +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + #ifdef __UCLIBC_HAS_THREADS_NATIVE__ - static_fd = open(static_ut_name, O_RDWR); + static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); #else - static_fd = open_not_cancel_2(static_ut_name, O_RDWR); + static_fd = open(static_ut_name, O_RDWR | O_CLOEXEC); #endif if (static_fd < 0) { #ifdef __UCLIBC_HAS_THREADS_NATIVE__ - static_fd = open(static_ut_name, O_RDONLY); + static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); #else - static_fd = open(static_ut_name, O_RDONLY); + static_fd = open(static_ut_name, O_RDONLY | O_CLOEXEC); #endif if (static_fd < 0) { return; /* static_fd remains < 0 */ } } - /* Make sure the file will be closed on exec() */ + + if (O_CLOEXEC == 0) { + /* Make sure the file will be closed on exec() */ #ifdef __UCLIBC_HAS_THREADS_NATIVE__ - fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC); + fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC); #else - fcntl(static_fd, F_SETFD, FD_CLOEXEC); + fcntl(static_fd, F_SETFD, FD_CLOEXEC); #endif - // thus far, {G,S}ETFD only has this single flag, - // and setting it never fails. - //int ret = fcntl(static_fd, F_GETFD, 0); - //if (ret >= 0) { - // ret = fcntl(static_fd, F_SETFD, ret | FD_CLOEXEC); - //} - //if (ret < 0) { - // static_fd = -1; - //} + // thus far, {G,S}ETFD only has this single flag, + // and setting it never fails. + //int ret = fcntl(static_fd, F_GETFD, 0); + //if (ret >= 0) { + // ret = fcntl(static_fd, F_SETFD, ret | FD_CLOEXEC); + //} + //if (ret < 0) { + // static_fd = -1; + //} + } return; } lseek(static_fd, 0, SEEK_SET); |