diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2014-11-04 01:20:28 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2014-11-04 01:20:28 +0000 |
commit | 9908b63b0671dcc2b4ca2f1c4567e9d82c7367af (patch) | |
tree | e32b64815395fa003fe6cfbd7f042e2e3161311f /sbin/dhclient/dhclient.c | |
parent | f7c14ddd55de0a869d6f0175fe891d779371bdbc (diff) |
Instead of correcting things after the fact, use SOCK_NONBLOCK and SOCK_CLOEXEC
to create the socketpair() with non-blocking and close-on-exec set.
ok krw@
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r-- | sbin/dhclient/dhclient.c | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index a93d1a4af57..e6f7ab3ae90 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.327 2014/11/03 02:22:15 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.328 2014/11/04 01:20:27 guenther Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -103,7 +103,6 @@ void write_file(char *, int, mode_t, uid_t, gid_t, u_int8_t *, size_t); struct client_lease *apply_defaults(struct client_lease *); struct client_lease *clone_lease(struct client_lease *); -void socket_nonblockmode(int); void apply_ignore_list(char *); void add_direct_route(int, struct in_addr, struct in_addr, struct in_addr); @@ -549,12 +548,9 @@ main(int argc, char *argv[]) if_register_receive(); if_register_send(); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, socket_fd) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, + PF_UNSPEC, socket_fd) == -1) error("socketpair: %s", strerror(errno)); - socket_nonblockmode(socket_fd[0]); - fcntl(socket_fd[0], F_SETFD, FD_CLOEXEC); - socket_nonblockmode(socket_fd[1]); - fcntl(socket_fd[1], F_SETFD, FD_CLOEXEC); fork_privchld(socket_fd[0], socket_fd[1]); @@ -2241,20 +2237,6 @@ cleanup: return (NULL); } -void -socket_nonblockmode(int fd) -{ - int flags; - - if ((flags = fcntl(fd, F_GETFL, 0)) == -1) - error("fcntl F_GETF: %s", strerror(errno)); - - flags |= O_NONBLOCK; - - if ((flags = fcntl(fd, F_SETFL, flags)) == -1) - error("fcntl F_SETFL: %s", strerror(errno)); -} - /* * Apply the list of options to be ignored that was provided on the * command line. This will override any ignore list obtained from |