- 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@
diff --git a/ChangeLog b/ChangeLog
index 36aeb85..d1d45db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -29,6 +29,10 @@
[readconf.h scp.1 sftp.1 ssh.1 ssh.c ssh_config.5]
implement session multiplexing in the client (the server has supported
this since 2.0); ok markus@
+ - 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@
20040603
- (dtucker) [auth-pam.c] Don't use pam_* namespace for sshd's PAM functions.
@@ -1213,4 +1217,4 @@
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
-$Id: ChangeLog,v 1.3382 2004/06/15 00:34:08 djm Exp $
+$Id: ChangeLog,v 1.3383 2004/06/15 00:35:30 djm Exp $
diff --git a/channels.c b/channels.c
index 1fb1092..97c1fd3 100644
--- a/channels.c
+++ b/channels.c
@@ -39,7 +39,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: channels.c,v 1.204 2004/06/13 15:03:02 djm Exp $");
+RCSID("$OpenBSD: channels.c,v 1.205 2004/06/14 01:44:38 djm Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -2509,8 +2509,8 @@
verbose("socket: %.100s", strerror(errno));
continue;
}
- if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0)
- fatal("connect_to: F_SETFL: %s", strerror(errno));
+ if (set_nonblock(sock) == -1)
+ fatal("%s: set_nonblock(%d)", __func__, sock);
if (connect(sock, ai->ai_addr, ai->ai_addrlen) < 0 &&
errno != EINPROGRESS) {
error("connect_to %.100s port %s: %.100s", ntop, strport,
diff --git a/clientloop.c b/clientloop.c
index 6401588..eada560 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -59,7 +59,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: clientloop.c,v 1.123 2004/06/13 15:03:02 djm Exp $");
+RCSID("$OpenBSD: clientloop.c,v 1.124 2004/06/14 01:44:38 djm Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -167,7 +167,7 @@
enter_non_blocking(void)
{
in_non_blocking_mode = 1;
- (void) fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
+ set_nonblock(fileno(stdin));
}
/*
diff --git a/misc.c b/misc.c
index 1f32035..1c43bc0 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 @@
}
/* set/unset filedescriptor to non-blocking */
-void
+int
set_nonblock(int fd)
{
int val;
@@ -54,20 +54,23 @@
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 @@
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 */
diff --git a/misc.h b/misc.h
index d4a23cb..6a4eff1 100644
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.14 2004/05/08 00:21:31 djm Exp $ */
+/* $OpenBSD: misc.h,v 1.15 2004/06/14 01:44:39 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -16,8 +16,8 @@
char *chop(char *);
char *strdelim(char **);
-void set_nonblock(int);
-void unset_nonblock(int);
+int set_nonblock(int);
+int unset_nonblock(int);
void set_nodelay(int);
int a2port(const char *);
char *cleanhostname(char *);
diff --git a/packet.c b/packet.c
index fe3eea0..fca0075 100644
--- a/packet.c
+++ b/packet.c
@@ -37,7 +37,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: packet.c,v 1.113 2004/05/11 19:01:43 deraadt Exp $");
+RCSID("$OpenBSD: packet.c,v 1.114 2004/06/14 01:44:39 djm Exp $");
#include "openbsd-compat/sys-queue.h"
@@ -319,13 +319,10 @@
packet_set_nonblocking(void)
{
/* Set the socket into non-blocking mode. */
- if (fcntl(connection_in, F_SETFL, O_NONBLOCK) < 0)
- error("fcntl O_NONBLOCK: %.100s", strerror(errno));
+ set_nonblock(connection_in);
- if (connection_out != connection_in) {
- if (fcntl(connection_out, F_SETFL, O_NONBLOCK) < 0)
- error("fcntl O_NONBLOCK: %.100s", strerror(errno));
- }
+ if (connection_out != connection_in)
+ set_nonblock(connection_out);
}
/* Returns the socket used for reading. */
diff --git a/ssh-agent.c b/ssh-agent.c
index a383221..ea84f21 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -35,7 +35,7 @@
#include "includes.h"
#include "openbsd-compat/sys-queue.h"
-RCSID("$OpenBSD: ssh-agent.c,v 1.118 2004/05/08 00:21:31 djm Exp $");
+RCSID("$OpenBSD: ssh-agent.c,v 1.119 2004/06/14 01:44:39 djm Exp $");
#include <openssl/evp.h>
#include <openssl/md5.h>
@@ -789,8 +789,7 @@
{
u_int i, old_alloc, new_alloc;
- if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
- error("fcntl O_NONBLOCK: %s", strerror(errno));
+ set_nonblock(fd);
if (fd > max_fd)
max_fd = fd;
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index c4a2414..01615b5 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -7,7 +7,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-keyscan.c,v 1.48 2004/06/13 12:53:24 djm Exp $");
+RCSID("$OpenBSD: ssh-keyscan.c,v 1.49 2004/06/14 01:44:39 djm Exp $");
#include "openbsd-compat/sys-queue.h"
@@ -397,8 +397,8 @@
error("socket: %s", strerror(errno));
continue;
}
- if (fcntl(s, F_SETFL, O_NONBLOCK) < 0)
- fatal("F_SETFL: %s", strerror(errno));
+ if (set_nonblock(s) == -1)
+ fatal("%s: set_nonblock(%d)", __func__, s);
if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0 &&
errno != EINPROGRESS)
error("connect (`%s'): %s", host, strerror(errno));
diff --git a/sshd.c b/sshd.c
index 5f38781..3437917 100644
--- a/sshd.c
+++ b/sshd.c
@@ -42,7 +42,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: sshd.c,v 1.292 2004/06/13 12:53:24 djm Exp $");
+RCSID("$OpenBSD: sshd.c,v 1.293 2004/06/14 01:44:39 djm Exp $");
#include <openssl/dh.h>
#include <openssl/bn.h>
@@ -1140,8 +1140,7 @@
verbose("socket: %.100s", strerror(errno));
continue;
}
- if (fcntl(listen_sock, F_SETFL, O_NONBLOCK) < 0) {
- error("listen_sock O_NONBLOCK: %s", strerror(errno));
+ if (set_nonblock(listen_sock) == -1) {
close(listen_sock);
continue;
}
@@ -1284,8 +1283,7 @@
error("accept: %.100s", strerror(errno));
continue;
}
- if (fcntl(newsock, F_SETFL, 0) < 0) {
- error("newsock del O_NONBLOCK: %s", strerror(errno));
+ if (unset_nonblock(newsock) == -1) {
close(newsock);
continue;
}