summaryrefslogtreecommitdiff
path: root/libc/misc/utmp/utent.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/misc/utmp/utent.c')
-rw-r--r--libc/misc/utmp/utent.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c
index f0700af21..7d8a2d3c1 100644
--- a/libc/misc/utmp/utent.c
+++ b/libc/misc/utmp/utent.c
@@ -34,24 +34,29 @@ static const char *static_ut_name = default_file_name;
static void __setutent(void)
{
if (static_fd < 0) {
- static_fd = open(static_ut_name, O_RDWR);
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+ static_fd = open(static_ut_name, O_RDWR | O_CLOEXEC);
if (static_fd < 0) {
- static_fd = open(static_ut_name, O_RDONLY);
+ static_fd = open(static_ut_name, O_RDONLY | O_CLOEXEC);
if (static_fd < 0) {
return; /* static_fd remains < 0 */
}
}
- /* Make sure the file will be closed on exec() */
- fcntl(static_fd, F_SETFD, FD_CLOEXEC);
- // 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;
- //}
+ if (O_CLOEXEC == 0) {
+ /* Make sure the file will be closed on exec() */
+ fcntl(static_fd, F_SETFD, FD_CLOEXEC);
+ // 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);