diff options
author | Damien Miller <djm@mindrot.org> | 2004-06-15 10:35:30 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2004-06-15 10:35:30 +1000 |
commit | 232711f6dbc107711b3957bfa2fd798aec702241 (patch) | |
tree | 2dfcd276712caa022fd8aa2f3c1319c13660fdd7 /misc.c | |
parent | 0e220dbfbcc9fe252e8f1f4890dbfa415aad35db (diff) |
- djm@cvs.openbsd.org 2004/06/14 01:44:39
[channels.c clientloop.c misc.c misc.h packet.c ssh-agent.c ssh-keyscan.c]
[sshd.c]
set_nonblock() instead of fnctl(...,O_NONBLOCK); "looks sane" deraadt@
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -23,7 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | RCSID("$OpenBSD: misc.c,v 1.23 2003/10/28 09:08:06 markus Exp $"); | 26 | RCSID("$OpenBSD: misc.c,v 1.24 2004/06/14 01:44:39 djm Exp $"); |
27 | 27 | ||
28 | #include "misc.h" | 28 | #include "misc.h" |
29 | #include "log.h" | 29 | #include "log.h" |
@@ -46,7 +46,7 @@ chop(char *s) | |||
46 | } | 46 | } |
47 | 47 | ||
48 | /* set/unset filedescriptor to non-blocking */ | 48 | /* set/unset filedescriptor to non-blocking */ |
49 | void | 49 | int |
50 | set_nonblock(int fd) | 50 | set_nonblock(int fd) |
51 | { | 51 | { |
52 | int val; | 52 | int val; |
@@ -54,20 +54,23 @@ set_nonblock(int fd) | |||
54 | val = fcntl(fd, F_GETFL, 0); | 54 | val = fcntl(fd, F_GETFL, 0); |
55 | if (val < 0) { | 55 | if (val < 0) { |
56 | error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); | 56 | error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); |
57 | return; | 57 | return (-1); |
58 | } | 58 | } |
59 | if (val & O_NONBLOCK) { | 59 | if (val & O_NONBLOCK) { |
60 | debug2("fd %d is O_NONBLOCK", fd); | 60 | debug3("fd %d is O_NONBLOCK", fd); |
61 | return; | 61 | return (0); |
62 | } | 62 | } |
63 | debug2("fd %d setting O_NONBLOCK", fd); | 63 | debug2("fd %d setting O_NONBLOCK", fd); |
64 | val |= O_NONBLOCK; | 64 | val |= O_NONBLOCK; |
65 | if (fcntl(fd, F_SETFL, val) == -1) | 65 | if (fcntl(fd, F_SETFL, val) == -1) { |
66 | debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", | 66 | debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", fd, |
67 | fd, strerror(errno)); | 67 | strerror(errno)); |
68 | return (-1); | ||
69 | } | ||
70 | return (0); | ||
68 | } | 71 | } |
69 | 72 | ||
70 | void | 73 | int |
71 | unset_nonblock(int fd) | 74 | unset_nonblock(int fd) |
72 | { | 75 | { |
73 | int val; | 76 | int val; |
@@ -75,17 +78,20 @@ unset_nonblock(int fd) | |||
75 | val = fcntl(fd, F_GETFL, 0); | 78 | val = fcntl(fd, F_GETFL, 0); |
76 | if (val < 0) { | 79 | if (val < 0) { |
77 | error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); | 80 | error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); |
78 | return; | 81 | return (-1); |
79 | } | 82 | } |
80 | if (!(val & O_NONBLOCK)) { | 83 | if (!(val & O_NONBLOCK)) { |
81 | debug2("fd %d is not O_NONBLOCK", fd); | 84 | debug3("fd %d is not O_NONBLOCK", fd); |
82 | return; | 85 | return (0); |
83 | } | 86 | } |
84 | debug("fd %d clearing O_NONBLOCK", fd); | 87 | debug("fd %d clearing O_NONBLOCK", fd); |
85 | val &= ~O_NONBLOCK; | 88 | val &= ~O_NONBLOCK; |
86 | if (fcntl(fd, F_SETFL, val) == -1) | 89 | if (fcntl(fd, F_SETFL, val) == -1) { |
87 | debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", | 90 | debug("fcntl(%d, F_SETFL, ~O_NONBLOCK): %s", |
88 | fd, strerror(errno)); | 91 | fd, strerror(errno)); |
92 | return (-1); | ||
93 | } | ||
94 | return (0); | ||
89 | } | 95 | } |
90 | 96 | ||
91 | /* disable nagle on socket */ | 97 | /* disable nagle on socket */ |