Page MenuHomeFreeBSD

cron(8): schedule interval jobs that get loaded during execution
ClosedPublic

Authored by kevans on Apr 16 2019, 2:57 PM.

Details

Summary

Jobs using the @<second> syntax currently only get executed if they exist when cron is started. The simplest reproducer of this is:

echo '@20 root echo "Hello!"' >> /etc/cron.d/myjob

myjob will get loaded at the next second==0, but this echo job will ever run. These jobs are normally handled in run_reboot_jobs(), which sets e->lastexit of INTERVAL jobs to the startup time so they run 'n' seconds later.

Fix this by special-casing TargetTime > 0 in the database load. Preexisting jobs will be handled at startup during run_reboot_jobs as normal, but if we've reloaded a database during runtime we'll hit this case and set e->lastexit to the current time when we process it. They will then run every 'n' seconds from that point, and a full restart of cron is no longer required to make these jobs work.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

kevans created this revision.Apr 16 2019, 2:57 PM

Revision has been tested and working properly.

This revision is now accepted and ready to land.Apr 16 2019, 3:32 PM
bapt accepted this revision.Apr 19 2019, 11:23 AM
bjk added a subscriber: bjk.Apr 19 2019, 6:13 PM
bjk added inline comments.
usr.sbin/cron/crontab/crontab.5
254 ↗(On Diff #56251)

This is an error in the preexisting text, not your change, but while you're here, please s/scheduled specified amount/scheduled the specified number/

allanjude added inline comments.
usr.sbin/cron/crontab/crontab.5
248 ↗(On Diff #56251)

"that many seconds after completion of the previous invocation of" is much more grammatically pleasing

253 ↗(On Diff #56251)

It might be good to be more explicit here.

Might it overlap every time you reload cron, or is the only risk of overlap when you modify the file containing the @ entry?

254 ↗(On Diff #56251)

"The first run is scheduled for the specified number of seconds after cron is started or the crontab entry is reloaded"

Does that sound better?

kevans updated this revision to Diff 56399.Apr 19 2019, 6:49 PM
kevans marked 3 inline comments as done.

Take a shot at re-wording various bits based on feedback from @bjk and @allanjude

This revision now requires review to proceed.Apr 19 2019, 6:49 PM
kevans added inline comments.Apr 19 2019, 6:49 PM
usr.sbin/cron/crontab/crontab.5
253 ↗(On Diff #56251)

How's this?

254 ↗(On Diff #56251)

I think that flows pretty well.

allanjude accepted this revision.Apr 19 2019, 8:53 PM
This revision is now accepted and ready to land.Apr 19 2019, 8:53 PM
This revision was automatically updated to reflect the committed changes.