From be425821c4bf87c743b8107c28804f3c67054943 Mon Sep 17 00:00:00 2001 From: millert Date: Fri, 21 Jan 2022 22:53:20 +0000 Subject: [PATCH] Treat ppoll(2) errors as fatal. OK deraadt@ --- usr.sbin/cron/cron.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c index 6fe8916141d..831a70d5411 100644 --- a/usr.sbin/cron/cron.c +++ b/usr.sbin/cron/cron.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cron.c,v 1.79 2020/04/16 17:51:56 millert Exp $ */ +/* $OpenBSD: cron.c,v 1.80 2022/01/21 22:53:20 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -368,11 +368,21 @@ cron_sleep(time_t target, sigset_t *mask) /* Sleep until we time out, get a poke, or get a signal. */ nfds = ppoll(pfd, 1, &timeout, mask); - if (nfds == 0) - break; /* timer expired */ - if (nfds == -1 && errno != EINTR) - break; /* an error occurred */ - if (nfds > 0) { + switch (nfds) { + case -1: + if (errno != EINTR && errno != EAGAIN) + err(EXIT_FAILURE, "ppoll"); + if (errno == EINTR) { + if (got_sigchld) { + got_sigchld = 0; + sigchld_reaper(); + } + } + break; + case 0: + /* done sleeping */ + return; + default: sunlen = sizeof(s_un); fd = accept4(cronSock, (struct sockaddr *)&s_un, &sunlen, SOCK_NONBLOCK); @@ -396,12 +406,6 @@ cron_sleep(time_t target, sigset_t *mask) batch_maxload, t2.tv_sec); } } - } else { - /* Interrupted by a signal. */ - if (got_sigchld) { - got_sigchld = 0; - sigchld_reaper(); - } } /* Adjust tv and continue where we left off. */ -- 2.20.1