summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2015-11-23 19:31:52 +0000
committerreyk <reyk@openbsd.org>2015-11-23 19:31:52 +0000
commit5f0d8540be12ea6fd3b1dfbeabdb247ce580ef4a (patch)
tree101434e0b225210123e99a7395114742f59bde51
parentReplace socket_set_blockmode() and fcntl(fd, F_SETFL, O_NONBLOCK) calls (diff)
downloadwireguard-openbsd-5f0d8540be12ea6fd3b1dfbeabdb247ce580ef4a.tar.xz
wireguard-openbsd-5f0d8540be12ea6fd3b1dfbeabdb247ce580ef4a.zip
Use SOCK_NONBLOCK to replace socket_set_blockmode() and fcntl(..O_NONBLOCK).
(SOCK_CLOEXEC should also be added where it is appropriate, but this is OBnot done in this commit yet.) OK claudio@
-rw-r--r--usr.sbin/snmpd/control.c11
-rw-r--r--usr.sbin/snmpd/proc.c8
-rw-r--r--usr.sbin/snmpd/snmpd.c19
-rw-r--r--usr.sbin/snmpd/snmpd.h9
4 files changed, 9 insertions, 38 deletions
diff --git a/usr.sbin/snmpd/control.c b/usr.sbin/snmpd/control.c
index 3981ca4983e..b705c248fc0 100644
--- a/usr.sbin/snmpd/control.c
+++ b/usr.sbin/snmpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.34 2015/11/21 13:09:47 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.35 2015/11/23 19:31:52 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -60,7 +60,7 @@ control_init(struct privsep *ps, struct control_sock *cs)
if (cs->cs_name == NULL)
return (0);
- if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1) {
log_warn("%s: socket", __func__);
return (-1);
}
@@ -103,7 +103,6 @@ control_init(struct privsep *ps, struct control_sock *cs)
return (-1);
}
- socket_set_blockmode(fd, BM_NONBLOCK);
cs->cs_fd = fd;
cs->cs_env = env;
@@ -153,8 +152,8 @@ control_accept(int listenfd, short event, void *arg)
return;
len = sizeof(sun);
- if ((connfd = accept(listenfd,
- (struct sockaddr *)&sun, &len)) == -1) {
+ if ((connfd = accept4(listenfd,
+ (struct sockaddr *)&sun, &len, SOCK_NONBLOCK)) == -1) {
/*
* Pause accept if we are out of file descriptors, or
* libevent will haunt us here too.
@@ -170,8 +169,6 @@ control_accept(int listenfd, short event, void *arg)
return;
}
- socket_set_blockmode(connfd, BM_NONBLOCK);
-
if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) {
close(connfd);
log_warn("%s: calloc", __func__);
diff --git a/usr.sbin/snmpd/proc.c b/usr.sbin/snmpd/proc.c
index 89526001cbb..80c94a9d2f2 100644
--- a/usr.sbin/snmpd/proc.c
+++ b/usr.sbin/snmpd/proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.c,v 1.16 2015/11/23 16:43:55 reyk Exp $ */
+/* $OpenBSD: proc.c,v 1.17 2015/11/23 19:31:52 reyk Exp $ */
/*
* Copyright (c) 2010 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -174,13 +174,11 @@ proc_open(struct privsep *ps, struct privsep_proc *p,
if (pa->pp_pipes[procs[proc].p_id][j] != -1)
continue;
- if (socketpair(AF_UNIX, SOCK_STREAM,
+ if (socketpair(AF_UNIX,
+ SOCK_STREAM | SOCK_NONBLOCK,
PF_UNSPEC, fds) == -1)
fatal("socketpair");
- socket_set_blockmode(fds[0], BM_NONBLOCK);
- socket_set_blockmode(fds[1], BM_NONBLOCK);
-
pa->pp_pipes[procs[proc].p_id][j] = fds[0];
pb->pp_pipes[src][i] = fds[1];
}
diff --git a/usr.sbin/snmpd/snmpd.c b/usr.sbin/snmpd/snmpd.c
index e176b20bcd8..9f9eda56bf5 100644
--- a/usr.sbin/snmpd/snmpd.c
+++ b/usr.sbin/snmpd/snmpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpd.c,v 1.30 2015/11/22 13:27:13 reyk Exp $ */
+/* $OpenBSD: snmpd.c,v 1.31 2015/11/23 19:31:52 reyk Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
@@ -373,20 +373,3 @@ tohexstr(u_int8_t *str, int len)
*r = '\0';
return hstr;
}
-
-void
-socket_set_blockmode(int fd, enum blockmodes bm)
-{
- int flags;
-
- if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
- fatal("fcntl F_GETFL");
-
- if (bm == BM_NONBLOCK)
- flags |= O_NONBLOCK;
- else
- flags &= ~O_NONBLOCK;
-
- if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
- fatal("fcntl F_SETFL");
-}
diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h
index d98905ea2cf..77c580569d3 100644
--- a/usr.sbin/snmpd/snmpd.h
+++ b/usr.sbin/snmpd/snmpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpd.h,v 1.64 2015/11/22 13:27:13 reyk Exp $ */
+/* $OpenBSD: snmpd.h,v 1.65 2015/11/23 19:31:52 reyk Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
@@ -173,11 +173,6 @@ struct privsep_proc {
u_int p_instance;
};
-enum blockmodes {
- BM_NORMAL,
- BM_NONBLOCK
-};
-
/*
* kroute
*/
@@ -585,8 +580,6 @@ int control_init(struct privsep *, struct control_sock *);
int control_listen(struct control_sock *);
void control_cleanup(struct control_sock *);
-void socket_set_blockmode(int, enum blockmodes);
-
/* parse.y */
struct snmpd *parse_config(const char *, u_int);
int cmdline_symset(char *);