summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2015-02-09 11:45:22 +0000
committerclaudio <claudio@openbsd.org>2015-02-09 11:45:22 +0000
commit47c393532ffb1dceb5f45a30a8b5b89926beed8a (patch)
treed21ac80be5d98199eafd9ade6ffea33463c2399e
parentdon't cast malloc (diff)
downloadwireguard-openbsd-47c393532ffb1dceb5f45a30a8b5b89926beed8a.tar.xz
wireguard-openbsd-47c393532ffb1dceb5f45a30a8b5b89926beed8a.zip
Kill another session_socket_blockmode() ... 6 or so to go.
-rw-r--r--usr.sbin/dvmrpd/control.c29
-rw-r--r--usr.sbin/dvmrpd/control.h4
-rw-r--r--usr.sbin/dvmrpd/dvmrpd.c18
3 files changed, 13 insertions, 38 deletions
diff --git a/usr.sbin/dvmrpd/control.c b/usr.sbin/dvmrpd/control.c
index a2d3c3a7c7f..4483d54481f 100644
--- a/usr.sbin/dvmrpd/control.c
+++ b/usr.sbin/dvmrpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.19 2014/07/11 16:43:33 krw Exp $ */
+/* $OpenBSD: control.c,v 1.20 2015/02/09 11:45:22 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -46,7 +46,8 @@ control_init(void)
int fd;
mode_t old_umask;
- if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ 0)) == -1) {
log_warn("control_init: socket");
return (-1);
}
@@ -78,7 +79,6 @@ control_init(void)
return (-1);
}
- session_socket_blockmode(fd, BM_NONBLOCK);
control_state.fd = fd;
return (0);
@@ -123,8 +123,8 @@ control_accept(int listenfd, short event, void *bula)
return;
len = sizeof(sun);
- if ((connfd = accept(listenfd,
- (struct sockaddr *)&sun, &len)) == -1) {
+ if ((connfd = accept4(listenfd, (struct sockaddr *)&sun, &len,
+ SOCK_NONBLOCK | SOCK_CLOEXEC)) == -1) {
/*
* Pause accept if we are out of file descriptors, or
* libevent will haunt us here too.
@@ -140,8 +140,6 @@ control_accept(int listenfd, short event, void *bula)
return;
}
- session_socket_blockmode(connfd, BM_NONBLOCK);
-
if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) {
log_warn("control_accept");
close(connfd);
@@ -314,20 +312,3 @@ control_imsg_relay(struct imsg *imsg)
return (imsg_compose_event(&c->iev, imsg->hdr.type, 0, imsg->hdr.pid,
-1, imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE));
}
-
-void
-session_socket_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/dvmrpd/control.h b/usr.sbin/dvmrpd/control.h
index 6eeef82e7e6..dbf623683b5 100644
--- a/usr.sbin/dvmrpd/control.h
+++ b/usr.sbin/dvmrpd/control.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.h,v 1.3 2012/04/10 07:56:54 deraadt Exp $ */
+/* $OpenBSD: control.h,v 1.4 2015/02/09 11:45:22 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -46,6 +46,4 @@ void control_dispatch_imsg(int, short, void *);
int control_imsg_relay(struct imsg *);
void control_cleanup(void);
-void session_socket_blockmode(int, enum blockmodes);
-
#endif /* _CONTROL_H_ */
diff --git a/usr.sbin/dvmrpd/dvmrpd.c b/usr.sbin/dvmrpd/dvmrpd.c
index 1784b9be26a..21b8a24a963 100644
--- a/usr.sbin/dvmrpd/dvmrpd.c
+++ b/usr.sbin/dvmrpd/dvmrpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dvmrpd.c,v 1.17 2015/01/16 06:40:16 deraadt Exp $ */
+/* $OpenBSD: dvmrpd.c,v 1.18 2015/02/09 11:45:22 claudio Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -204,19 +204,15 @@ main(int argc, char *argv[])
log_info("startup");
- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
- pipe_parent2dvmrpe) == -1)
+ if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ PF_UNSPEC, pipe_parent2dvmrpe) == -1)
fatal("socketpair");
- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2rde) == -1)
+ if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ PF_UNSPEC, pipe_parent2rde) == -1)
fatal("socketpair");
- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_dvmrpe2rde) == -1)
+ if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ PF_UNSPEC, pipe_dvmrpe2rde) == -1)
fatal("socketpair");
- session_socket_blockmode(pipe_parent2dvmrpe[0], BM_NONBLOCK);
- session_socket_blockmode(pipe_parent2dvmrpe[1], BM_NONBLOCK);
- session_socket_blockmode(pipe_parent2rde[0], BM_NONBLOCK);
- session_socket_blockmode(pipe_parent2rde[1], BM_NONBLOCK);
- session_socket_blockmode(pipe_dvmrpe2rde[0], BM_NONBLOCK);
- session_socket_blockmode(pipe_dvmrpe2rde[1], BM_NONBLOCK);
/* start children */
rde_pid = rde(conf, pipe_parent2rde, pipe_dvmrpe2rde,