svn commit: r332429 - head/usr.sbin/cron/cron
Kyle Evans
kevans at FreeBSD.org
Thu Apr 12 13:52:56 UTC 2018
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;
}
More information about the svn-src-all
mailing list