summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2004-06-15 10:35:30 +1000
committerDamien Miller <djm@mindrot.org>2004-06-15 10:35:30 +1000
commit232711f6dbc107711b3957bfa2fd798aec702241 (patch)
tree2dfcd276712caa022fd8aa2f3c1319c13660fdd7 /misc.c
parent0e220dbfbcc9fe252e8f1f4890dbfa415aad35db (diff)
downloadopenssh-git-232711f6dbc107711b3957bfa2fd798aec702241.tar.gz
- 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.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/misc.c b/misc.c
index 1f320353..1c43bc00 100644
--- a/misc.c
+++ b/misc.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: misc.c,v 1.23 2003/10/28 09:08:06 markus Exp $");
+RCSID("$OpenBSD: misc.c,v 1.24 2004/06/14 01:44:39 djm Exp $");
#include "misc.h"
#include "log.h"
@@ -46,7 +46,7 @@ chop(char *s)
}
/* set/unset filedescriptor to non-blocking */
-void
+int
set_nonblock(int fd)
{
int val;
@@ -54,20 +54,23 @@ set_nonblock(int fd)
val = fcntl(fd, F_GETFL, 0);
if (val < 0) {
error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
- return;
+ return (-1);
}
if (val & O_NONBLOCK) {
- debug2("fd %d is O_NONBLOCK", fd);
- return;
+ debug3("fd %d is O_NONBLOCK", fd);
+ return (0);
}
debug2("fd %d setting O_NONBLOCK", fd);
val |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, val) == -1)
- debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s",
- fd, strerror(errno));
+ if (fcntl(fd, F_SETFL, val) == -1) {
+ debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", fd,
+ strerror(errno));
+ return (-1);
+ }
+ return (0);
}
-void
+int
unset_nonblock(int fd)
{
int val;
@@ -75,17 +78,20 @@ unset_nonblock(int fd)
val = fcntl(fd, F_GETFL, 0);
if (val < 0) {
error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
- return;
+ return (-1);
}
if (!(val & O_NONBLOCK)) {
- debug2("fd %d is not O_NONBLOCK", fd);
- return;
+ debug3("fd %d is not O_NONBLOCK", fd);
+ return (0);
}
debug("fd %d clearing O_NONBLOCK", fd);
val &= ~O_NONBLOCK;
- if (fcntl(fd, F_SETFL, val) == -1)
- debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s",
+ if (fcntl(fd, F_SETFL, val) == -1) {
+ debug("fcntl(%d, F_SETFL, ~O_NONBLOCK): %s",
fd, strerror(errno));
+ return (-1);
+ }
+ return (0);
}
/* disable nagle on socket */