History log of /freebsd-current/usr.sbin/cron/cron/cron.c
Revision Date Author Comments
# fe590ffe 01-Jun-2023 Eric van Gyzen <vangyzen@FreeBSD.org>

Import vixie cron 4.0

Specifically, import the diff from commit e745bd4c10ab to
commit 83563783cc2 in https://github.com/vixie/cron.git

My sole motivation is changing to the common MIT license.
The old license, especially the "buildable source" clause,
is unfriendly for commercial users of this code. Simply
changing the license without importing [most of] the code
accompanying that license seemed legally dubious.

The most regrettable change is losing Paul's uucp path.
I partially atone for this loss by restoring the upstream
$Id$ tags, since $FreeBSD$ is no longer useful.

This is [intended to be] a complete list of the functional
changes in this commit. Some changes were made so that we
could consider vixie cron to be our upstream and reduce our
diffs against it, while others were simply a good idea.

- main() - use putenv instead of setenv for PATH
- open_pidfile no longer needs snprintf to build pidfile
- crontab main() - abort() on impossible errors
- check for truncation when building strings with snprintf
- getdtablesize() -> sysconf(_SC_OPEN_MAX)

These changes were not taken from upstream's 4.0 diff because
they [could] actually change behavior. Some of them might be
beneficial, but should be taken separately.

- config.h - sendmail args: remove -oi and add -or0s
- call setlocale(LC_ALL, "") at the top of main()
- acquire_daemonlock - we already use pidfile
- cast getpid(), uid_t, and gid_t to long for printf
- remove unnecessary braces - I consider them beneficial
- BSDi support
- glue_strings() - use snprintf(), as we often already did

MFC after: on demand
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D40260


# e93f27e3 18-Apr-2023 John Baldwin <jhb@FreeBSD.org>

cron: Use C89 function definitions.

Reviewed by: zlei
Differential Revision: https://reviews.freebsd.org/D39529


# a08d12d3 07-Jun-2018 Gleb Smirnoff <glebius@FreeBSD.org>

Add new functionality and syntax to cron(1) to allow to run jobs at a
given interval, which is counted in seconds since exit of the previous
invocation of the job. Example user crontab entry:

@25 sleep 10

The example will launch 'sleep 10' every 35 seconds. This is a rather
useless example above, but clearly explains the functionality.

The practical goal here is to avoid overlap of previous job invocation
to a new one, or to avoid too short interval(s) for jobs that last long
and doesn't have any point of immediate launch soon after previous run.

Another useful effect of interval jobs can be noticed when a cluster of
machines periodically communicates with a single node. Running the task
time based creates too much load on the node. Running interval based
spreads invocations across machines in cluster. Note that -j/-J won't
help in this case.

Sponsored by: Netflix


# 4555b2ad 19-Jul-2017 Enji Cooper <ngie@FreeBSD.org>

Fix trivial whitespace bug introduced in usage message changes for -n
support (r304570).

MFC after: now


# 370b58b9 21-Aug-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add the "-n" flag to cron(8), to prevent it from daemonizing.
This makes it possible to use it with external supervisors.
The "-n" flag name is compatible with Linux, NetBSD, and OpenBSD.

Reviewed by: jilles, pfg, wblock
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D7581


# b5635ba0 01-May-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

usr.sbin: minor spelling fixes on comments.

No functional change.


# bc36ff9b 24-Jan-2014 Andrey A. Chernov <ache@FreeBSD.org>

Bad timespec_subtract() calculations produce negative tv_nsec on i386
which cause EINVAL returned from nanosleep() which cause loop in
cron_sleep() and making all cron jobs to start about 30 seconds earlier
(which cause f.e. logfiles rotation by newsyslog delayed by 1 hour).

Use simple and proved calculations from kernel's timespecsub() instead.

MFC after: 3 days


# 7a5c30c5 25-Oct-2012 Maxim Sobolev <sobomax@FreeBSD.org>

Second attempt to add @every_second keyword support. Due to multiple
requests, default to the previous 60-seconds scheduling method
unless there is any @every_second entries to conserve CPU cycles and
power.

This change also improves scheduling in the default mode by running
as close to the beginning of the minnute as possible by replacing
sleep(3) with nanosleep(2). Previously, the tasks would run anywhere
within the first second of the minute and that offset drifted back
and forth each time cron(8) was engaged.

MFC after: 1 month


# 27858d0b 18-Oct-2012 Maxim Sobolev <sobomax@FreeBSD.org>

Fully backout latest changes.

Pointy hat to: sobomax


# 07e9aac0 17-Oct-2012 Maxim Sobolev <sobomax@FreeBSD.org>

Revert latest changes to cron, until better version is worked out (I hope).

Requested by: few


# 7bd02886 16-Oct-2012 Maxim Sobolev <sobomax@FreeBSD.org>

o Use nanosleep(2) to sleep exact amount of time till the next second,
not multiple of 1 second, which results in actual time to drift back
and forth every run within 1 second of the actual action has
been set for.

Suggested by: Ian Lepore

o Schedule the first run in 1 second after starting up, not on the
boundary of the next minute, which results in the every_second jobs
not being run.


# 2543786a 15-Oct-2012 Maxim Sobolev <sobomax@FreeBSD.org>

Add per-second scheduling into the cron(8). Right now it's
only available via the new @every_second shortcut. ENOTIME to
implement crontab(5) format extensions to allow more flexible
scheduling.

