From: millert Date: Mon, 26 Oct 2015 15:16:30 +0000 (+0000) Subject: Use SOCK_NONBLOCK and SOCK_CLOEXEC instead of fcntl() calls. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5ce06057bae089b324728019ffece0c94d3cc089;p=openbsd Use SOCK_NONBLOCK and SOCK_CLOEXEC instead of fcntl() calls. OK guenther@ --- diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c index 88deab1eba5..02d86339a4a 100644 --- a/usr.sbin/cron/cron.c +++ b/usr.sbin/cron/cron.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cron.c,v 1.56 2015/10/26 14:27:41 millert Exp $ */ +/* $OpenBSD: cron.c,v 1.57 2015/10/26 15:16:30 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -345,8 +345,9 @@ cron_sleep(time_t target, sigset_t *mask) break; /* an error occurred */ if (nfds > 0) { sunlen = sizeof(s_un); - fd = accept(cronSock, (struct sockaddr *)&s_un, &sunlen); - if (fd >= 0 && fcntl(fd, F_SETFL, O_NONBLOCK) == 0) { + fd = accept4(cronSock, (struct sockaddr *)&s_un, + &sunlen, SOCK_NONBLOCK); + if (fd >= 0) { (void) read(fd, &poke, 1); close(fd); if (poke & RELOAD_CRON) { diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c index 5677cf988a7..6073dd81db4 100644 --- a/usr.sbin/cron/misc.c +++ b/usr.sbin/cron/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.59 2015/10/26 14:27:41 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.60 2015/10/26 15:16:30 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -405,27 +405,13 @@ open_socket(void) mode_t omask; struct sockaddr_un s_un; - sock = socket(AF_UNIX, SOCK_STREAM, 0); + sock = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); if (sock == -1) { fprintf(stderr, "%s: can't create socket: %s\n", ProgramName, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't create socket"); exit(EXIT_FAILURE); } - if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { - fprintf(stderr, "%s: can't make socket close on exec: %s\n", - ProgramName, strerror(errno)); - log_it("CRON", getpid(), "DEATH", - "can't make socket close on exec"); - exit(EXIT_FAILURE); - } - if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) { - fprintf(stderr, "%s: can't make socket non-blocking: %s\n", - ProgramName, strerror(errno)); - log_it("CRON", getpid(), "DEATH", - "can't make socket non-blocking"); - exit(EXIT_FAILURE); - } bzero(&s_un, sizeof(s_un)); if (snprintf(s_un.sun_path, sizeof s_un.sun_path, "%s/%s", SPOOL_DIR, CRONSOCK) >= sizeof(s_un.sun_path)) {