From 33229c10ed6c320049b860171d9d5b83ec676501 Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 9 Feb 2015 12:13:42 +0000 Subject: More session_socket_blockmode() removal. While there make the main UDP socket non-blocking by default. --- usr.sbin/ripd/control.c | 29 +++++------------------------ usr.sbin/ripd/control.h | 9 +-------- usr.sbin/ripd/interface.c | 5 +++-- usr.sbin/ripd/ripd.c | 18 +++++++----------- 4 files changed, 16 insertions(+), 45 deletions(-) (limited to 'usr.sbin/ripd') diff --git a/usr.sbin/ripd/control.c b/usr.sbin/ripd/control.c index 2a6f6aa4f9d..38165c497c5 100644 --- a/usr.sbin/ripd/control.c +++ b/usr.sbin/ripd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.20 2014/07/11 16:43:33 krw Exp $ */ +/* $OpenBSD: control.c,v 1.21 2015/02/09 12:13:42 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -45,7 +45,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); } @@ -77,7 +78,6 @@ control_init(void) return (-1); } - session_socket_blockmode(fd, BM_NONBLOCK); control_state.fd = fd; return (0); @@ -122,8 +122,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_CLOEXEC | SOCK_NONBLOCK)) == -1) { /* * Pause accept if we are out of file descriptors, or * libevent will haunt us here too. @@ -139,8 +139,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); @@ -313,20 +311,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/ripd/control.h b/usr.sbin/ripd/control.h index 6eeef82e7e6..67306ac4820 100644 --- a/usr.sbin/ripd/control.h +++ b/usr.sbin/ripd/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 12:13:42 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -29,11 +29,6 @@ struct { int fd; } control_state; -enum blockmodes { - BM_NORMAL, - BM_NONBLOCK -}; - struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; struct imsgev iev; @@ -46,6 +41,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/ripd/interface.c b/usr.sbin/ripd/interface.c index d3ae7799f14..65e5667578b 100644 --- a/usr.sbin/ripd/interface.c +++ b/usr.sbin/ripd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.11 2011/07/04 04:34:14 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.12 2015/02/09 12:13:42 claudio Exp $ */ /* * Copyright (c) 2006 Michele Marchetto @@ -405,7 +405,8 @@ if_new(struct kif *kif) /* set up ifreq */ strlcpy(ifr->ifr_name, kif->ifname, sizeof(ifr->ifr_name)); - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + if ((s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, + 0)) < 0) err(1, "if_new: socket"); /* get type */ diff --git a/usr.sbin/ripd/ripd.c b/usr.sbin/ripd/ripd.c index f779aaf25eb..efaeba35db0 100644 --- a/usr.sbin/ripd/ripd.c +++ b/usr.sbin/ripd/ripd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ripd.c,v 1.24 2015/01/16 06:40:20 deraadt Exp $ */ +/* $OpenBSD: ripd.c,v 1.25 2015/02/09 12:13:42 claudio Exp $ */ /* * Copyright (c) 2006 Michele Marchetto @@ -207,19 +207,15 @@ main(int argc, char *argv[]) log_info("startup"); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, - pipe_parent2ripe) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, + PF_UNSPEC, pipe_parent2ripe) == -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_ripe2rde) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, + PF_UNSPEC, pipe_ripe2rde) == -1) fatal("socketpair"); - session_socket_blockmode(pipe_parent2ripe[0], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2ripe[1], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2rde[0], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2rde[1], BM_NONBLOCK); - session_socket_blockmode(pipe_ripe2rde[0], BM_NONBLOCK); - session_socket_blockmode(pipe_ripe2rde[1], BM_NONBLOCK); /* start children */ rde_pid = rde(conf, pipe_parent2rde, pipe_ripe2rde, pipe_parent2ripe); -- cgit v1.2.3-59-g8ed1b