diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-05-17 01:15:45 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-05-17 01:15:45 +0000 |
commit | c9491ee9754a9ee93ab7b8a0e4c0bd1954a5164a (patch) | |
tree | 6a16d024be2151c1a903df2bf78ce5c143b6b226 /lib/libc | |
parent | f13075bb9201775d106b03d2037724269351fb23 (diff) |
Use fcntl() to set non-blocking-mode, rather ioctl(). This has a better
chance of working in systrace restricted environments.
ok guenther
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/rpc/clnt_udp.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/libc/rpc/clnt_udp.c b/lib/libc/rpc/clnt_udp.c index 1939ac1cfce..af43cc082e2 100644 --- a/lib/libc/rpc/clnt_udp.c +++ b/lib/libc/rpc/clnt_udp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clnt_udp.c,v 1.27 2014/11/11 04:51:49 guenther Exp $ */ +/* $OpenBSD: clnt_udp.c,v 1.28 2015/05/17 01:15:44 deraadt Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -39,9 +39,9 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <fcntl.h> #include <rpc/rpc.h> #include <sys/socket.h> -#include <sys/ioctl.h> #include <netdb.h> #include <errno.h> #include <rpc/pmap_clnt.h> @@ -160,7 +160,7 @@ clntudp_bufcreate(struct sockaddr_in *raddr, u_long program, u_long version, } cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs)); if (*sockp < 0) { - int dontblock = 1; + int fl; *sockp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (*sockp < 0) { @@ -171,7 +171,23 @@ clntudp_bufcreate(struct sockaddr_in *raddr, u_long program, u_long version, /* attempt to bind to priv port */ (void)bindresvport(*sockp, NULL); /* the sockets rpc controls are non-blocking */ - (void)ioctl(*sockp, FIONBIO, (char *) &dontblock); + + fl = fcntl(*sockp, F_GETFL); + if (fl == -1) { + close(*sockp); + rpc_createerr.cf_stat = RPC_SYSTEMERROR; + rpc_createerr.cf_error.re_errno = errno; + goto fooy; + } + if ((fl & O_NONBLOCK) == 0) { + fl |= O_NONBLOCK; + if (fcntl(*sockp, F_SETFL, fl) == -1) { + close(*sockp); + rpc_createerr.cf_stat = RPC_SYSTEMERROR; + rpc_createerr.cf_error.re_errno = errno; + goto fooy; + } + } cu->cu_closeit = TRUE; } else { cu->cu_closeit = FALSE; |