diff options
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.102 2016/03/02 22:42:40 dtucker Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.103 2016/04/02 14:37:42 krw Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -84,9 +84,9 @@ set_nonblock(int fd) | |||
84 | { | 84 | { |
85 | int val; | 85 | int val; |
86 | 86 | ||
87 | val = fcntl(fd, F_GETFL, 0); | 87 | val = fcntl(fd, F_GETFL); |
88 | if (val < 0) { | 88 | if (val < 0) { |
89 | error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); | 89 | error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
90 | return (-1); | 90 | return (-1); |
91 | } | 91 | } |
92 | if (val & O_NONBLOCK) { | 92 | if (val & O_NONBLOCK) { |
@@ -108,9 +108,9 @@ unset_nonblock(int fd) | |||
108 | { | 108 | { |
109 | int val; | 109 | int val; |
110 | 110 | ||
111 | val = fcntl(fd, F_GETFL, 0); | 111 | val = fcntl(fd, F_GETFL); |
112 | if (val < 0) { | 112 | if (val < 0) { |
113 | error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); | 113 | error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
114 | return (-1); | 114 | return (-1); |
115 | } | 115 | } |
116 | if (!(val & O_NONBLOCK)) { | 116 | if (!(val & O_NONBLOCK)) { |
@@ -729,16 +729,16 @@ sanitise_stdfd(void) | |||
729 | strerror(errno)); | 729 | strerror(errno)); |
730 | exit(1); | 730 | exit(1); |
731 | } | 731 | } |
732 | while (++dupfd <= 2) { | 732 | while (++dupfd <= STDERR_FILENO) { |
733 | /* Only clobber closed fds */ | 733 | /* Only populate closed fds. */ |
734 | if (fcntl(dupfd, F_GETFL, 0) >= 0) | 734 | if (fcntl(dupfd, F_GETFL) == -1 && errno == EBADF) { |
735 | continue; | 735 | if (dup2(nullfd, dupfd) == -1) { |
736 | if (dup2(nullfd, dupfd) == -1) { | 736 | fprintf(stderr, "dup2: %s\n", strerror(errno)); |
737 | fprintf(stderr, "dup2: %s\n", strerror(errno)); | 737 | exit(1); |
738 | exit(1); | 738 | } |
739 | } | 739 | } |
740 | } | 740 | } |
741 | if (nullfd > 2) | 741 | if (nullfd > STDERR_FILENO) |
742 | close(nullfd); | 742 | close(nullfd); |
743 | } | 743 | } |
744 | 744 | ||