Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Apr 2018 01:14:01 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r332747 - stable/11/usr.sbin/cron/cron
Message-ID:  <201804190114.w3J1E18c032511@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Thu Apr 19 01:14:01 2018
New Revision: 332747
URL: https://svnweb.freebsd.org/changeset/base/332747

Log:
  MFC r332429, r332431
  
  r332429:
  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.
  
  r332431:
  cron(8): Correct test sense
  
  We're about to use the result of fstat(2) either way, so don't do that if it
  fails...

Modified:
  stable/11/usr.sbin/cron/cron/database.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/cron/cron/database.c
==============================================================================
--- stable/11/usr.sbin/cron/cron/database.c	Thu Apr 19 01:10:53 2018	(r332746)
+++ stable/11/usr.sbin/cron/cron/database.c	Thu Apr 19 01:14:01 2018	(r332747)
@@ -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;
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804190114.w3J1E18c032511>