From owner-svn-src-head@freebsd.org Thu Apr 12 13:52:56 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 40C6CF972E2; Thu, 12 Apr 2018 13:52:56 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E903F6C7CB; Thu, 12 Apr 2018 13:52:55 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E3C8F439A; Thu, 12 Apr 2018 13:52:55 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3CDqtPi034494; Thu, 12 Apr 2018 13:52:55 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3CDqtMS034493; Thu, 12 Apr 2018 13:52:55 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201804121352.w3CDqtMS034493@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 12 Apr 2018 13:52:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332429 - head/usr.sbin/cron/cron X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/usr.sbin/cron/cron X-SVN-Commit-Revision: 332429 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Apr 2018 13:52:56 -0000 Author: kevans Date: Thu Apr 12 13:52:55 2018 New Revision: 332429 URL: https://svnweb.freebsd.org/changeset/base/332429 Log: cron(8): Reload database if an existing job in cron.d changed as well Directory mtime will only change if a file is added or removed, not modified. For /var/cron/tabs, this is fine because of how crontab(1) manages it using temp files so all crontab(1) changes will trigger a reload of the database. For /etc/cron.d and /usr/local/etc/cron.d, this is not necessarily the case. Instead of checking their mtime, we should descend into them and check mtime on all jobs also. Reported by: des Reviewed by: bapt MFC after: 1 week Modified: head/usr.sbin/cron/cron/database.c Modified: head/usr.sbin/cron/cron/database.c ============================================================================== --- head/usr.sbin/cron/cron/database.c Thu Apr 12 13:40:02 2018 (r332428) +++ head/usr.sbin/cron/cron/database.c Thu Apr 12 13:52:55 2018 (r332429) @@ -56,7 +56,7 @@ load_database(old_db) { SYSCRONTABS }, { LOCALSYSCRONTABS } }; - int i; + int i, ret; Debug(DLOAD, ("[%d] load_database()\n", getpid())) @@ -79,6 +79,18 @@ load_database(old_db) for (i = 0; i < nitems(syscrontabs); i++) { if (stat(syscrontabs[i].name, &syscrontabs[i].st) != -1) { maxmtime = TMAX(syscrontabs[i].st.st_mtime, maxmtime); + /* Traverse into directory */ + if (!(dir = opendir(syscrontabs[i].name))) + continue; + while (NULL != (dp = readdir(dir))) { + if (dp->d_name[0] == '.') + continue; + ret = fstatat(dirfd(dir), dp->d_name, &st, 0); + if (ret == 0 && !S_ISREG(st.st_mode)) + continue; + maxmtime = TMAX(st.st_mtime, maxmtime); + } + closedir(dir); } else { syscrontabs[i].st.st_mtime = 0; }