summaryrefslogtreecommitdiff
path: root/usr.sbin/cron
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2015-10-26 15:16:31 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2015-10-26 15:16:31 +0000
commit1601fdb2485d3d18165ae623db5d3e29d62bead1 (patch)
treec7ac2f259be97864733e1f57e5c0c467c1d06278 /usr.sbin/cron
parent3245efed863c7e6267b46264a1d988f788c2379b (diff)
Use SOCK_NONBLOCK and SOCK_CLOEXEC instead of fcntl() calls.
OK guenther@
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/cron.c7
-rw-r--r--usr.sbin/cron/misc.c18
2 files changed, 6 insertions, 19 deletions
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)) {