Debian Codegraph @

bcron.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <title>bcron documentation</title>
6
7 <meta name="description" content="bcron documentation">
8 <meta name="keywords" content="bcron documentation">
9 <meta name="resource-type" content="document">
10 <meta name="distribution" content="global">
11 <meta name="Generator" content="makeinfo">
12 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
13 <link href="#Top" rel="start" title="Top">
14 <link href="#SEC_Contents" rel="contents" title="Table of Contents">
15 <link href="dir.html#Top" rel="up" title="(dir)">
16 <style type="text/css">
17 <!--
18 a.summary-letter {text-decoration: none}
19 blockquote.smallquotation {font-size: smaller}
20 div.display {margin-left: 3.2em}
21 div.example {margin-left: 3.2em}
22 div.indentedblock {margin-left: 3.2em}
23 div.lisp {margin-left: 3.2em}
24 div.smalldisplay {margin-left: 3.2em}
25 div.smallexample {margin-left: 3.2em}
26 div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
27 div.smalllisp {margin-left: 3.2em}
28 kbd {font-style:oblique}
29 pre.display {font-family: inherit}
30 pre.format {font-family: inherit}
31 pre.menu-comment {font-family: serif}
32 pre.menu-preformatted {font-family: serif}
33 pre.smalldisplay {font-family: inherit; font-size: smaller}
34 pre.smallexample {font-size: smaller}
35 pre.smallformat {font-family: inherit; font-size: smaller}
36 pre.smalllisp {font-size: smaller}
37 span.nocodebreak {white-space:nowrap}
38 span.nolinebreak {white-space:nowrap}
39 span.roman {font-family:serif; font-weight:normal}
40 span.sansserif {font-family:sans-serif; font-weight:normal}
41 ul.no-bullet {list-style: none}
42 -->
43 </style>
44
45
46 </head>
47
48 <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
49 <h1 class="settitle" align="center">bcron documentation</h1>
50
51
52
53
54 <a name="Top"></a>
55 <div class="header">
56 <p>
57 Next: <a href="#Introduction" accesskey="n" rel="next">Introduction</a>, Previous: <a href="dir.html#Top" accesskey="p" rel="prev">(dir)</a>, Up: <a href="dir.html#Top" accesskey="u" rel="up">(dir)</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
58 </div>
59 <h1 class="node-heading">Top</h1>
60
61 <table class="menu" border="0" cellspacing="0">
62 <tr><td align="left" valign="top">&bull; <a href="#Introduction" accesskey="1">Introduction</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
63 </td></tr>
64 <tr><td align="left" valign="top">&bull; <a href="#Design-Notes" accesskey="2">Design Notes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
65 </td></tr>
66 <tr><td align="left" valign="top">&bull; <a href="#Configuration" accesskey="3">Configuration</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
67 </td></tr>
68 <tr><td align="left" valign="top">&bull; <a href="#Implementation-Notes" accesskey="4">Implementation Notes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
69 </td></tr>
70 </table>
71
72 <hr>
73 <a name="Introduction"></a>
74 <div class="header">
75 <p>
76 Next: <a href="#Design-Notes" accesskey="n" rel="next">Design Notes</a>, Previous: <a href="#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
77 </div>
78 <a name="Introduction-1"></a>
79 <h2 class="chapter">1 Introduction</h2>
80
81 <p>Name comes from: Bruce&rsquo;s / Better / Busy cron.
82 </p>
83 <table class="menu" border="0" cellspacing="0">
84 <tr><td align="left" valign="top">&bull; <a href="#Problems" accesskey="1">Problems</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
85 </td></tr>
86 <tr><td align="left" valign="top">&bull; <a href="#Requirements" accesskey="2">Requirements</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
87 </td></tr>
88 <tr><td align="left" valign="top">&bull; <a href="#Design-Choices" accesskey="3">Design Choices</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
89 </td></tr>
90 <tr><td align="left" valign="top">&bull; <a href="#vixie_002dcron-Patches" accesskey="4">vixie-cron Patches</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
91 </td></tr>
92 </table>
93
94 <hr>
95 <a name="Problems"></a>
96 <div class="header">
97 <p>
98 Next: <a href="#Requirements" accesskey="n" rel="next">Requirements</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
99 </div>
100 <a name="Problems-With-Other-cron-Systems"></a>
101 <h3 class="section">1.1 Problems With Other cron Systems</h3>
102
103 <table class="menu" border="0" cellspacing="0">
104 <tr><td align="left" valign="top">&bull; <a href="#Problems-with-vixie_002dcron" accesskey="1">Problems with vixie-cron</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
105 </td></tr>
106 <tr><td align="left" valign="top">&bull; <a href="#Problems-with-fcron" accesskey="2">Problems with fcron</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
107 </td></tr>
108 <tr><td align="left" valign="top">&bull; <a href="#Problems-with-anacron" accesskey="3">Problems with anacron</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
109 </td></tr>
110 <tr><td align="left" valign="top">&bull; <a href="#Problems-with-dcron" accesskey="4">Problems with dcron</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
111 </td></tr>
112 </table>
113
114 <hr>
115 <a name="Problems-with-vixie_002dcron"></a>
116 <div class="header">
117 <p>
118 Next: <a href="#Problems-with-fcron" accesskey="n" rel="next">Problems with fcron</a>, Previous: <a href="#Problems" accesskey="p" rel="prev">Problems</a>, Up: <a href="#Problems" accesskey="u" rel="up">Problems</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
119 </div>
120 <a name="vixie_002dcron"></a>
121 <h4 class="subsection">1.1.1 vixie-cron</h4>
122
123 <ul>
124 <li> Too many bugs
125 The last official release of vixie-cron was in December of 1993.
126 Since then, many security holes and other bugs have been found,
127 requiring every vendor to distribute a multiply-patched version of
128 this system. Most vendors have a different set of patches, making
129 this a bit of a moving target.
130
131 </li><li> Can&rsquo;t handle DST changes
132 vixie-cron&rsquo;s mode of operations is to wake up every minute and
133 determine, with no history, what jobs to run. When DST changes, this
134 causes some jobs to be either skipped or run twice.
135
136 </li></ul>
137
138 <hr>
139 <a name="Problems-with-fcron"></a>
140 <div class="header">
141 <p>
142 Next: <a href="#Problems-with-anacron" accesskey="n" rel="next">Problems with anacron</a>, Previous: <a href="#Problems-with-vixie_002dcron" accesskey="p" rel="prev">Problems with vixie-cron</a>, Up: <a href="#Problems" accesskey="u" rel="up">Problems</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
143 </div>
144 <a name="fcron"></a>
145 <h4 class="subsection">1.1.2 fcron</h4>
146
147 <ul>
148 <li> Parsing issues
149 If a job starts with a word (terminated by any non-word character,
150 like <code>/</code>) that happens to also be a username, fcron interprets
151 this word as the userid to run the job under, even for non-root users.
152 This causes problems for jobs like <code>bin/something</code> when user
153 <code>bin</code> exists.
154
155 </li><li> No support for <samp>/etc/cron.d</samp>
156
157 </li><li> No support for <samp>/etc/crontab</samp>
158
159 </li><li> Gratuitious incompatibilities with vixie-cron
160 Jobs are run with the login shell for the user instead of
161 <samp>/bin/sh</samp>. The default mode of execution prevents the same job
162 from running multiple times (a good option, but bad default).
163 <code>MAILTO</code> can only contain a username, not a full email address.
164
165 </li></ul>
166
167 <hr>
168 <a name="Problems-with-anacron"></a>
169 <div class="header">
170 <p>
171 Next: <a href="#Problems-with-dcron" accesskey="n" rel="next">Problems with dcron</a>, Previous: <a href="#Problems-with-fcron" accesskey="p" rel="prev">Problems with fcron</a>, Up: <a href="#Problems" accesskey="u" rel="up">Problems</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
172 </div>
173 <a name="anacron"></a>
174 <h4 class="subsection">1.1.3 anacron</h4>
175
176 <p>Anacron is only really useful for running jobs once a day or less
177 frequently. From what I&rsquo;ve seen, it&rsquo;s good at what it does, just not
178 useful at much else.
179 </p>
180 <hr>
181 <a name="Problems-with-dcron"></a>
182 <div class="header">
183 <p>
184 Previous: <a href="#Problems-with-anacron" accesskey="p" rel="prev">Problems with anacron</a>, Up: <a href="#Problems" accesskey="u" rel="up">Problems</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
185 </div>
186 <a name="dcron"></a>
187 <h4 class="subsection">1.1.4 dcron</h4>
188
189 <ul>
190 <li> No support for <samp>/etc/cron.d</samp>
191
192 </li><li> No support for <samp>/etc/crontab</samp>
193
194 </li><li> No easy way of emulating support for system crontabs
195 dcron&rsquo;s crontab format does not include a &ldquo;username&rdquo; column, and as
196 such makes it nearly impossible to even emulate system crontabs.
197
198 </li><li> Unusual or broken handling of DST changes
199 From reading the source, dcron only handles cases where the linear
200 time jumps. When DST changes, linear time does not change, and so
201 dcron effectively does not handle this situation.
202
203 </li></ul>
204
205 <hr>
206 <a name="Requirements"></a>
207 <div class="header">
208 <p>
209 Next: <a href="#Design-Choices" accesskey="n" rel="next">Design Choices</a>, Previous: <a href="#Problems" accesskey="p" rel="prev">Problems</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
210 </div>
211 <a name="Requirements-1"></a>
212 <h3 class="section">1.2 Requirements</h3>
213
214 <ul>
215 <li> Security
216
217 <p>I am choosing to make a number of relatively unorthodox choices in
218 order to avoid many of the security issues that have plagued
219 vixie-cron and other related systems.
220 </p>
221 </li><li> External compatability with vixie-cron
222
223 <p>In particular, the system must support:
224 </p><ul>
225 <li> crontabs in the same file format as vixie-cron
226 </li><li> crontabs submitted via a command-line compatable <samp>crontab</samp>
227 program
228 </li><li> mail is sent to <code>$MAILTO</code> if the job produces any output
229 (and possibly if the job exits non-zero)
230 </li></ul>
231
232 </li><li> Support for system crontabs
233
234 <p>This means that the system MUST support:
235 </p><ul>
236 <li> System crontab entries in <samp>/etc/crontab</samp>
237 </li><li> System crontab entries in <samp>/etc/cron.d/*</samp>
238 </li></ul>
239 <p>System crontab entries are additionally differentiated from normal
240 ones by having a &ldquo;username&rdquo; column immediately preceding the
241 command.
242 </p>
243 </li><li> Intelligent handling of DST time changes
244
245 <p>One of the biggest frustrations I have had with dealing with
246 vixie-cron is its complete inability to deal with time jumps in an
247 intelligent manner. In particular, when DST changes happen, jobs will
248 either get skipped (when time jumps forward) or executed twice (when
249 time jumps backwards). This is unacceptable.
250 </p>
251 </li><li> Allow setting ulimits before executing commands
252
253 <p>In one of the target installations, we need to set up ulimits
254 (limiting CPU time and memory) before executing commands. It would be
255 easy enough to ulimit the entire daemon, but then the daemon itself
256 would be vulnerable to getting killed when it has run for long enough.
257 Our current setup is to run jobs through a global wrapper script,
258 which can set any necessary limits (or anything else) and then execute
259 the job.
260 </p>
261 </li></ul>
262
263 <hr>
264 <a name="Design-Choices"></a>
265 <div class="header">
266 <p>
267 Next: <a href="#vixie_002dcron-Patches" accesskey="n" rel="next">vixie-cron Patches</a>, Previous: <a href="#Requirements" accesskey="p" rel="prev">Requirements</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
268 </div>
269 <a name="Design-Choices-1"></a>
270 <h3 class="section">1.3 Design Choices</h3>
271
272 <dl compact="compact">
273 <dt>Use local socket to submit files.</dt>
274 <dd>
275 <p>There are two basic methods of submitting crontab files:
276 </p><ol>
277 <li> Use a setuid program to write directly into spool files.
278 </li><li> Set up a local socket to submit jobs to a daemon.
279 </li></ol>
280 <p><a name="DOCF1" href="#FOOT1"><sup>1</sup></a> Using a setuid submission
281 agent was discarded to prevent the possibility of all the bugs that
282 have plagued other setuid submission agents. The socket protocol is
283 deliberately very simple, to make the submission agent foolproof.
284 </p>
285 </dd>
286 <dt>Multiple process daemon.</dt>
287 <dd>
288 <p>By seperating job submission from job execution, exploiting the system
289 to run arbitrary jobs as privileged users is made even harder. It
290 also makes the design of those individual programs much simpler.
291 </p>
292 </dd>
293 </dl>
294
295 <hr>
296 <a name="vixie_002dcron-Patches"></a>
297 <div class="header">
298 <p>
299 Previous: <a href="#Design-Choices" accesskey="p" rel="prev">Design Choices</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
300 </div>
301 <a name="vixie_002dcron-Patches-1"></a>
302 <h3 class="section">1.4 vixie-cron Patches</h3>
303
304 <p>This section lists all the non-trivial patches found for vixie-cron,
305 what problem they appear to address, and (if appropriate) how bcron
306 will avoid the same problem. The patches listed come from multiple
307 sources, including the latest RPM (Fedora Core IIRC).
308 </p>
309 <dl compact="compact">
310 <dt>0days.patch</dt>
311 <dd>
312 <p>This patch modifies the <samp>crontab.5</samp> man page to remove allowing
313 &lsquo;<samp>0</samp>&rsquo; for day of month or month numbers.
314 </p>
315 </dd>
316 <dt>badsig.patch</dt>
317 <dd>
318 <p>On some systems, signal handlers are single-shot. This patch modifies
319 the SIGHUP handler to reactivate itself before it returns. bcron will
320 use the bglibs signal functions, which use sigaction to create
321 suitable handlers, where appropriate. bcron doesn&rsquo;t use signals for
322 any purpose.
323 </p>
324
325 </dd>
326 <dt>buffer.patch</dt>
327 <dd>
328 <p>This patch increases the maximum username length from 20 to 32, and
329 modifies calls to strcpy to use strncpy to ensure all string copies
330 are length bounded. bcron uses dynamically allocated strings to
331 eliminate the possibility of buffer overflows.
332 </p>
333 </dd>
334 <dt>close_stdin.diff</dt>
335 <dd>
336 <p>This patch modifies the cron daemon to close stdin, stdout, and stderr
337 on startup, and to reopen them as <samp>/dev/null</samp>. The bcron daemons
338 run under supervise, and have no need of such handling.
339 </p>
340 </dd>
341 <dt>crond.patch</dt>
342 <dd>
343 <p>Adds support for <samp>/etc/cron.d</samp>
344 </p>
345 </dd>
346 <dt>cront_stdin.patch</dt>
347 <dd>
348 <p>Appears to modify <samp>crontab</samp>&rsquo;s command-line handling such that no
349 argument is interpreted as to read the crontab from standard input.
350 </p>
351 </dd>
352 <dt>crontab.5.diff</dt>
353 <dd>
354 <p>Documents several builtin macros to replace the first 5 fields. This
355 macros consist of: &lsquo;<samp>@reboot</samp>&rsquo;, &lsquo;<samp>@yearly</samp>&rsquo;,
356 &lsquo;<samp>@annually</samp>&rsquo;, &lsquo;<samp>@monthly</samp>&rsquo;, &lsquo;<samp>@weekly</samp>&rsquo;, &lsquo;<samp>@daily</samp>&rsquo;,
357 &lsquo;<samp>@midnight</samp>&rsquo;, and &lsquo;<samp>@hourly</samp>&rsquo;. bcron will not, at least
358 initially, support these macros.
359 </p>
360 </dd>
361 <dt>crontab.patch</dt>
362 <dd>
363 <p>Modifies crontab to use strncpy and snprintf when writing into
364 length-bounded strings.
365 </p>
366 </dd>
367 <dt>crontabloc.patch</dt>
368 <dd>
369 <p>Patches the crontab man page to reference <samp>/etc/crontab</samp>.
370 </p>
371 </dd>
372 <dt>dst.patch</dt>
373 <dd>
374 <p>Patches the crontab man page to point out that DST may cause jobs to
375 be skipped or repeated.
376 </p>
377 </dd>
378 <dt>name.patch</dt>
379 <dd>
380 <p>Appears to modify how the cron daemon handles sending messages to
381 syslog. bcron will log messages to stderr, avoiding syslog entirely.
382 </p>
383 </dd>
384 <dt>nodot.patch</dt>
385 <dd>
386 <p>Adds &lsquo;<samp>-i</samp>&rsquo; to the list of arguments sent to sendmail (result is
387 &lsquo;<samp>-FCronDaemon -i -odi -oem</samp>&rsquo;). Only useful for sendmail, but
388 still needed.
389 </p>
390 </dd>
391 <dt>root_-u-85879.patch</dt>
392 <dd>
393 <p>Sanity checks the use of &lsquo;<samp>-u</samp>&rsquo; against UID and/or root.
394 </p>
395 </dd>
396 <dt>security2.patch</dt>
397 <dd>
398 <p>Does some sanity checking on mailto, and does a setuid before sending
399 mail. bcron plays safe with mailto by putting it into a message
400 header, and always drops root privileges before executing commands.
401 </p>
402 </dd>
403 <dt>sigchld.patch</dt>
404 <dd>
405 <p>Return the SIGCHLD handler to its default state before executing
406 commands.
407 </p>
408 </dd>
409 <dt>sprintf.patch</dt>
410 <dd>
411 <p>More sprintf -&gt; snprintf conversions.
412 </p>
413 </dd>
414 <dt>time.patch</dt>
415 <dd>
416 <p>Sync all the crontabs before sleeping to handle changes in the system
417 time.
418 </p>
419 </dd>
420 <dt>timeaftertime.patch</dt>
421 <dd>
422 <p>The previous patch created double execution issues with small
423 backwards adjustments in the clock time.
424 </p>
425 </dd>
426 </dl>
427
428 <hr>
429 <a name="Design-Notes"></a>
430 <div class="header">
431 <p>
432 Next: <a href="#Configuration" accesskey="n" rel="next">Configuration</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
433 </div>
434 <a name="Design-Notes-1"></a>
435 <h2 class="chapter">2 Design Notes</h2>
436
437 <table class="menu" border="0" cellspacing="0">
438 <tr><td align="left" valign="top">&bull; <a href="#Fundamental-Operations" accesskey="1">Fundamental Operations</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
439 </td></tr>
440 <tr><td align="left" valign="top">&bull; <a href="#Programs" accesskey="2">Programs</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
441 </td></tr>
442 <tr><td align="left" valign="top">&bull; <a href="#Files" accesskey="3">Files</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
443 </td></tr>
444 <tr><td align="left" valign="top">&bull; <a href="#Inter_002dProcess-Communication" accesskey="4">Inter-Process Communication</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
445 </td></tr>
446 </table>
447
448 <hr>
449 <a name="Fundamental-Operations"></a>
450 <div class="header">
451 <p>
452 Next: <a href="#Programs" accesskey="n" rel="next">Programs</a>, Previous: <a href="#Design-Notes" accesskey="p" rel="prev">Design Notes</a>, Up: <a href="#Design-Notes" accesskey="u" rel="up">Design Notes</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
453 </div>
454 <a name="Fundamental-Operations-1"></a>
455 <h3 class="section">2.1 Fundamental Operations</h3>
456
457 <p>The following is a list of all the &ldquo;core&rdquo; operations that must be
458 provided based on the requirements.
459 </p>
460 <dl compact="compact">
461 <dt>Execute jobs</dt>
462 <dd><p>Strictly speaking, this is the only role that requires superuser
463 privileges. Every other job should run as non-root.
464 </p>
465 </dd>
466 <dt>Schedule jobs</dt>
467 <dd><p>Scan all the known jobs, determine which one needs to be executed
468 next, and sleep until that time arrives.
469 </p>
470 </dd>
471 <dt>Accept new user crontabs</dt>
472 <dd><p>Listen for connections on a socket and accept job data.
473 </p>
474 </dd>
475 <dt>Parse crontabs into internal job format</dt>
476 <dd><p>Read the submitted files and parse their contents into a structured
477 format.
478 </p>
479 </dd>
480 <dt>Check for new system crontabs</dt>
481 <dd><p>Check <samp>/etc/crontab</samp> and <samp>/etc/cron.d/*</samp> every minute for
482 modifications. If any files are changed, added, or deleted, add the
483 listed jobs. On systems with tightened security, these files may only
484 be readable by &lsquo;<samp>root</samp>&rsquo;.
485 </p>
486 </dd>
487 <dt>Manage saved state</dt>
488 <dd><p>All jobs need to be saved to disk along with when they were last
489 executed, in order to determine when they should be next executed.
490 </p>
491 </dd>
492 </dl>
493
494 <hr>
495 <a name="Programs"></a>
496 <div class="header">
497 <p>
498 Next: <a href="#Files" accesskey="n" rel="next">Files</a>, Previous: <a href="#Fundamental-Operations" accesskey="p" rel="prev">Fundamental Operations</a>, Up: <a href="#Design-Notes" accesskey="u" rel="up">Design Notes</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
499 </div>
500 <a name="Programs-1"></a>
501 <h3 class="section">2.2 Programs</h3>
502
503 <dl compact="compact">
504 <dt><samp>bcron-sched</samp></dt>
505 <dd><p>Top-level scheduler agent. Starts up as root, runs <samp>bcron-exec</samp>,
506 and then drops root permanently.
507 </p>
508 </dd>
509 <dt><samp>bcron-exec</samp></dt>
510 <dd><p>Accepts jobs to run from <samp>bcron-sched</samp> on stdin, writes exit
511 status back to stdout.
512 </p>
513 </dd>
514 <dt><samp>bcron-spool</samp></dt>
515 <dd><p>Manages the cron spool: receives jobs submitted from users, writes
516 them to files in <samp>/var/spool/cron/crontabs</samp>, and notifies
517 <samp>bcron-sched</samp>. This needs to be run from <samp>unixserver</samp> in
518 order to securely determine the invoking UID. This program will
519 optionally run the file through an external filter, specified on the
520 command line, before installing the job.
521 </p>
522 </dd>
523 <dt><samp>bcron-update</samp></dt>
524 <dd><p>Watches for changes to the system crontabs and notifies
525 <samp>bcron-sched</samp>.
526 </p>
527 </dd>
528 </dl>
529
530 <hr>
531 <a name="Files"></a>
532 <div class="header">
533 <p>
534 Next: <a href="#Inter_002dProcess-Communication" accesskey="n" rel="next">Inter-Process Communication</a>, Previous: <a href="#Programs" accesskey="p" rel="prev">Programs</a>, Up: <a href="#Design-Notes" accesskey="u" rel="up">Design Notes</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
535 </div>
536 <a name="Files-1"></a>
537 <h3 class="section">2.3 Files</h3>
538
539 <table class="menu" border="0" cellspacing="0">
540 <tr><td align="left" valign="top">&bull; <a href="#File-Hierarchy" accesskey="1">File Hierarchy</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
541 </td></tr>
542 </table>
543
544 <hr>
545 <a name="File-Hierarchy"></a>
546 <div class="header">
547 <p>
548 Previous: <a href="#Files" accesskey="p" rel="prev">Files</a>, Up: <a href="#Files" accesskey="u" rel="up">Files</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
549 </div>
550 <a name="File-Hierarchy-1"></a>
551 <h4 class="subsection">2.3.1 File Hierarchy</h4>
552
553 <dl compact="compact">
554 <dt><samp>/etc/cron.d/</samp></dt>
555 <dt><samp>/etc/cron.d/*</samp></dt>
556 <dt><samp>/etc/crontab</samp></dt>
557 <dd><p>The above three items are read
558 </p>
559 </dd>
560 <dt><samp>/var/spool/cron/</samp></dt>
561 <dt><samp>/var/spool/cron/crontabs/</samp></dt>
562 <dd><p>Directory containing raw (text) crontab files.
563 </p>
564 </dd>
565 <dt><samp>/var/spool/cron/crontabs/:etc:cron.d:*</samp></dt>
566 <dd><p>Colon is chosen as a seperator because usernames cannot contain
567 colons due to the format of <samp>/etc/passwd</samp>.
568 </p>
569 </dd>
570 <dt><samp>/var/spool/cron/crontabs/:etc:crontab</samp></dt>
571 <dt><samp>/var/spool/cron/bcrontabs/</samp></dt>
572 <dd><p>Directory containing pre-parsed (aka compiled) crontab files (Not yet
573 implemented).
574 </p>
575 </dd>
576 <dt><samp>/var/spool/cron/tmp/</samp></dt>
577 <dd><p>Temporary directory for files as they are written.
578 </p>
579 </dd>
580 <dt><samp>/var/spool/cron/trigger</samp></dt>
581 <dd><p>Named pipe used to tell <samp>bcron-sched</samp> to rescan the crontabs.
582 </p>
583 </dd>
584 </dl>
585
586
587 <hr>
588 <a name="Inter_002dProcess-Communication"></a>
589 <div class="header">
590 <p>
591 Previous: <a href="#Files" accesskey="p" rel="prev">Files</a>, Up: <a href="#Design-Notes" accesskey="u" rel="up">Design Notes</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
592 </div>
593 <a name="Inter_002dProcess-Communication-1"></a>
594 <h3 class="section">2.4 Inter-Process Communication</h3>
595
596 <p>All communication between programs is done in terms of either
597 &ldquo;packets&rdquo; or &ldquo;lines&rdquo;. A packet is formatted as a
598 <a href="http://cr.yp.to/proto/netstrings.txt">netstring</a>. That is, a
599 packet of length <var>N</var> is encoded as the ASCII decimal value of
600 <var>N</var>, &lsquo;<samp>:</samp>&rsquo;, N bytes of data, terminated by &lsquo;<samp>,</samp>&rsquo;. A line is
601 simply a series of non-NUL bytes terminated by a NUL byte.
602 </p>
603 <table class="menu" border="0" cellspacing="0">
604 <tr><td align="left" valign="top">&bull; <a href="#Job-Submission-Protocol" accesskey="1">Job Submission Protocol</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
605 </td></tr>
606 <tr><td align="left" valign="top">&bull; <a href="#bcron_002dexec-Protocol" accesskey="2">bcron-exec Protocol</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
607 </td></tr>
608 </table>
609
610 <hr>
611 <a name="Job-Submission-Protocol"></a>
612 <div class="header">
613 <p>
614 Next: <a href="#bcron_002dexec-Protocol" accesskey="n" rel="next">bcron-exec Protocol</a>, Previous: <a href="#Inter_002dProcess-Communication" accesskey="p" rel="prev">Inter-Process Communication</a>, Up: <a href="#Inter_002dProcess-Communication" accesskey="u" rel="up">Inter-Process Communication</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
615 </div>
616 <a name="Job-Submission-Protocol-1"></a>
617 <h4 class="subsection">2.4.1 Job Submission Protocol</h4>
618
619 <p>Client sends a packet containing a single byte command followed by the
620 username. If the command requires additional data, it is seperated
621 from the username by a NUL byte. Server responds with a packet
622 containing a response byte followed by a text message.
623 </p>
624 <p>Client command codes are:
625 </p><dl compact="compact">
626 <dt><code>S</code></dt>
627 <dd><p>Submit a user crontab file. The content string contains the entire
628 crontab file.
629 </p></dd>
630 <dt><code>L</code></dt>
631 <dd><p>List the current crontab file. No content string.
632 </p></dd>
633 <dt><code>R</code></dt>
634 <dd><p>Remove any previously submitted crontab file. No content string.
635 </p></dd>
636 <dt><code>Y</code></dt>
637 <dd><p>List all system crontabs. No content string. This command is only
638 available to users &lsquo;<samp>root</samp>&rsquo; and &lsquo;<samp>cron</samp>&rsquo;.
639 </p></dd>
640 </dl>
641
642 <p>Server response codes are:
643 </p><dl compact="compact">
644 <dt><code>K</code></dt>
645 <dd><p>Command was successful; file was parsed and accepted.
646 </p></dd>
647 <dt><code>D</code></dt>
648 <dd><p>File could not be parsed.
649 </p></dd>
650 <dt><code>Z</code></dt>
651 <dd><p>Temporary internal error.
652 </p></dd>
653 </dl>
654
655 <hr>
656 <a name="bcron_002dexec-Protocol"></a>
657 <div class="header">
658 <p>
659 Previous: <a href="#Job-Submission-Protocol" accesskey="p" rel="prev">Job Submission Protocol</a>, Up: <a href="#Inter_002dProcess-Communication" accesskey="u" rel="up">Inter-Process Communication</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
660 </div>
661 <a name="bcron_002dexec-Protocol-1"></a>
662 <h4 class="subsection">2.4.2 bcron-exec Protocol</h4>
663
664 <p>Input packets contain a series of four or more NUL-terminated lines:
665 </p><dl compact="compact">
666 <dt><code>ID</code></dt>
667 <dt><code>username</code></dt>
668 <dt><code>command</code></dt>
669 <dt><code>environment</code></dt>
670 <dd><p>The environment is optional. If the environment contains
671 <code>SHELL</code>, it replaces the default shell (&lsquo;<samp>/bin/sh</samp>&rsquo;). If the
672 environment contains <code>MAILTO</code>, it overrides the default mailing
673 address derived from the username.
674 </p></dd>
675 </dl>
676
677 <p>Output packet:
678 </p><dl compact="compact">
679 <dt><code>ID</code></dt>
680 <dt><code>NUL</code></dt>
681 <dt><code>response code</code></dt>
682 <dt><code>text message</code></dt>
683 </dl>
684 <p>Output packets are sent asynchronously with respect to input packets.
685 </p>
686 <hr>
687 <a name="Configuration"></a>
688 <div class="header">
689 <p>
690 Next: <a href="#Implementation-Notes" accesskey="n" rel="next">Implementation Notes</a>, Previous: <a href="#Design-Notes" accesskey="p" rel="prev">Design Notes</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
691 </div>
692 <a name="Configuration-1"></a>
693 <h2 class="chapter">3 Configuration</h2>
694
695 <table class="menu" border="0" cellspacing="0">
696 <tr><td align="left" valign="top">&bull; <a href="#Environment-Variables" accesskey="1">Environment Variables</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
697 </td></tr>
698 </table>
699
700 <hr>
701 <a name="Environment-Variables"></a>
702 <div class="header">
703 <p>
704 Previous: <a href="#Configuration" accesskey="p" rel="prev">Configuration</a>, Up: <a href="#Configuration" accesskey="u" rel="up">Configuration</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
705 </div>
706 <a name="Environment-Variables-1"></a>
707 <h3 class="section">3.1 Environment Variables</h3>
708
709 <dl compact="compact">
710 <dt><code>BCRON_SPOOL</code></dt>
711 <dd><p>The base directory for bcron&rsquo;s files. Defaults to
712 <samp>/var/spool/cron</samp>.
713 </p>
714 </dd>
715 <dt><code>BCRON_USER</code></dt>
716 <dd><p>The non-root user name to switch to for all processes that don&rsquo;t
717 require root privileges. Defaults to &lsquo;<samp>cron</samp>&rsquo;.
718 </p>
719 </dd>
720 <dt><code>BCRON_MAXSIZE</code></dt>
721 <dd><p>The maximum size (in bytes) of a single user crontab. Defaults to
722 unlimited.
723 </p>
724 </dd>
725 <dt><code>BCRON_MAXJOBS</code></dt>
726 <dd><p>The maximum number of jobs in a single user crontab. Defaults to
727 unlimited.
728 </p>
729 </dd>
730 <dt><code>BCRON_SOCKET</code></dt>
731 <dd><p>The full path to the UNIX-domain socket used to submit crontabs.
732 Defaults to <samp>/var/run/bcron-spool</samp>.
733 </p>
734 </dd>
735 </dl>
736
737 <hr>
738 <a name="Implementation-Notes"></a>
739 <div class="header">
740 <p>
741 Previous: <a href="#Configuration" accesskey="p" rel="prev">Configuration</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
742 </div>
743 <a name="Implementation-Notes-1"></a>
744 <h2 class="chapter">4 Implementation Notes</h2>
745
746 <table class="menu" border="0" cellspacing="0">
747 <tr><td align="left" valign="top">&bull; <a href="#Job-Scheduler" accesskey="1">Job Scheduler</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
748 </td></tr>
749 </table>
750
751 <hr>
752 <a name="Job-Scheduler"></a>
753 <div class="header">
754 <p>
755 Previous: <a href="#Implementation-Notes" accesskey="p" rel="prev">Implementation Notes</a>, Up: <a href="#Implementation-Notes" accesskey="u" rel="up">Implementation Notes</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
756 </div>
757 <a name="Job-Scheduler-1"></a>
758 <h3 class="section">4.1 Job Scheduler</h3>
759
760 <p>Getting the job scheduler to work correctly for all possible cases
761 consumed more time than all the other parts of the program put
762 together, and this is <strong>all</strong> because of the problems that
763 daylight savings causes.
764 </p>
765 <p>The ultimate goal is this: given a linear timestamp, determine the
766 <strong>next</strong> linear timestamp after which a job must be run.
767 &ldquo;Linear time&rdquo; means the number of seconds since an epoch, in this
768 case the UNIX epoch, midnight GMT January 1st, 1970. To contrast,
769 &ldquo;local time&rdquo; means the time in terms of years, months, days, hours,
770 minutes, and seconds in the current locale.
771 </p>
772 <p>The time specification for jobs is composed of a set of local time
773 bitmaps quantifying under what time conditions the job should run,
774 assuming the conditions are evaluated every minute. The maximum
775 scheduling resolution is one minute.
776 </p>
777 <p>The effective algorithm is to step through every possible minute until
778 the local time matches all the conditions in the time specification.
779 This would result in an algorithm that could take up to 527,040-1
780 steps to complete, which is far too big a number to evaluate on every
781 job. So, the algorithm optimizes away all impossible cases to make
782 much larger time jumps. For example, if the job cannot be scheduled
783 on the current day, skip over the entire day instead of just the
784 current minute.
785 </p>
786 <p>There are two ways I approached this task. First, do all calculations
787 in terms of local time, and return the linear time at the last step.
788 Second, do as many calculations as possible in terms of linear time,
789 which can be returned directly. Both methods start with the same
790 input data: The current linear time, and a set of bitmasks
791 representing under what time conditions the job should run.
792 </p>
793 <p>The first method was the most straightforward to get mostly working,
794 until I started to consider the implications of DST. During the
795 transition from normal time to DST, an hour is skipped. This is no
796 big deal, as <code>mktime</code> will (or can be made to) compensate by
797 picking the next valid hour when presented with a &ldquo;missing&rdquo; hour.
798 On the other hand, there are many gotchas when dealing with the
799 duplicated hour. For example, hourly jobs need to get scheduled on
800 both, but daily jobs on only one.
801 </p>
802 <p>The second method was harder to get working initially, as the math is
803 more complicated. Despite doing many calculations in terms of linear
804 time, this method still needs to keep track of the local time, in
805 order to check against the bitmaps as well as to determine things like
806 when the next day or month should start. This approach proved to be
807 much easier to work with, once the initial math was done, and easier
808 to make work correctly with regards to DST transitions.
809 </p>
810 <a name="SEC_Contents"></a>
811 <h2 class="contents-heading">Table of Contents</h2>
812
813 <div class="contents">
814 <ul class="no-bullet">
815 <li><a name="toc-Introduction-1" href="#Introduction">1 Introduction</a>
816 <ul class="no-bullet">
817 <li><a name="toc-Problems-With-Other-cron-Systems" href="#Problems">1.1 Problems With Other cron Systems</a>
818 <ul class="no-bullet">
819 <li><a name="toc-vixie_002dcron" href="#Problems-with-vixie_002dcron">1.1.1 vixie-cron</a></li>
820 <li><a name="toc-fcron" href="#Problems-with-fcron">1.1.2 fcron</a></li>
821 <li><a name="toc-anacron" href="#Problems-with-anacron">1.1.3 anacron</a></li>
822 <li><a name="toc-dcron" href="#Problems-with-dcron">1.1.4 dcron</a></li>
823 </ul></li>
824 <li><a name="toc-Requirements-1" href="#Requirements">1.2 Requirements</a></li>
825 <li><a name="toc-Design-Choices-1" href="#Design-Choices">1.3 Design Choices</a></li>
826 <li><a name="toc-vixie_002dcron-Patches-1" href="#vixie_002dcron-Patches">1.4 vixie-cron Patches</a></li>
827 </ul></li>
828 <li><a name="toc-Design-Notes-1" href="#Design-Notes">2 Design Notes</a>
829 <ul class="no-bullet">
830 <li><a name="toc-Fundamental-Operations-1" href="#Fundamental-Operations">2.1 Fundamental Operations</a></li>
831 <li><a name="toc-Programs-1" href="#Programs">2.2 Programs</a></li>
832 <li><a name="toc-Files-1" href="#Files">2.3 Files</a>
833 <ul class="no-bullet">
834 <li><a name="toc-File-Hierarchy-1" href="#File-Hierarchy">2.3.1 File Hierarchy</a></li>
835 </ul></li>
836 <li><a name="toc-Inter_002dProcess-Communication-1" href="#Inter_002dProcess-Communication">2.4 Inter-Process Communication</a>
837 <ul class="no-bullet">
838 <li><a name="toc-Job-Submission-Protocol-1" href="#Job-Submission-Protocol">2.4.1 Job Submission Protocol</a></li>
839 <li><a name="toc-bcron_002dexec-Protocol-1" href="#bcron_002dexec-Protocol">2.4.2 bcron-exec Protocol</a></li>
840 </ul></li>
841 </ul></li>
842 <li><a name="toc-Configuration-1" href="#Configuration">3 Configuration</a>
843 <ul class="no-bullet">
844 <li><a name="toc-Environment-Variables-1" href="#Environment-Variables">3.1 Environment Variables</a></li>
845 </ul></li>
846 <li><a name="toc-Implementation-Notes-1" href="#Implementation-Notes">4 Implementation Notes</a>
847 <ul class="no-bullet">
848 <li><a name="toc-Job-Scheduler-1" href="#Job-Scheduler">4.1 Job Scheduler</a></li>
849 </ul></li>
850
851 </ul>
852 </div>
853
854
855 <div class="footnote">
856 <hr>
857 <h4 class="footnotes-heading">Footnotes</h4>
858
859 <h3><a name="FOOT1" href="#DOCF1">(1)</a></h3>
860 <p>There are actually others, but these two are the most simple
861 and portable of the choices. See also
862 <a href="http://cr.yp.to/docs/secureipc.html">http://cr.yp.to/docs/secureipc.html</a></p>
863 </div>
864 <hr>
865
866
867
868 </body>
869 </html>