Bug 224537 - cron uses directory mtime to notice changes - not sufficient - file changes don't change dir mtime
Summary: cron uses directory mtime to notice changes - not sufficient - file changes d...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.1-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-23 08:37 UTC by jsellens
Modified: 2017-12-23 08:37 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jsellens 2017-12-23 08:37:26 UTC
/usr/sbin/cron allows multiple files in /etc/cron.d and /usr/local/etc/cron.d and uses the mtime of the directory as an indicator of when to reload the cron files.

In cron/database.c in load_database() at around line 100, the comment is:

        /* if spooldir's mtime has not changed, we don't need to fiddle with
         * the database.

and the statbuf.st_mtime is compared to the previous version.

If a file in a directory changes, the mtime on the directory does not change, so changes to files in cron.d directories are often not noticed.

Repeat by putting a cron file in /etc/cron.d, then using echo or cat to add an additional entry and notice that the additional entry does not run.  Similarly, use vi to edit the file, the directory's mtime does not change, and cron file changes are not loaded.

The cron(8) man page says: "Thus cron need not be restarted whenever a crontab file is modified." which is incorrect.  It mentions that crontab(1) will update the directory time, but crontab(1) can't be used with /etc/cron.d or /usr/local/etc/cron.d files.

Perhaps the code could compute and compare a checksum on the directory, or a checksum on the results of opendir() / readdir() , rather than looking only at the directory mtime?

(I ran into this when puppet was updating files in /etc/cron.d and the commands being run were not changing.)

Thanks!