CHECK/TODO

	crontab printlog uses stderr, fatal and reopenlogfile write to fd 2
	errorlogging: perror?, exit?
	sizeof()
	tainted annotations: splint ch. 10
	cw_Flag -> cw_Status
	mail waiting without signals?
	website: debugging instructions

	HEAD~73 Cleaned up error reporting
	63 refined ints
	57,56,55,52,50 factor string routines
	49 crontab:path and visual...

	HEAD~44 are all the (void)s ok?
	check all asserts
	check all @-options
	check that cl_Timestamp != NULL when cl_Delay>0

	check str_tok*,str_sep,str*spn

	HEAD~11 check ZeroConfLine (// comments)


Rogutės Sparnuotos??
It's true we don't clean that subdirectory up on exit. crond is always
exited by sending it a TERM or KILL signal. I could install a signal
handler to try to remove this directory in this case. But then that will
have to be tested carefully. In present usage, all that's left in /tmp
when crond is killed are some extra directories, and they'll be deleted
by the system on next reboot anyway. I'm expecting crond will normally
only be started/stopped once or at most a few times during each
reboot-session-lifetime of the machine. So it's harmless for a few empty
directories to be left in /tmp until reboot.



Packaging: use /etc/conf.d/dcron, make sure cmdline options are all overridable

> 1. Some users have been needing to put the "-m username@host" or "-M
> sendmail_substitute" options on their crond invocation line. I told them
> just edit the /etc/rc.d/crond file and tell pacman not to overwrite it.
> But then someone pointed out this could be done more politely with an
> /etc/conf.d/crond file. What do you think? You could distribute such a
> file containing only comments, then source it from the /etc/rc.d/crond
> script and add a variable to the end of the crond invocation line.
vvvvvvvvvvvvvvvvvvv
> I just need to make sure that any options at the end of the invocation
> line can overwrite options set earlier in the line, so that users can
> supply the whole range of options in the /etc/conf.d file. I don't want
> any voodoo about which options can be supplied there and which can't.
^^^^^^^^^^^^^^^^^^^^



LOGROTATE
=========
FS#18039 - log rotation - I'm planning to do the simultaneous
syslog-ng and dcron package update, and move the logrotate
responsibility into syslog-ng



   I see that in your syslog-ng, you don't have the line 'kill -HUP `cat
   /var/run/crond.pid`'. I'm guessing that line isn't necessary.

Yeah, actually sending the HUP signal to crond only helps when you have
crond using the -L logfile option. Arch uses the -S syslogging option.
We should really be sending HUP to syslog-ng. I'll talk to the Arch
packager about it.


> I can see both sides of this, but in essence, it seems like it's
> syslog-ng which ultimately decides the filename-- if syslog-ng.conf
> is changed to log cron output to another file, it's syslog-ng that
> decides where they go. So I think I agree with Eric that syslog-ng
> should be responsible for the rotating the files it determines
> should exist in its default configuration.
>
> I'll wait a while to hear from others before doing anything directly
> to address this.

Yes, the logrotate script was needed when dcron didn't use syslog. And
I'll leave it in the release tarballs "extra" folder as an example for
users who continue to use dcron that way. But on my own system I have
syslog logging the cron output to "cron.log" not "crond.log":

from /etc/syslog-ng.conf:

    destination d_cron { file("/var/log/cron.log"); };
    filter f_cron { facility(cron) or program("rsnapshot"); };
    log { source(src); filter(f_cron); destination(d_cron); };

And I have /var/log/cron.log handled by my /etc/logrotate.d/syslog-ng
script:

/var/log/[..lots of logs, including cron.log..] {
    missingok
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslog-ng.pid 2>/dev/null`  2>
/dev/null || true
    endscript
}

I can appreciate arguments both ways myself, but for my own use found it
easiest to just ignore the dcron-supplied logrotate script and edit it
into my syslog-ng logrotate script.



> 3. We've got to think about the logrotate script. A few people pointed out
> to me that we now have it reading /var/run/cron.pid, but there is no
> such file. (It's also on Flyspray #18039.) OK, that's clearly a slip,
> but there's a larger issue here. Sending the HUP signal to crond only
> does anything when crond is using the "-L logfile" option, not when it's
> using the "-S" syslogging option. Since we're doing the latter, we
> should really be sending a HUP to syslog-ng instead. Here are the
> options I see:

I think we can start from the presumption of a reasonable default
behavior-- logging to syslog-- and require users to customize their
logrotate scripts if they plan to do something different.

>
>      i. change the Arch logrotate script to send HUP to syslog-ng. This
> may involve syslog-ng being HUPd twice in short succession, since the
> syslog-ng logrotate script does the same. Perhaps that's harmless.

i. I agree that HUPping syslog-ng twice seems odd put is probably
harmless in practice.

>
>      ii. don't HUP syslog-ng in the cron logrotate script, rely on the
> syslog-ng logrotate script to do it. Problem is, I don't think we can
> rely on these scripts always both running. Situations could arise where
> logrotate decides crond's logs are ready to rotate and syslog-ng's
> aren't. (Perhaps that wouldn't happen if a user only used the default
> settings for logrotate and never ran logrotate from command line but
> only from the cronjob. Perhaps. But I don't think things should break
> just because some of the conditions are unmet.)

ii. I think the coordination issues here are messy and should be avoided.

>
>      iii. integrate crond's logrotating with syslog's. Probably a good
> idea, but a longer-term project, right?

iii. This sounds like the right approach on balance. We simply add the
cron log file into the syslog-ng logrotate script, and it works. I can
commit such a change and deploy it.

Am I overlooking anything? The syslog-ng logrotate script already
integrates the HUP, so that should work cleanly. If someone wants to
use the -L option to dcron, they need to rewrite both the syslog-ng
and add a dcron logrotate script.


==============================



todo
  * add timestamps to -d output

  * manual cron.update prodding doesn't affect cl_NotUntil

  * Use hash when ID=... is supplied. FS#18292.

  * FS#18352: Another thing: when moving the original file to the backup name, and the edited version is written in it's place, the file is written without preserving the same permissions as the original, so if you have a umask that prevents others from reading your stuff, crontab won't be able to load the new file.

git
  * Numeric loglevels specified by 'crond -l <level>' weren't being validated.
    Now we no longer accept numeric loglevels; they must be specified
    symbolically. Thanks to Rogutės Sparnuotos.

  * Continued portability improvements. Makefile now uses -lbsd-compat.
    Factored allocation and string calls to utils.c.

  * Many internal changes and annotations to pass splint review.

  * Documentation and error message updates.

v4.5  30-Apr-2011
  * Some cron jobs were running multiple times. Now we make sure not to
    ArmJobs that are already running; and not to resynchronize while jobs are
    running; and to poll the DST setting. (Fixes Arch FS#18681; thanks to Paul
    Gideon Dann for identifying the second issue; and Tilman Sauerbeck for
    identifying the third.)

  * @monthly was wrongly being parsed the same as @yearly (fixes Arch
    FS#19123). Thanks to Peter Johnson, Paul Gideon Dann, and Tilman Sauerbeck.

  * extra/crond.rc: now uses $CROND_ARGS from /etc/conf.d/crond; sample included
    as extra/crond.conf. Suggested by Eric Bélanger.

  * Running `/etc/rc.d/crond start` after startup could leak unwanted
    environment into cronjobs; now we force crond to start in empty env
    (fixes Arch FS#22085). Thanks to Mantas.

  * Also set LOGNAME environment variable in cronjobs. Requested by Michael
    Trunner; fixes Arch FS#18338.

  * extra/crond.logrotate now correctly gets pid from /var/run/crond.pid
    (fixes Arch FS#18039). Thanks to Kay Abendroth, revel, and Chlump Chatkupt.

  * extra/prune-cronstamps now only deletes files, and is formatted as a
    @weekly crontab. Thanks to Alec Moskvin <alecm@gmx.com>.

  * extra/crontab.vim works around an issue where vim's writebackup would
    interfere with crontab's security model (addresses Arch FS#18352).
    Thanks to Armadillo and Simon Williams.

  * Makefile uses $LDFLAGS (fixes Arch FS#23784). Thanks to Kristoffer Tidemann
    and Mike Frysinger.

  * defs.h sets default locations for CRONTABS and CRONSTAMPS beneath /var/spool/cron/,
    as in earlier versions of dcron.

  * Documentation updates.

  * Thanks for testing and feedback: Feifei Jia, Spider.007, Ray Kohler,
    Igor Zakharoff, Edward Hades, and Joe Lightning.

v4.4  17-Jan-2010
  * Finished mailjobs were being left as zombie processes. Fixed.

  * When using crond with logging-to-file, user jobs could only log some
    events if they had write access to the log. Fixed this by having crond
    keep a file descriptor open to the log; also added a SIGHUP handler
    to make crond re-open the logfile. The sample logrotate script now
    sends that signal.

  * More sensible command-line parsing by crontab.

  * Add prune-cronstamps to extra; document extra/*; general improvement
    of README and manpages.

  * Portability improvements, and defs.h now has fuller comments about
    requirements.

  * Makefile improvements: `make` now caches variables for `make install`;
    don't stomp CFLAGS environment variable, and added BINDIR,SBINDIR,MANDIR.

  * Thanks to Juergen Daubert for more testing and suggestions.

v4.3  11-Jan-2010
  * Internal refactoring to make buffer overflow checks
    clearer and portability issues more explicit.

  * Made file argument to -L mandatory; optional args to
    getopt needs GNU extensions.

  * Makefile tweaks. Added CRONTAB_GROUP for `make install`.
    Renamed TIMESTAMPS -> CRONSTAMPS.

  * Thanks to Juergen Daubert for testing and suggestions.

v4.2  11-Jan-2010
  * Makefile tweaks; moved more constants to #defines.

v4.1  10-Jan-2010
  * Fixed bug in parsing some numeric fields in crontabs. (Terminus of range
    wasn't being modded.)

  * Updated Makefile to make it easier to customize timestamps at configure
    time. Also, if LC_TIME is defined when crond runs, we use that instead of
    compiled-in default (for logging to files, to customize syslog output use
    syslog-ng's 'template' command).

  * Fixed Makefile permissions on crond and crontab binaries.

v4.0  6-Jan-2010
  * Jim Pryor took over development; folded in changes from his fork "yacron"

  * Applied "Daniel's patch" from dcron 3.x tarballs to enable logging to syslog or
    files. Added further logging improvements.

  * Added -m user@host and -M mailer options

  * Various crontab syntax extensions, including "2nd Monday of every month",
    @reboot, @daily, and finer-grained frequency specifiers.

  * Jobs can wait until AFTER other jobs have finished.

  * Enhanced parsing of cron.update file, to make it possible for scripts to
    interact with a running crond in limited ways.

  * Various internal changes

  * Updated Makefile, manpage buildchain, and docs

v3.2
    Fixed a minor bug, remove the newline terminating a line only if there
    is a newline to remove.

v3.1
    Add support for root-run crontab files in /etc/cron.d and rewrite a
    good chunk of the crontab file management code.  By VMiklos and Matt
    Dillon.

v3.0
    Fix /tmp race and misc cleanups from Emiel Kollof <emiel@gamepoint.net>

v2.9
    Modernize the code, remove strcpy() and sprintf() in favor of snprintf().
    (Supplied by Christine Jamison <technobabe@mail.nwmagic.net>)

v2.8
    Fixed bug found by Christian HOFFMANN.  newline removal was broken
    for lines that began with whitespace, causing crontab lines to be
    chopped off.

v2.7
    Committed changes suggested by
    Ragnar Hojland Espinosa <ragnar@redestb.es>

    Fixed a few printfs, removed strdup() function ( strdup() is now standard
    in all major clib's )

v2.4-2.6
    ( changes lost )

v2.3
    dillon: Fixed bug in job.c -- if ChangeUser() fails, would return from child fork rather
        then exit!  Oops.

v2.2
    dillon: Initial release