In order to address some concerns expressed by Terry Lambert
while discussing the topic few years ago, about per-second cron
possibly causing some bad effects on /etc/crontab by stat()ing
it every second instead of every minute now (i.e. atime update),
only check that database needs to be reloaded on every 60-th
loop run. This should be close enough to the current behaviour.

Add "@every_minute" shortcut while I am here.

MFC after: 1 month


# 9281629f 02-Oct-2012 Sergey Kandaurov <pluknet@FreeBSD.org>

Fix build with DEBUGGING disabled.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# acd3c015 19-Dec-2009 Attilio Rao <attilio@FreeBSD.org>

MFC r199804:
Avoid sshd, crond, inetd and syslogd to be killed in an high-pressure
swapping environment.

Sponsored by: Sandvine Incorporated


# 7a7043c7 25-Nov-2009 Attilio Rao <attilio@FreeBSD.org>

Avoid sshd, cron, syslogd and inetd to be killed under high-pressure swap
environments.
Please note that this can't be done while such processes run in jails.

Note: in future it would be interesting to find a way to do that
selectively for any desired proccess (choosen by user himself), probabilly
via a ptrace interface or whatever.

Obtained from: Sandvine Incorporated
Reviewed by: emaste, arch@
Sponsored by: Sandvine Incorporated
MFC: 1 month


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# b75634d2 29-Jun-2008 Dmitry Morozovsky <marck@FreeBSD.org>

Add -m option to cron(8), overriding default mail recipient for cron mails,
unless explicitly provided by MAILTO= line in crontab. This feature can be
useful in massive hosting environment, where most users do not care about
autogenerated mails.

Setting recipient to null string disables default mails at all.

Approved by: yar
MFC after: 4 weeks


# 784bddbc 07-Nov-2007 Kevin Lo <kevlo@FreeBSD.org>

Cleanup of userland __P use


# 531c70a6 20-Jul-2006 Stefan Farfeleder <stefanf@FreeBSD.org>

Don't use "implicit int". Move the opening { of the functions to the next
line while there.


# 8b28aef2 16-Sep-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Pidfiles should be created with permission preventing users from opening
them for reading. When user can open file for reading, he can also
flock(2) it, which can lead to confusions.

Pointed out by: green


# 78735592 24-Aug-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Use pidfile(3) in cron(8).

Note, that when cron(8) cannot create pidfile, it'll exit. I didn't
changed this behaviour, but its better to ignore errors other than
EEXIST, so daemon can be started on systems where /var/ file system
doesn't support locking (like NFS without rpc.lockd(8)).


# f5896baf 16-May-2004 Yaroslav Tykhiy <ytykhiy@gmail.com>

Add two new options to cron(8), -J and -j. They allow to specify
the maximum amount of time jitter for root and other users, respectively.
Before starting a job, cron(8) will sleep a random number of seconds,
from 0 to the amount specified. This can help to smooth down load spikes
when a lot of jobs are to start at the beginning of a particular minute
(e.g., the first minute of an hour.)

PR: bin/66474
Submitted by: Dmitry Morozovsky <marck <@> rinet.ru>


# 404363cc 08-Mar-2001 Sergey Babkin <babkin@FreeBSD.org>

The new version of the daylight time saving support. This time it works
for any change of the time zone offset from GMT. To enable use the
option -s.


# 1db78faf 07-Mar-2001 Peter Wemm <peter@FreeBSD.org>

Properly detach at startup. We could be passing revoked fd's to
child processes or starting children with no fd 0 (stdin) at all etc.
This is currently breaking on hub.freebsd.org.


# 6548bd56 22-Jan-2001 Sergey Babkin <babkin@FreeBSD.org>

Backed out the DST support changes.


# be821963 21-Jan-2001 Sergey Babkin <babkin@FreeBSD.org>

Made the special handling of the daylight time switches optional,
enabled by the option "-s" (for dSt). This returned the default behavior
to its original form.

The new option name is not "-d" because that would cause associations with
"debug" and cron already has "-x" for debugging, so this would cause
confusion.


# 08b2398e 20-Jan-2001 Sergey Babkin <babkin@FreeBSD.org>

Added sensible handling of switch to and from daylight saving time
for the jobs that fall into the disappearing or duplicated time
interval.

PR: bin/24494


# 97d92980 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 4ef875d7 12-Dec-1998 Matthew Dillon <dillon@FreeBSD.org>

PR: bin/5572

Prevent cron from going crazy if the time steps. For example, if you
have a system with hundreds of users and lots of different crontabs
and your time steps back an hour, the old cron would then attempt to
run an hours worth of cron jobs in a few seconds.


# 78cda230 06-Jul-1998 Bruce Evans <bde@FreeBSD.org>

Fixed printf format errors.


# 401e6468 15-Sep-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3). Rewrote man page in mdoc format.


# 6c3f552a 30-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 476602a9 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 3eacc3d7 30-Jun-1996 Wolfram Schneider <wosch@FreeBSD.org>

fix: debug flag 'test' cause endless loop
document debug flags

close PR bin/683


# 84f33dea 27-Aug-1994 Jordan K. Hubbard <jkh@FreeBSD.org>

Paul Vixie's cron, version 3.0. Munged into bmake format. If this goes
well, expect our two seperate directories for cron and crontab to go away
shortly.
Submitted by: jkh