cron(8) mis-feature with @reboot long after system startup

Tim Kientzle tim at kientzle.com
Sat Nov 26 20:51:43 UTC 2011


>>> Add an option to cron to check lastlog and if within 5 or 10 minutes
>>> of the last reboot, then call run_reboot_jobs().
>> 
>> Depending on timestamps might be okay as a temporary quick-and-dirty
>> workaround, but there is likely to be a case where it will also do the
>> wrong thing. ??What if you need to restart cron within the 5-10 minutes?
>> 
>> Maybe something like: rc script sets a flag, cron_reboot script checks
>> and resets flag. ??The flag could be a file ("> /tmp/rebooting_system").
>> Better yet, a run-the-reboot-script command line option could be added
>> to cron.
> 
> cron(8) already creates a pid file. Maybe it wouldn't be so bad to just check the timestamp of that before creating its new pid file along with comparing to system boottime so we could make an accurate measure whether it should or should not run the @reboot extension at least down to 1 minute.

Timing-based approaches like this tend to be
brittle and fail in strange ways.

Remember that "boot time" basically means "run by /etc/rc".
Is there any way for /etc/rc.d/cron to notice that it's being
run by /etc/rc and pass an extra flag to cron in that case?
(If not, then perhaps /etc/rc should set some kind of marker
when it starts --- such as an environment variable or a 
file on disk --- that scripts such as /etc/rc.d/cron can use
to distinguish boot-time startup from manual startup.)

Tim




More information about the freebsd-hackers mailing list