home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume23 / vixie-cron / part01 next >
Encoding:
Internet Message Format  |  1990-10-09  |  58.0 KB

  1. Subject:  v23i028:  A cron/crontab replacement, Part01/01
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 5c2f7c46 95a72c9a e2417093 1de75679
  5.  
  6. Submitted-by: Paul A Vixie <vixie@vixie.sf.ca.us>
  7. Posting-number: Volume 23, Issue 28
  8. Archive-name: vixie-cron/part01
  9.  
  10. [ I used the first version of this a few years ago at an old job.
  11.   It was wonderful. --r$  ]
  12.  
  13. At long last.  Here is Cron V2.  It has been submitted to Berkeley for 4.4BSD;
  14. since it didn't make it into 4.3-Reno, I'm going to quench the demand for it
  15. by posting it here.  Here's the README:
  16.  
  17. =====
  18. Vixie's Cron V2.0
  19. July 5, 1990
  20. [V2.0-beta was December 9, 1988]
  21. [V1.0 was May 6, 1987]
  22. Paul Vixie
  23.  
  24. This is a version of 'cron' that is known to run on BSD 4.[23] systems.  It
  25. is functionally based on the SysV cron, which means that each user can have
  26. their own crontab file (all crontab files are stored in a read-protected
  27. directory, usually /var/cron/tabs).  No direct support is provided for
  28. 'at'; you can continue to run 'atrun' from the crontab as you have been
  29. doing.  If you don't have atrun (i.e., System V) you are in trouble.
  30.  
  31. A messages is logged each time a command is executed; also, the files
  32. "allow" and "deny" in /var/cron can be used to control access to the
  33. "crontab" command (which installs crontabs).  It hasn't been tested on
  34. SysV, although some effort has gone into making the port an easy one.
  35.  
  36. The code was all written by me, and is (quoted from Makefile):
  37.  
  38. #/* Copyright 1988,1990 by Paul Vixie
  39. # * All rights reserved
  40. # *
  41. # * Distribute freely, except: don't remove my name from the source or
  42. # * documentation (don't take credit for my work), mark your changes (don't
  43. # * get me blamed for your possible bugs), don't alter or remove this
  44. # * notice.  May be sold if buildable source is provided to buyer.  No
  45. # * warrantee of any kind, express or implied, is included with this
  46. # * software; use at your own risk, responsibility for damages (if any) to
  47. # * anyone resulting from the use of this software rests entirely with the
  48. # * user.
  49. # *
  50. # * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  51. # * I'll try to keep a version up to date.  I can be reached as follows:
  52. # * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  53. # * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  54. # */
  55.  
  56. This is more or less the copyright that USENET contributed software usually
  57. has.  Since ATT couldn't use this version if they had to freely distribute
  58. source, and since I'd love to see them use it, I'll offer some rediculously
  59. low license fee just to have them take it.  In the unlikely event that they
  60. do this, I will continue to support and distribute the pseudo-PD version, so
  61. please, don't flame me for wanting my work to see a wider distribution.
  62.  
  63. To use this: Sorry, folks, there is no cutesy 'Configure' script.  You'll
  64. have to go edit a couple of files... So, here's the checklist:
  65.  
  66.     Read all the FEATURES, INSTALL, and CONVERSION files
  67.     Edit config.h
  68.     Edit Makefile
  69.         (both of these files have instructions inside; note that
  70.          some things in config.h are definable in Makefile and are
  71.          therefore surrounded by #ifndef...#endif)
  72.     'make'
  73.     'su' and 'make install'
  74.         (you may have to install the man pages by hand)
  75.     kill your existing cron process
  76.         (actually you can run your existing cron if you want, but why?)
  77.     build new crontabs using /usr/lib/{crontab,crontab.local}
  78.         (either put them all in "root"'s crontab, or divide it up
  79.          and rip out all the 'su' commands, collapse the lengthy
  80.          lists into ranges with steps -- basically, this step is
  81.          as much work as you want to make it)
  82.     start up the new cron
  83.         (must be done as root)
  84.     watch it. test it with 'crontab -r' and watch the daemon track your
  85.         changes.
  86.     if you like it, change your /etc/{rc,rc.local} to use it instead of
  87.         the old one.
  88.  
  89. $Header: README,v 2.1 90/07/18 00:23:54 vixie Exp $
  90. $Source: /jove_u3/vixie/src/cron/RCS/README,v $
  91. $Revision: 2.1 $
  92. $Log:    README,v $
  93. Revision 2.1  90/07/18  00:23:54  vixie
  94. Baseline for 4.4BSD release
  95.  
  96. Revision 2.0  88/12/10  04:57:50  vixie
  97. V2 Beta
  98.  
  99. Revision 1.2  87/07/10  11:36:45  paul
  100. misc
  101.  
  102. Revision 1.1  87/07/10  11:15:05  paul
  103. Initial revision
  104. =====
  105.  
  106. #! /bin/sh
  107. # This is a shell archive.  Remove anything before this line, then unpack
  108. # it by saving it into a file and typing "sh file".  To overwrite existing
  109. # files, type "sh file -c".  You can also feed this as standard input via
  110. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  111. # will see the following message at the end:
  112. #        "End of archive 1 (of 3)."
  113. # Contents:  CHANGES.V2 CONVERSION FEATURES INSTALL MANIFEST Makefile
  114. #   README THANKS bitstring.3 bitstring.h config.h crond.8 crontab.1
  115. #   env.c job.c user.c
  116. # Wrapped by vixie@volition.pa.dec.com on Wed Jul 18 00:32:47 1990
  117. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  118. if test -f 'CHANGES.V2' -a "${1}" != "-c" ; then 
  119.   echo shar: Will not clobber existing file \"'CHANGES.V2'\"
  120. else
  121. echo shar: Extracting \"'CHANGES.V2'\" \(1786 characters\)
  122. sed "s/^X//" >'CHANGES.V2' <<'END_OF_FILE'
  123. Vixie Cron        Changes from V1 to V2
  124. Paul Vixie
  125. X8-Feb-1988
  126. X
  127. Many changes were made in a rash of activity about six months ago, the exact
  128. list of which is no longer clear in my memory.  I know that V1 used a file
  129. called POKECRON in /usr/spool/cron to tell it that it was time to re-read
  130. all the crontab files; V2 uses the modtime the crontab directory as a flag to
  131. check out the crontab files; those whose modtime has changed will be re-read,
  132. and the others left alone.  Note that the crontab(1) command will do a utimes
  133. call to make sure the mtime of the dir changes, since the filename/inode will
  134. often remain the same after a replacement and the mtime wouldn't change in
  135. that case.
  136. X
  137. X8-Feb-88: made it possible to use much larger environment variable strings.
  138. X    V1 allowed 100 characters; V2 allows 1000.  This was needed for PATH
  139. X    variables on some systems.  Thanks to Toerless Eckert for this idea.
  140. X    E-mail: UUCP: ...pyramid!fauern!faui10!eckert
  141. X
  142. X16-Feb-88: added allow/deny, moved /usr/spool/cron/crontabs to
  143. X    /usr/lib/cron/tabs.  allow and deny are /usr/lib/cron/{allow,deny},
  144. X    since the sysv naming for this depends on 'at' using the same
  145. X    dir, which would be stupid (hint: use /usr/{lib,spool}/at).
  146. X
  147. X22-Feb-88: made it read the spool directory for crontabs and look each one
  148. X    up using getpwnam() rather than reading all passwds with getpwent()
  149. X    and trying to open each crontab.
  150. X
  151. X9-Dec-88: made it sync to :00 after the minute, makes cron predictable.
  152. X    added logging to /var/cron/log.
  153. X
  154. X14-Apr-90: (actually, changes since December 1989)
  155. X    fixed a number of bugs reported from the net and from John Gilmore.
  156. X    added syslog per Keith Bostic.  security features including not
  157. X    being willing to run a command owned or writable by other than
  158. X    the owner of the crontab 9not working well yet)
  159. END_OF_FILE
  160. if test 1786 -ne `wc -c <'CHANGES.V2'`; then
  161.     echo shar: \"'CHANGES.V2'\" unpacked with wrong size!
  162. fi
  163. # end of 'CHANGES.V2'
  164. fi
  165. if test -f 'CONVERSION' -a "${1}" != "-c" ; then 
  166.   echo shar: Will not clobber existing file \"'CONVERSION'\"
  167. else
  168. echo shar: Extracting \"'CONVERSION'\" \(3914 characters\)
  169. sed "s/^X//" >'CONVERSION' <<'END_OF_FILE'
  170. X$Header: CONVERSION,v 2.1 90/07/18 00:27:18 vixie Exp $
  171. X
  172. Conversion of BSD 4.[23] crontab files:
  173. X
  174. XEdit your current crontab (/usr/lib/crontab) into little pieces, with each
  175. users' commands in a different file.  This is different on 4.2 and 4.3,
  176. but I'll get to that below.  The biggest feature of this cron is that you
  177. can move 'news' and 'uucp' cron commands into files owned and maintainable
  178. by those two users.  You also get to rip all the fancy 'su' footwork out
  179. of the cron commands.  On 4.3, there's no need for the 'su' stuff since the
  180. user name appears on each command -- but I'd still rather have separate
  181. crontabs with seperate environments and so on.
  182. X
  183. Leave the original /usr/lib/crontab!  This cron doesn't use it, so you may
  184. as well keep it around for a while in case something goes wakko with this
  185. fancy version.
  186. X
  187. Most commands in most crontabs are run by root, have to run by root, and
  188. should continue to be run by root.  They still have to be in their own file;
  189. I recommend /etc/crontab.src or /usr/adm/crontab.src.
  190. X
  191. X'uucp's commands need their own file; how about /usr/lib/uucp/crontab.src?
  192. X'news' also, perhaps in /usr/lib/news/crontab.src...
  193. X
  194. I say `how about' and `perhaps' because it really doesn't matter to anyone
  195. X(except you) where you put the crontab source files.  The `crontab' command
  196. COPIES them into a protected directory (CRONDIR/SPOOL_DIR in cron.h), named
  197. after the user whose crontab it is.  If you want to examine, replace, or
  198. delete a crontab, the `crontab' command does all of those things.  The
  199. various `crontab.src' (my suggested name for them) files are just source
  200. files---they have to be copied to SPOOLDIR using `crontab' before they'll be
  201. executed.
  202. X
  203. On 4.2, your crontab might have a few lines like this:
  204. X
  205. X    5 * * * *   su uucp < /usr/lib/uucp/uudemon.hr
  206. X    10 4 * * *  su uucp < /usr/lib/uucp/uudemon.day
  207. X    15 5 * * 0  su uucp < /usr/lib/uucp/uudemon.wk
  208. X
  209. X...or like this:
  210. X
  211. X    5 * * * *   echo /usr/lib/uucp/uudemon.hr | su uucp
  212. X    10 4 * * *  echo /usr/lib/uucp/uudemon.day | su uucp
  213. X    15 5 * * 0  echo /usr/lib/uucp/uudemon.wk | su uucp
  214. X
  215. On 4.3, they'd look a little bit better, but not much:
  216. X
  217. X    5 * * * *   uucp  /usr/lib/uucp/uudemon.hr
  218. X    10 4 * * *  uucp  /usr/lib/uucp/uudemon.day
  219. X    15 5 * * 0  uucp  /usr/lib/uucp/uudemon.wk
  220. X
  221. XFor this cron, you'd create /usr/lib/uucp/crontab.src (or wherever you want
  222. to keep uucp's commands) which would look like this:
  223. X
  224. X    # /usr/lib/uucp/crontab.src - uucp's crontab
  225. X    #
  226. X    PATH=/usr/lib/uucp:/bin:/usr/bin
  227. X    SHELL=/bin/sh                # otherwise it's uucico
  228. X    HOME=/usr/lib/uucp            # '' '' /usr/spool/uucppublic
  229. X    #
  230. X    5 * * * *   uudemon.hr
  231. X    10 4 * * *  uudemon.day
  232. X    15 5 * * 0  uudemon.wk
  233. X
  234. The application to the `news' cron commands (if any) is left for you to
  235. figure out.  Likewise if there are any other cruddy-looking 'su' commands in
  236. your crontab commands, you don't need them anymore: just find a good place
  237. to put the `crontab.src' (or whatever you want to call it) file for that
  238. user, put the cron commands into it, and install it using the `crontab'
  239. command (probably with "-u USERNAME", but see the man page).
  240. X
  241. If you run a 4.2-derived cron, you could of course just install your current
  242. crontab in toto as root's crontab.  It would work exactly the way your
  243. current one does, barring the extra steps in installing or changing it.
  244. There would still be advantages to this cron, mostly that you get mail if
  245. there is any output from your cron commands.
  246. X
  247. One note about getting mail from cron: you will probably find, after you
  248. install this version of cron, that your cron commands are generating a lot
  249. of irritating output.  The work-around for this is to redirect all EXPECTED
  250. output to a per-execution log file, which you can examine if you want to
  251. see the output from the "last time" a command was executed; if you get any
  252. UNEXPECTED output, it will be mailed to you.  This takes a while to get
  253. right, but it's amazingly convenient.  Trust me.
  254. X
  255. END_OF_FILE
  256. if test 3914 -ne `wc -c <'CONVERSION'`; then
  257.     echo shar: \"'CONVERSION'\" unpacked with wrong size!
  258. fi
  259. # end of 'CONVERSION'
  260. fi
  261. if test -f 'FEATURES' -a "${1}" != "-c" ; then 
  262.   echo shar: Will not clobber existing file \"'FEATURES'\"
  263. else
  264. echo shar: Extracting \"'FEATURES'\" \(4078 characters\)
  265. sed "s/^X//" >'FEATURES' <<'END_OF_FILE'
  266. X$Header: INFO.features,v 2.0 88/12/10 04:57:35 vixie Exp $
  267. X
  268. XFeatures of Vixie's cron relative to BSD 4.[23] and SysV crons:
  269. X
  270. X--    Environment variables can be set in each crontab.  SHELL, USER,
  271. X    and HOME are set from the user's passwd entry; all except USER
  272. X    can be changed in the crontab.  PATH is especially useful to
  273. X    set there.  TZ can be set, but cron ignores it other than passing
  274. X    it on through to the commands it runs.  Format is
  275. X
  276. X        variable=value
  277. X
  278. X    Blanks surrounding the '=' will be eaten; other blanks in value are
  279. X    okay.  Leading or trailing blanks can be preserved by quoting, single
  280. X    or double quotes are okay, just so they match.
  281. X
  282. X        PATH=.:/bin:/usr/bin
  283. X        SHELL=/bin/sh
  284. X        FOOBAR = this is a long blanky example
  285. X
  286. X    Above, FOOBAR would get `this is a long blanky example' as its value.
  287. X
  288. X    SHELL and HOME will be examined when it's time to run a command; if
  289. X    you don't change them, they default to your /etc/passwd entry.
  290. X
  291. X    *DANGER*, WILL ROBINSON! This means that all 'uucp' logins should set
  292. X    SHELL=/bin/sh or cron will try to use /usr/lib/uucp/uucico as the
  293. X    shell.  This won't work.
  294. X
  295. X    MAILTO, if set to the login name of a user on your system, will be the
  296. X    person that cron mails the output of commands in that crontab.  This is
  297. X    useful if you decide on BINMAIL when configuring cron.h, since binmail
  298. X    doesn't know anything about aliasing.
  299. X
  300. X    Setting SHELL=/bin/sh will in general speed up your commands since it
  301. X    is a much smaller shell than the one you probably use normally (csh
  302. X    or ksh) and has enough features to work non-interactively.
  303. X
  304. X--    Weekdays can be specified by name.  Case is not significant, but only
  305. X    the first three letters should be specified.
  306. X
  307. X--    Months can likewise be specified by name.  Three letters only.
  308. X
  309. X--    Ranges and lists can be mixed.  Standard crons won't allow '1,3-5'.
  310. X
  311. X--    Ranges can specify 'step' values.  '10-16/2' is like '10,12,14,16'.
  312. X
  313. X--    Sunday is both day 0 and day 7 -- apparently BSD and ATT disagree
  314. X    about this.
  315. X
  316. X--    Each user gets their own crontab file.  This is a win over BSD 4.2,
  317. X    where only root has one, and over BSD 4.3, where they made the crontab
  318. X    format incompatible and although the commands can be run by non-root
  319. X    uid's, root is still the only one who can edit the crontab file.  This
  320. X    feature mimics the SysV cron.
  321. X
  322. X--    The 'crontab' command is loosely compatible with SysV, but has more
  323. X    options which just generally make more sense.  Running crontab with
  324. X    no arguments will print a cute little summary of the command syntax.
  325. X
  326. X--    Comments and blank lines are allowed in the crontab file.  Comments
  327. X    must be on a line by themselves; leading whitespace is ignored, and
  328. X    a '#' introduces the comment.
  329. X
  330. X--    (big win) If the `crontab' command changes anything in any crontab, it
  331. X    tells the 'cron' daemon, who reloads all the tables before running the
  332. X    next iteration.  In some crons, you have to kill and restart the
  333. X    daemon whenever you change a crontab.  In other crons, the crontab
  334. X    file is reread and reparsed every minute even if it didn't change.
  335. X
  336. X--    In order to support the automatic reload, the crontab files are not
  337. X    readable or writable except by 'crontab' or 'cron'.  This is not a
  338. X    problem, since 'crontab' will let you do pretty much whatever you
  339. X    want to your own crontab, or if you are root, to anybody's crontab.
  340. X
  341. X--    If any output is generated by a command (on stdout OR stderr), it will
  342. X    be mailed to the owner of the crontab that contained the command (or
  343. X    MAILTO, see discussion of environment variables, above).  The headers
  344. X    of the mail message will include the command that was run, and a
  345. X    complete list of the environment that was passed to it, which will
  346. X    contain (at least) the USER (LOGNAME on SysV), HOME, and SHELL.
  347. X
  348. X--    the dom/dow situation is odd.  '* * 1,15 * Sun' will run on the
  349. X    first and fifteenth AND every Sunday;  '* * * * Sun' will run *only*
  350. X    on Sundays;  '* * 1,15 * *' will run *only* the 1st and 15th.  this
  351. X    is why we keep 'e->dow_star' and 'e->dom_star'.  I didn't think up
  352. X    this behaviour; it's how cron has always worked but the documentation
  353. X    hasn't been very clear.
  354. END_OF_FILE
  355. if test 4078 -ne `wc -c <'FEATURES'`; then
  356.     echo shar: \"'FEATURES'\" unpacked with wrong size!
  357. fi
  358. # end of 'FEATURES'
  359. fi
  360. if test -f 'INSTALL' -a "${1}" != "-c" ; then 
  361.   echo shar: Will not clobber existing file \"'INSTALL'\"
  362. else
  363. echo shar: Extracting \"'INSTALL'\" \(3212 characters\)
  364. sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
  365. X$Header: INSTALL,v 2.1 90/07/18 00:23:36 vixie Exp $
  366. X
  367. X*** This does not work on ATT SysV yet, and given the feature overlap,
  368. X    it may never do so.
  369. X
  370. Read the comments at the top of the Makefile, then edit the area marked
  371. X'configurable stuff'.
  372. X
  373. XEdit config.h.  The stuff I expect you to change is down a bit from the
  374. top of the file, but it's clearly marked.  
  375. X
  376. You don't have to create the /var/cron or /var/cron/tabs directories, since
  377. both the daemon and the `crontab' program will do this the first time they
  378. run if they don't exist.  You do need to have a /var, though -- just "mkdir
  379. X/var" if you don't have one, or you can "mkdir /usr/var; ln -s /usr/var /var"
  380. if you expect your /var to have a lot of stuff in it.
  381. X
  382. You will also need /usr/local/etc and /usr/local/bin directories unless you
  383. change the Makefile.  These will have to be created by hand, but if you are
  384. a long-time Usenet user you probably have them already.  /usr/local/man is
  385. where I keep my man pages, but I have the source for `man' and you probably
  386. do not.  Therefore you may have to put the man pages into /usr/man/manl,
  387. which will be hard since there will be name collisions.  (Note that the man
  388. command was originally written by Bill Joy before he left Berkeley, and it
  389. contains no AT&T code, so it is in UUNET's archive of freely-distributable
  390. BSD code.)
  391. X
  392. say:
  393. X    make all
  394. X
  395. su and say:
  396. X    make install
  397. X
  398. Note that if I can get you to "su and say" something just by asking, you have
  399. a very serious security problem on your system and you should look into it.
  400. X
  401. XEdit your /usr/lib/crontab file into little pieces -- see the CONVERSION file
  402. for help on this.
  403. X
  404. Use the `crontab' command to install all the little pieces you just created.
  405. Some examples (see below before trying any of these!)
  406. X
  407. X    crontab -u uucp -r /usr/lib/uucp/crontab.src
  408. X    crontab -u news -r /usr/lib/news/crontab.src
  409. X    crontab -u root -r /usr/adm/crontab.src
  410. X
  411. Notes on above examples: (1) the .src files are copied at the time the
  412. command is issued; changing the source files later will have no effect until
  413. they are reinstalled with another `crontab -r' command.  (2) The crontab
  414. command will affect the crontab of the person using the command unless `-u
  415. USER' is given; `-u' only works for root.  When using most `su' commands
  416. under most BSD's, `crontab' will still think of you as yourself even though
  417. you may think of yourself as root -- so use `-u' liberally.  (3) the `-r'
  418. option stands for `replace'; check the man page for crontab(1) for other
  419. possibilities.
  420. X
  421. Kill your existing cron daemon -- do `ps aux' and look for /etc/cron.
  422. X
  423. XEdit your /etc/rc or /etc/rc.local, looking for the line that starts up
  424. X/etc/cron.  Comment it out and add a line to start the new cron daemon
  425. X-- usually /usr/local/etc/crond, unless you changed it in the Makefile.
  426. X
  427. Start up this cron daemon yourself as root.  Just type /usr/local/etc/crond
  428. X(or whatever); no '&' is needed since the cron daemon forks itself and the
  429. process you executed returns immediately.
  430. X
  431. ATT notes: for those people unfortunate enough to be stuck on a AT&T UNIX,
  432. you will need the public-domain "libndir", found in the B News source and in
  433. any comp.sources.unix archive.  You will also need to hack the code some.
  434. END_OF_FILE
  435. if test 3212 -ne `wc -c <'INSTALL'`; then
  436.     echo shar: \"'INSTALL'\" unpacked with wrong size!
  437. fi
  438. # end of 'INSTALL'
  439. fi
  440. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  441.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  442. else
  443. echo shar: Extracting \"'MANIFEST'\" \(858 characters\)
  444. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  445. X   File Name        Archive #    Description
  446. X-----------------------------------------------------------
  447. X CHANGES.V2                 1    
  448. X CONVERSION                 1    
  449. X FEATURES                   1    
  450. X INSTALL                    1    
  451. X MANIFEST                   1    This shipping list
  452. X Makefile                   1    
  453. X README                     1    
  454. X THANKS                     1    
  455. X bitstring.3                1    
  456. X bitstring.h                1    
  457. X config.h                   1    
  458. X cron.h                     2    
  459. X crond.8                    1    
  460. X crond.c                    2    
  461. X crontab.1                  1    
  462. X crontab.5                  2    
  463. X crontab.c                  2    
  464. X database.c                 2    
  465. X do_command.c               3    
  466. X entry.c                    2    
  467. X env.c                      1    
  468. X job.c                      1    
  469. X misc.c                     3    
  470. X user.c                     1    
  471. END_OF_FILE
  472. if test 858 -ne `wc -c <'MANIFEST'`; then
  473.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  474. fi
  475. # end of 'MANIFEST'
  476. fi
  477. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  478.   echo shar: Will not clobber existing file \"'Makefile'\"
  479. else
  480. echo shar: Extracting \"'Makefile'\" \(4475 characters\)
  481. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  482. X# Makefile for vixie's cron
  483. X#
  484. X# $Header: Makefile,v 2.2 90/07/18 00:23:57 vixie Locked $
  485. X#
  486. X# vix 03mar88 [moved to RCS, rest of log is in there]
  487. X# vix 30mar87 [goodbye, time.c; hello, getopt]
  488. X# vix 12feb87 [cleanup for distribution]
  489. X# vix 30dec86 [written]
  490. X
  491. X#/* Copyright 1988,1990 by Paul Vixie
  492. X# * All rights reserved
  493. X# *
  494. X# * Distribute freely, except: don't remove my name from the source or
  495. X# * documentation (don't take credit for my work), mark your changes (don't
  496. X# * get me blamed for your possible bugs), don't alter or remove this
  497. X# * notice.  May be sold if buildable source is provided to buyer.  No
  498. X# * warrantee of any kind, express or implied, is included with this
  499. X# * software; use at your own risk, responsibility for damages (if any) to
  500. X# * anyone resulting from the use of this software rests entirely with the
  501. X# * user.
  502. X# *
  503. X# * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  504. X# * I'll try to keep a version up to date.  I can be reached as follows:
  505. X# * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  506. X# * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  507. X# */
  508. X
  509. X# NOTES:
  510. X#    'make' can be done by anyone
  511. X#    'make install' must be done by root
  512. X#
  513. X#    this package needs getopt(3), bitstring(3), and BSD install(8).
  514. X#
  515. X#    the configurable stuff in this makefile consists of compilation
  516. X#    options (use -O, cron runs forever) and destination directories.
  517. X#    SHELL is for the 'augumented make' systems where 'make' imports
  518. X#    SHELL from the environment and then uses it to run its commands.
  519. X#    if your environment SHELL variable is /bin/csh, make goes real
  520. X#    slow and sometimes does the wrong thing.  BINDIR is where the
  521. X#    'crontab' command goes, and should be a common place like /usr/bin.
  522. X#    LIBDIR is where the cron daemon lives; /usr/etc is common.
  523. X#
  524. X#    this package needs the 'bitstring macros' library, which is
  525. X#    available from me or from the comp.sources.unix archive.  if you
  526. X#    put 'bitstring.h' in a non-standard place (i.e., not intuited by
  527. X#    cc(1)), you will have to define INCLUDE to set the include
  528. X#    directory for cc.  INCLUDE should be `-Isomethingorother'.
  529. X#
  530. X#    there's more configuration info in config.h; edit that first!
  531. X
  532. X#################################### begin configurable stuff
  533. X#<<DESTROOT is assumed to have ./etc, ./bin, and ./man subdirectories>>
  534. DESTROOT    =    $(DESTDIR)/usr/local
  535. X#<<CRONDIR will be created by crond or crontab if nec'y>>
  536. CRONDIR        =    /var/cron
  537. X#<<need bitstring.h>>
  538. INCLUDE        =    -I.
  539. X#INCLUDE    =
  540. X#<<need getopt()>>
  541. X#LIBS        =    /usr/local/lib/getopt.o
  542. LIBS        =
  543. X#<<optimize or debug?>>
  544. X#OPTIM        =    -O
  545. OPTIM        =    -g
  546. X#<<want -x flag for debugging?>>
  547. DEBUGGING    =    -DDEBUGGING=1
  548. X#DEBUGGING    =    -DDEBUGGING=0
  549. X#<<ATT or BSD?>>
  550. X# (ATT untested)
  551. X#COMPAT        =    -DATT
  552. COMPAT        =    -DBSD
  553. X#<<lint flags of choice?>>
  554. LINTFLAGS    =    -hbxa $(INCLUDE) $(COMPAT) $(DEBUGGING)
  555. X#<<want to use a nonstandard CC?>>
  556. X#CC        =    vcc
  557. X#<<manifest defines>>
  558. DEFS        =    '-DCRONDIR="$(CRONDIR)"'
  559. X#################################### end configurable stuff
  560. X
  561. SHELL        =    /bin/sh
  562. CFLAGS        =    $(OPTIM) $(INCLUDE) $(COMPAT) $(DEBUGGING) $(DEFS)
  563. X
  564. INFOS        =    README CHANGES.V2 FEATURES INSTALL CONVERSION THANKS
  565. MANPAGES    =    bitstring.3 crontab.5 crontab.1 crond.8
  566. HEADERS        =    bitstring.h cron.h config.h
  567. SOURCES        =    crond.c crontab.c database.c do_command.c \
  568. X            entry.c env.c job.c misc.c user.c
  569. SHAR_SOURCE    =    $(INFOS) $(MANPAGES) Makefile $(HEADERS) $(SOURCES)
  570. LINT_CROND    =    crond.c database.c user.c entry.c \
  571. X            misc.c job.c do_command.c env.c
  572. LINT_CRONTAB    =    crontab.c misc.c entry.c env.c
  573. CRON_OBJ    =    crond.o database.o user.o entry.o \
  574. X            misc.o job.o do_command.o env.o
  575. CRONTAB_OBJ    =    crontab.o misc.o entry.o env.o
  576. X
  577. all        :    crond crontab
  578. X
  579. lint        :
  580. X            lint $(LINTFLAGS) $(LINT_CROND) $(LIBS) \
  581. X            |grep -v "constant argument to NOT" 2>&1
  582. X            lint $(LINTFLAGS) $(LINT_CRONTAB) $(LIBS) \
  583. X            |grep -v "constant argument to NOT" 2>&1
  584. X
  585. crond        :    $(CRON_OBJ)
  586. X            $(CC) -o crond $(CRON_OBJ) $(LIBS)
  587. X
  588. crontab        :    $(CRONTAB_OBJ)
  589. X            $(CC) -o crontab $(CRONTAB_OBJ) $(LIBS)
  590. X
  591. install        :    all
  592. X            install -c -m 111 -o root -s crond $(DESTROOT)/etc/
  593. X            install -c -m 4111 -o root -s crontab $(DESTROOT)/bin/
  594. X            install -c crontab.1 $(DESTROOT)/man/man1/crontab.1
  595. X            install -c crond.8   $(DESTROOT)/man/man8/crond.8
  596. X            install -c crontab.5 $(DESTROOT)/man/man5/crontab.5
  597. X
  598. clean        :;    rm -f *.o crond crontab a.out core tags *~ #*
  599. X
  600. kit        :    $(SHAR_SOURCE)
  601. X            makekit -m -s50k $(SHAR_SOURCE)
  602. X
  603. X$(CRON_OBJ)    :    cron.h config.h Makefile
  604. X$(CRONTAB_OBJ)    :    cron.h config.h Makefile
  605. END_OF_FILE
  606. if test 4475 -ne `wc -c <'Makefile'`; then
  607.     echo shar: \"'Makefile'\" unpacked with wrong size!
  608. fi
  609. # end of 'Makefile'
  610. fi
  611. if test -f 'README' -a "${1}" != "-c" ; then 
  612.   echo shar: Will not clobber existing file \"'README'\"
  613. else
  614. echo shar: Extracting \"'README'\" \(3631 characters\)
  615. sed "s/^X//" >'README' <<'END_OF_FILE'
  616. Vixie's Cron V2.0
  617. July 5, 1990
  618. X[V2.0-beta was December 9, 1988]
  619. X[V1.0 was May 6, 1987]
  620. Paul Vixie
  621. X
  622. This is a version of 'cron' that is known to run on BSD 4.[23] systems.  It
  623. is functionally based on the SysV cron, which means that each user can have
  624. their own crontab file (all crontab files are stored in a read-protected
  625. directory, usually /var/cron/tabs).  No direct support is provided for
  626. X'at'; you can continue to run 'atrun' from the crontab as you have been
  627. doing.  If you don't have atrun (i.e., System V) you are in trouble.
  628. X
  629. A messages is logged each time a command is executed; also, the files
  630. X"allow" and "deny" in /var/cron can be used to control access to the
  631. X"crontab" command (which installs crontabs).  It hasn't been tested on
  632. SysV, although some effort has gone into making the port an easy one.
  633. X
  634. The code was all written by me, and is (quoted from Makefile):
  635. X
  636. X#/* Copyright 1988,1990 by Paul Vixie
  637. X# * All rights reserved
  638. X# *
  639. X# * Distribute freely, except: don't remove my name from the source or
  640. X# * documentation (don't take credit for my work), mark your changes (don't
  641. X# * get me blamed for your possible bugs), don't alter or remove this
  642. X# * notice.  May be sold if buildable source is provided to buyer.  No
  643. X# * warrantee of any kind, express or implied, is included with this
  644. X# * software; use at your own risk, responsibility for damages (if any) to
  645. X# * anyone resulting from the use of this software rests entirely with the
  646. X# * user.
  647. X# *
  648. X# * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  649. X# * I'll try to keep a version up to date.  I can be reached as follows:
  650. X# * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  651. X# * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  652. X# */
  653. X
  654. This is more or less the copyright that USENET contributed software usually
  655. has.  Since ATT couldn't use this version if they had to freely distribute
  656. source, and since I'd love to see them use it, I'll offer some rediculously
  657. low license fee just to have them take it.  In the unlikely event that they
  658. do this, I will continue to support and distribute the pseudo-PD version, so
  659. please, don't flame me for wanting my work to see a wider distribution.
  660. X
  661. To use this: Sorry, folks, there is no cutesy 'Configure' script.  You'll
  662. have to go edit a couple of files... So, here's the checklist:
  663. X
  664. X    Read all the FEATURES, INSTALL, and CONVERSION files
  665. X    Edit config.h
  666. X    Edit Makefile
  667. X        (both of these files have instructions inside; note that
  668. X         some things in config.h are definable in Makefile and are
  669. X         therefore surrounded by #ifndef...#endif)
  670. X    'make'
  671. X    'su' and 'make install'
  672. X        (you may have to install the man pages by hand)
  673. X    kill your existing cron process
  674. X        (actually you can run your existing cron if you want, but why?)
  675. X    build new crontabs using /usr/lib/{crontab,crontab.local}
  676. X        (either put them all in "root"'s crontab, or divide it up
  677. X         and rip out all the 'su' commands, collapse the lengthy
  678. X         lists into ranges with steps -- basically, this step is
  679. X         as much work as you want to make it)
  680. X    start up the new cron
  681. X        (must be done as root)
  682. X    watch it. test it with 'crontab -r' and watch the daemon track your
  683. X        changes.
  684. X    if you like it, change your /etc/{rc,rc.local} to use it instead of
  685. X        the old one.
  686. X
  687. X$Header: README,v 2.1 90/07/18 00:23:54 vixie Exp $
  688. X$Source: /jove_u3/vixie/src/cron/RCS/README,v $
  689. X$Revision: 2.1 $
  690. X$Log:    README,v $
  691. Revision 2.1  90/07/18  00:23:54  vixie
  692. Baseline for 4.4BSD release
  693. X
  694. Revision 2.0  88/12/10  04:57:50  vixie
  695. V2 Beta
  696. X
  697. Revision 1.2  87/07/10  11:36:45  paul
  698. misc
  699. X
  700. Revision 1.1  87/07/10  11:15:05  paul
  701. Initial revision
  702. END_OF_FILE
  703. if test 3631 -ne `wc -c <'README'`; then
  704.     echo shar: \"'README'\" unpacked with wrong size!
  705. fi
  706. # end of 'README'
  707. fi
  708. if test -f 'THANKS' -a "${1}" != "-c" ; then 
  709.   echo shar: Will not clobber existing file \"'THANKS'\"
  710. else
  711. echo shar: Extracting \"'THANKS'\" \(1598 characters\)
  712. sed "s/^X//" >'THANKS' <<'END_OF_FILE'
  713. X15 January 1990
  714. Paul Vixie
  715. X
  716. Many people have contributed to cron.  Many more than I can remember, in fact.
  717. Rich Salz and Carl Gutekunst were each of enormous help to me in V1; Carl for
  718. helping me understand UNIX well enough to write it, and Rich for helping me
  719. get the features right.
  720. X
  721. John Gilmore wrote me a wonderful review of V2, which took me a whole year to
  722. answer even though it made me clean up some really awful things in the code.
  723. X(According to John the most awful things are still in here, of course.)
  724. X
  725. Paul Close made a suggestion which led to /etc/crond.pid and the mutex locking
  726. on it.  Kevin Braunsdorf of Purdue made a suggestion that led to @reboot and
  727. its brothers and sisters; he also sent some diffs that lead cron toward compil-
  728. ability with System V, though without at(1) capabilities, this cron isn't going
  729. to be that useful on System V.  Bob Alverson fixed a silly bug in the line
  730. number counting.  Brian Reid made suggestions which led to the run queue and
  731. the source-file labelling in installed crontabs.
  732. X
  733. Scott Narveson ported V2 to a Sequent, and sent in the most useful single batch
  734. of diffs I got from anybody.  Changes attributable to Scott are:
  735. X    -> sendmail won't time out if the command is slow to generate output
  736. X    -> day-of-week names aren't off by one anymore
  737. X    -> crontab says the right thing if you do something you shouldn't do
  738. X    -> crontab(5) man page is longer and more informative
  739. X    -> misc changes related to the side effects of fclose()
  740. X    -> Sequent "universe" support added (may also help on Pyramids)
  741. X    -> null pw_shell is dealt with now; default is /bin/sh
  742. END_OF_FILE
  743. if test 1598 -ne `wc -c <'THANKS'`; then
  744.     echo shar: \"'THANKS'\" unpacked with wrong size!
  745. fi
  746. # end of 'THANKS'
  747. fi
  748. if test -f 'bitstring.3' -a "${1}" != "-c" ; then 
  749.   echo shar: Will not clobber existing file \"'bitstring.3'\"
  750. else
  751. echo shar: Extracting \"'bitstring.3'\" \(3395 characters\)
  752. sed "s/^X//" >'bitstring.3' <<'END_OF_FILE'
  753. X.\" Copyright (c) 1989 The Regents of the University of California.
  754. X.\" All rights reserved.
  755. X.\"
  756. X.\" This code is derived from software contributed to Berkeley by
  757. X.\" Paul Vixie.
  758. X.\"
  759. X.\" Redistribution and use in source and binary forms are permitted
  760. X.\" provided that the above copyright notice and this paragraph are
  761. X.\" duplicated in all such forms and that any documentation,
  762. X.\" advertising materials, and other materials related to such
  763. X.\" distribution and use acknowledge that the software was developed
  764. X.\" by the University of California, Berkeley.  The name of the
  765. X.\" University may not be used to endorse or promote products derived
  766. X.\" from this software without specific prior written permission.
  767. X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  768. X.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  769. X.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  770. X.\"
  771. X.\"    @(#)bitstring.3    5.1 (Berkeley) 12/13/89
  772. X.\"
  773. X.TH BITSTRING 3  "December 13, 1989"
  774. X.UC 4
  775. X.SH NAME
  776. bit_alloc, bit_clear, bit_decl, bit_ffs, bit_nclear, bit_nset,
  777. bit_set, bitstr_size, bit_test \- bit-string manipulation macros
  778. X.SH SYNOPSIS
  779. X.ft B
  780. X.nf
  781. X#include <bitstring.h>
  782. X
  783. name = bit_alloc(nbits)
  784. bitstr_t *name;
  785. int nbits;
  786. X
  787. bit_decl(name, nbits)
  788. bitstr_t name;
  789. int nbits;
  790. X
  791. bit_clear(name, bit)
  792. bitstr_t name;
  793. int bit;
  794. X
  795. bit_ffc(name, nbits, value)
  796. bitstr_t name;
  797. int nbits, *value;
  798. X
  799. bit_ffs(name, nbits, value)
  800. bitstr_t name;
  801. int nbits, *value;
  802. X
  803. bit_nclear(name, start, stop)
  804. bitstr_t name;
  805. int start, stop;
  806. X
  807. bit_nset(name, start, stop)
  808. bitstr_t name;
  809. int start, stop;
  810. X
  811. bit_set(name, bit)
  812. bitstr_t name;
  813. int bit;
  814. X
  815. bitstr_size(nbits)
  816. int nbits;
  817. X
  818. bit_test(name, bit)
  819. bitstr_t name;
  820. int bit;
  821. X.fi
  822. X.ft R
  823. X.SH DESCRIPTION
  824. These macros operate on strings of bits.
  825. X.PP
  826. X.I Bit_alloc
  827. returns a pointer of type
  828. X.I bitstr_t\ *
  829. to sufficient space to store
  830. X.I nbits
  831. bits, or NULL if no space is available.
  832. X.PP
  833. X.I Bit_decl
  834. is a macro for allocating sufficient space to store
  835. X.I nbits
  836. bits on the stack.
  837. X.PP
  838. X.I Bitstr_size
  839. returns the number of elements of type
  840. X.I bitstr_t
  841. necessary to store
  842. X.I nbits
  843. bits.
  844. This is useful for copying bit strings.
  845. X.PP
  846. X.I Bit_clear
  847. and
  848. X.I bit_set
  849. clear or set the zero-based numbered bit
  850. X.IR bit ,
  851. in the bit string
  852. X.IR name .
  853. X.PP
  854. X.I Bit_nset
  855. and
  856. X.I bit_nclear
  857. set or clear the zero-based numbered bits from
  858. X.I start
  859. to
  860. X.I stop
  861. in the bit string
  862. X.IR name .
  863. X.PP
  864. X.I Bit_test
  865. evaluates to zero if the zero-based numbered bit
  866. X.I bit
  867. of bit string
  868. X.I name
  869. is set, and non-zero otherwise.
  870. X.PP
  871. X.I Bit_ffs
  872. sets
  873. X.I *value
  874. to the zero-based number of the first bit set in the array of
  875. X.I nbits
  876. bits referenced by
  877. X.IR name .
  878. If no bits are set,
  879. X.I *value
  880. is set to -1.
  881. X.PP
  882. X.I Bit_ffc
  883. sets
  884. X.I *value
  885. to the zero-based number of the first bit not set in the array of
  886. X.I nbits
  887. bits referenced by
  888. X.IR name .
  889. If all bits are set,
  890. X.I value
  891. is set to -1.
  892. X.SH EXAMPLE
  893. X.nf
  894. X.in +5
  895. X#include <limits.h>
  896. X#include <bitstring.h>
  897. X
  898. X...
  899. X#define    LPR_BUSY_BIT        0
  900. X#define    LPR_FORMAT_BIT        1
  901. X#define    LPR_DOWNLOAD_BIT    2
  902. X...
  903. X#define    LPR_AVAILABLE_BIT    9
  904. X#define    LPR_MAX_BITS        10
  905. X
  906. make_lpr_available()
  907. X{
  908. X    bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
  909. X    ...
  910. X    bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
  911. X    ...
  912. X    if (!bit_test(bitlist, LPR_BUSY_BIT)) {
  913. X        bit_clear(bitlist, LPR_FORMAT_BIT);
  914. X        bit_clear(bitlist, LPR_DOWNLOAD_BIT);
  915. X        bit_set(bitlist, LPR_AVAILABLE_BIT);
  916. X    }
  917. X}
  918. X.fi
  919. X.SH "SEE ALSO"
  920. malloc(3)
  921. END_OF_FILE
  922. if test 3395 -ne `wc -c <'bitstring.3'`; then
  923.     echo shar: \"'bitstring.3'\" unpacked with wrong size!
  924. fi
  925. # end of 'bitstring.3'
  926. fi
  927. if test -f 'bitstring.h' -a "${1}" != "-c" ; then 
  928.   echo shar: Will not clobber existing file \"'bitstring.h'\"
  929. else
  930. echo shar: Extracting \"'bitstring.h'\" \(3656 characters\)
  931. sed "s/^X//" >'bitstring.h' <<'END_OF_FILE'
  932. X/*
  933. X * Copyright (c) 1989 The Regents of the University of California.
  934. X * All rights reserved.
  935. X *
  936. X * This code is derived from software contributed to Berkeley by
  937. X * Paul Vixie.
  938. X *
  939. X * Redistribution and use in source and binary forms are permitted
  940. X * provided that the above copyright notice and this paragraph are
  941. X * duplicated in all such forms and that any documentation,
  942. X * advertising materials, and other materials related to such
  943. X * distribution and use acknowledge that the software was developed
  944. X * by the University of California, Berkeley.  The name of the
  945. X * University may not be used to endorse or promote products derived
  946. X * from this software without specific prior written permission.
  947. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  948. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  949. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  950. X *
  951. X *    @(#)bitstring.h    5.2 (Berkeley) 4/4/90
  952. X */
  953. X
  954. typedef    unsigned char bitstr_t;
  955. X
  956. X/* internal macros */
  957. X                /* byte of the bitstring bit is in */
  958. X#define    _bit_byte(bit) \
  959. X    ((bit) >> 3)
  960. X
  961. X                /* mask for the bit within its byte */
  962. X#define    _bit_mask(bit) \
  963. X    (1 << ((bit)&0x7))
  964. X
  965. X/* external macros */
  966. X                /* bytes in a bitstring of nbits bits */
  967. X#define    bitstr_size(nbits) \
  968. X    ((((nbits) - 1) >> 3) + 1)
  969. X
  970. X                /* allocate a bitstring */
  971. X#define    bit_alloc(nbits) \
  972. X    (bitstr_t *)malloc(1, \
  973. X        (unsigned int)_bitstr_size(nbits) * sizeof(bitstr_t))
  974. X
  975. X                /* allocate a bitstring on the stack */
  976. X#define    bit_decl(name, nbits) \
  977. X    (name)[bitstr_size(nbits)]
  978. X
  979. X                /* is bit N of bitstring name set? */
  980. X#define    bit_test(name, bit) \
  981. X    ((name)[_bit_byte(bit)] & _bit_mask(bit))
  982. X
  983. X                /* set bit N of bitstring name */
  984. X#define    bit_set(name, bit) \
  985. X    (name)[_bit_byte(bit)] |= _bit_mask(bit)
  986. X
  987. X                /* clear bit N of bitstring name */
  988. X#define    bit_clear(name, bit) \
  989. X    (name)[_bit_byte(bit)] &= ~_bit_mask(bit)
  990. X
  991. X                /* clear bits start ... stop in bitstring */
  992. X#define    bit_nclear(name, start, stop) { \
  993. X    register bitstr_t *_name = name; \
  994. X    register int _start = start, _stop = stop; \
  995. X    register int _startbyte = _bit_byte(_start); \
  996. X    register int _stopbyte = _bit_byte(_stop); \
  997. X    _name[_startbyte] &= 0xff >> (8 - (_start&0x7)); \
  998. X    while (++_startbyte < _stopbyte) \
  999. X        _name[_startbyte] = 0; \
  1000. X    _name[_stopbyte] &= 0xff << ((_stop&0x7) + 1); \
  1001. X}
  1002. X
  1003. X                /* set bits start ... stop in bitstring */
  1004. X#define    bit_nset(name, start, stop) { \
  1005. X    register bitstr_t *_name = name; \
  1006. X    register int _start = start, _stop = stop; \
  1007. X    register int _startbyte = _bit_byte(_start); \
  1008. X    register int _stopbyte = _bit_byte(_stop); \
  1009. X    _name[_startbyte] |= 0xff << ((start)&0x7); \
  1010. X    while (++_startbyte < _stopbyte) \
  1011. X        _name[_startbyte] = 0xff; \
  1012. X    _name[_stopbyte] |= 0xff >> (7 - (_stop&0x7)); \
  1013. X}
  1014. X
  1015. X                /* find first bit clear in name */
  1016. X#define    bit_ffc(name, nbits, value) { \
  1017. X    register bitstr_t *_name = name; \
  1018. X    register int _byte, _nbits = nbits; \
  1019. X    register int _stopbyte = _bit_byte(_nbits), _value = -1; \
  1020. X    for (_byte = 0; _byte <= _stopbyte; ++_byte) \
  1021. X        if (_name[_byte] != 0xff) { \
  1022. X            _value = _byte << 3; \
  1023. X            for (_stopbyte = _name[_byte]; (_stopbyte&0x1); \
  1024. X                ++_value, _stopbyte >>= 1); \
  1025. X            break; \
  1026. X        } \
  1027. X    *(value) = _value; \
  1028. X}
  1029. X
  1030. X                /* find first bit set in name */
  1031. X#define    bit_ffs(name, nbits, value) { \
  1032. X    register bitstr_t *_name = name; \
  1033. X    register int _byte, _nbits = nbits; \
  1034. X    register int _stopbyte = _bit_byte(_nbits), _value = -1; \
  1035. X    for (_byte = 0; _byte <= _stopbyte; ++_byte) \
  1036. X        if (_name[_byte]) { \
  1037. X            _value = _byte << 3; \
  1038. X            for (_stopbyte = _name[_byte]; !(_stopbyte&0x1); \
  1039. X                ++_value, _stopbyte >>= 1); \
  1040. X            break; \
  1041. X        } \
  1042. X    *(value) = _value; \
  1043. X}
  1044. END_OF_FILE
  1045. if test 3656 -ne `wc -c <'bitstring.h'`; then
  1046.     echo shar: \"'bitstring.h'\" unpacked with wrong size!
  1047. fi
  1048. # end of 'bitstring.h'
  1049. fi
  1050. if test -f 'config.h' -a "${1}" != "-c" ; then 
  1051.   echo shar: Will not clobber existing file \"'config.h'\"
  1052. else
  1053. echo shar: Extracting \"'config.h'\" \(3929 characters\)
  1054. sed "s/^X//" >'config.h' <<'END_OF_FILE'
  1055. X/* config.h - configurables for Vixie Cron
  1056. X *
  1057. X * $Header: config.h,v 2.1 90/07/18 00:24:35 vixie Exp $
  1058. X */
  1059. X
  1060. X/* Copyright 1988,1990 by Paul Vixie
  1061. X * All rights reserved
  1062. X *
  1063. X * Distribute freely, except: don't remove my name from the source or
  1064. X * documentation (don't take credit for my work), mark your changes (don't
  1065. X * get me blamed for your possible bugs), don't alter or remove this
  1066. X * notice.  May be sold if buildable source is provided to buyer.  No
  1067. X * warrantee of any kind, express or implied, is included with this
  1068. X * software; use at your own risk, responsibility for damages (if any) to
  1069. X * anyone resulting from the use of this software rests entirely with the
  1070. X * user.
  1071. X *
  1072. X * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  1073. X * I'll try to keep a version up to date.  I can be reached as follows:
  1074. X * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  1075. X * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  1076. X */
  1077. X
  1078. X#ifndef    _CONFIG_FLAG
  1079. X#define    _CONFIG_FLAG
  1080. X
  1081. X/*
  1082. X * these are site-dependent
  1083. X */
  1084. X            /*
  1085. X             * choose one of these MAILCMD commands.  I use
  1086. X             * /bin/mail for speed; it makes biff bark but doesn't
  1087. X             * do aliasing.  /usr/lib/sendmail does aliasing but is
  1088. X             * a hog for short messages.  aliasing is not needed
  1089. X             * if you make use of the MAILTO= feature in crontabs.
  1090. X             * (hint: MAILTO= was added for this reason).
  1091. X             */
  1092. X
  1093. X# define MAILCMD "/usr/lib/sendmail -F\"Cron Daemon\" -odi -oem -or0s %s" /*-*/
  1094. X            /* -Fx     = set full-name of sender
  1095. X             * -odi     = Option Deliverymode Interactive
  1096. X             * -oem     = Option Errors Mailedtosender
  1097. X             * -or0s = Option Readtimeout -- don't time out
  1098. X             */
  1099. X
  1100. X/* # define MAILCMD "/bin/mail -d  %s"        /*-*/
  1101. X            /* -d = undocumented but common flag: deliver locally?
  1102. X             */
  1103. X
  1104. X#ifndef CRONDIR
  1105. X            /* CRONDIR is where crond(8) and crontab(1) both chdir
  1106. X             * to; SPOOL_DIR, ALLOW_FILE, DENY_FILE, and LOG_FILE
  1107. X             * are all relative to this directory.
  1108. X             *
  1109. X             * this can and should be set in the Makefile.
  1110. X             */
  1111. X# define CRONDIR    "/var/cron"
  1112. X#endif
  1113. X
  1114. X            /* SPOOLDIR is where the crontabs live.
  1115. X             * This directory will have its modtime updated
  1116. X             * whenever crontab(1) changes a crontab; this is
  1117. X             * the signal for crond(8) to look at each individual
  1118. X             * crontab file and reload those whose modtimes are
  1119. X             * newer than they were last time around (or which
  1120. X             * didn't exist last time around...)
  1121. X             */
  1122. X#define SPOOL_DIR    "tabs"
  1123. X
  1124. X            /* undefining these turns off their features.  note
  1125. X             * that ALLOW_FILE and DENY_FILE must both be defined
  1126. X             * in order to enable the allow/deny code.  If neither
  1127. X             * LOG_FILE or SYSLOG is defined, we don't log.  If
  1128. X             * both are defined, we log both ways.
  1129. X             */
  1130. X#define    ALLOW_FILE    "allow"        /*-*/
  1131. X#define DENY_FILE    "deny"        /*-*/
  1132. X#define LOG_FILE    "log"        /*-*/
  1133. X
  1134. X            /* if ALLOW_FILE and DENY_FILE are not defined or are
  1135. X             * defined but neither exists, should crontab(1) be
  1136. X             * usable only by root?
  1137. X             */
  1138. X/*#define ALLOW_ONLY_ROOT            /*-*/
  1139. X
  1140. X            /* if you want to use syslog(3) instead of appending
  1141. X             * to CRONDIR/LOG_FILE (/var/cron/log, e.g.), define
  1142. X             * SYSLOG here.  Note that quite a bit of logging
  1143. X             * info is written, and that you probably don't want
  1144. X             * to use this on 4.2bsd since everything goes in
  1145. X             * /usr/spool/mqueue/syslog.  On 4.[34]bsd you can
  1146. X             * tell /etc/syslog.conf to send cron's logging to
  1147. X             * a separate file.
  1148. X             */
  1149. X/*#define SYSLOG                 /*-*/
  1150. X
  1151. X            /* this is the name of the environment variable
  1152. X             * that contains the user name.  it isn't read by
  1153. X             * cron, but it is SET by crond in the environments
  1154. X             * it creates for subprocesses.  on BSD, it will
  1155. X             * always be USER; on SysV it could be LOGNAME or
  1156. X             * something else.
  1157. X             */
  1158. X#if defined(BSD)
  1159. X# define USERENV    "USER"
  1160. X#endif
  1161. X#if defined(ATT)
  1162. X# define USERENV    "LOGNAME"
  1163. X#endif
  1164. X
  1165. X            /* where should the daemon stick its PID?
  1166. X             */
  1167. X#define PIDFILE        "/etc/crond.pid"
  1168. X
  1169. X#endif /*CONFIG_FLAG*/
  1170. END_OF_FILE
  1171. if test 3929 -ne `wc -c <'config.h'`; then
  1172.     echo shar: \"'config.h'\" unpacked with wrong size!
  1173. fi
  1174. # end of 'config.h'
  1175. fi
  1176. if test -f 'crond.8' -a "${1}" != "-c" ; then 
  1177.   echo shar: Will not clobber existing file \"'crond.8'\"
  1178. else
  1179. echo shar: Extracting \"'crond.8'\" \(2165 characters\)
  1180. sed "s/^X//" >'crond.8' <<'END_OF_FILE'
  1181. X.\" $Header: crond.8,v 2.1 90/07/18 00:23:40 vixie Exp $
  1182. X.\" 
  1183. X.\"/* Copyright 1988,1990 by Paul Vixie
  1184. X.\" * All rights reserved
  1185. X.\" *
  1186. X.\" * Distribute freely, except: don't remove my name from the source or
  1187. X.\" * documentation (don't take credit for my work), mark your changes (don't
  1188. X.\" * get me blamed for your possible bugs), don't alter or remove this
  1189. X.\" * notice.  May be sold if buildable source is provided to buyer.  No
  1190. X.\" * warrantee of any kind, express or implied, is included with this
  1191. X.\" * software; use at your own risk, responsibility for damages (if any) to
  1192. X.\" * anyone resulting from the use of this software rests entirely with the
  1193. X.\" * user.
  1194. X.\" *
  1195. X.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  1196. X.\" * I'll try to keep a version up to date.  I can be reached as follows:
  1197. X.\" * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  1198. X.\" * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  1199. X.\" */
  1200. X.TH CROND 8 "15 Nov 1988"
  1201. X.UC 4
  1202. X.SH NAME
  1203. crond \- daemon to execute scheduled commands (Vixie Cron)
  1204. X.SH SYNOPSIS
  1205. crond
  1206. X.SH DESCRIPTION
  1207. X.I Crond
  1208. should be started from /etc/rc or /etc/rc.local.  It will return immediately,
  1209. so you don't need to start it with '&'.
  1210. X.PP
  1211. X.I Crond
  1212. searches /var/cron/tabs for crontab files which are named after accounts in
  1213. X/etc/passwd; crontabs found are loaded into memory.
  1214. X.I Crond
  1215. then wakes up every minute, examining all stored crontabs, checking each
  1216. command to see if it should be run in the current minute.  When executing
  1217. commands, any output is mailed to the owner of the crontab (or to the user
  1218. named in the MAILTO environment variable in the crontab, if such exists).
  1219. X.PP
  1220. Additionally,
  1221. X.I crond
  1222. checks each minute to see if its spool directory's modtime has changed, and
  1223. if it has,
  1224. X.I crond
  1225. will then examine the modtime on all crontabs and reload those which have
  1226. changed.  Thus
  1227. X.I crond
  1228. need not be restarted whenever a crontab file is modified.  Note that the
  1229. X.IR Crontab (1)
  1230. command updates the modtime of the spool directory whenever it changes a
  1231. crontab.
  1232. X.SH "SEE ALSO"
  1233. crontab(1), crontab(5)
  1234. X.SH AUTHOR
  1235. X.nf
  1236. Paul Vixie, paul@vixie.sf.ca.us
  1237. END_OF_FILE
  1238. if test 2165 -ne `wc -c <'crond.8'`; then
  1239.     echo shar: \"'crond.8'\" unpacked with wrong size!
  1240. fi
  1241. # end of 'crond.8'
  1242. fi
  1243. if test -f 'crontab.1' -a "${1}" != "-c" ; then 
  1244.   echo shar: Will not clobber existing file \"'crontab.1'\"
  1245. else
  1246. echo shar: Extracting \"'crontab.1'\" \(2789 characters\)
  1247. sed "s/^X//" >'crontab.1' <<'END_OF_FILE'
  1248. X.\" $Header: crontab.1,v 2.1 90/07/18 00:23:43 vixie Exp $
  1249. X.\"
  1250. X.\"/* Copyright 1988,1990 by Paul Vixie
  1251. X.\" * All rights reserved
  1252. X.\" *
  1253. X.\" * Distribute freely, except: don't remove my name from the source or
  1254. X.\" * documentation (don't take credit for my work), mark your changes (don't
  1255. X.\" * get me blamed for your possible bugs), don't alter or remove this
  1256. X.\" * notice.  May be sold if buildable source is provided to buyer.  No
  1257. X.\" * warrantee of any kind, express or implied, is included with this
  1258. X.\" * software; use at your own risk, responsibility for damages (if any) to
  1259. X.\" * anyone resulting from the use of this software rests entirely with the
  1260. X.\" * user.
  1261. X.\" *
  1262. X.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  1263. X.\" * I'll try to keep a version up to date.  I can be reached as follows:
  1264. X.\" * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  1265. X.\" * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  1266. X.\" */
  1267. X.TH CRONTAB 1 "9 December 1988"
  1268. X.UC 4
  1269. X.SH NAME
  1270. crontab \- maintain crontab files for individual users
  1271. X.SH SYNOPSIS
  1272. crontab [ -u user ] { -l | -d | -r file }
  1273. X.SH DESCRIPTION
  1274. X.I Crontab
  1275. is the program used to install, deinstall or list the tables
  1276. used to drive the
  1277. X.IR crond (8)
  1278. daemon in Vixie Cron.  Each user has their own crontab, and though these are
  1279. files in /var, they are not readable or writable by anyone or anything
  1280. except the super-user or the
  1281. X.IR crond (8)
  1282. or
  1283. X.I crontab
  1284. programs.
  1285. X.PP
  1286. If the
  1287. X.I allow
  1288. file exists, then you must be listed therein in order to be allowed to use
  1289. this command.  If the
  1290. X.I allow
  1291. file does not exist but the
  1292. X.I deny
  1293. file does exist, then you must \fBnot\fR be listed in the
  1294. X.I deny
  1295. file in order to use this command.  If neither of these files exists, then
  1296. depending on site-dependent configuration parameters, only the super user
  1297. will be allowed to use this command, or all users will be able to use this
  1298. command.
  1299. X.PP
  1300. If the
  1301. X.I -u
  1302. option is given, it specifies the name of the user whose crontab is to be
  1303. tweaked.  If this option is not given,
  1304. X.I crontab
  1305. examines "your" crontab, i.e., the crontab of the person executing the
  1306. command.  Note that
  1307. X.IR su (8)
  1308. can confuse
  1309. X.I crontab
  1310. and that if you are running inside of
  1311. X.IR su (8)
  1312. you should always use the
  1313. X.I -u
  1314. option for safety's sake.
  1315. X.PP
  1316. The
  1317. X.I -l
  1318. option causes the current crontab to be displayed on standard output.
  1319. X.PP
  1320. The
  1321. X.I -d
  1322. option causes the current crontab to be deleted.
  1323. X.PP
  1324. The
  1325. X.I -r
  1326. option is used to replace the current
  1327. crontab (if any) with the contents of the named file.
  1328. X.SH "SEE ALSO"
  1329. crontab(5), crond(8)
  1330. X.SH FILES
  1331. X.nf
  1332. X/var/cron/allow
  1333. X/var/cron/deny
  1334. X.fi
  1335. X.SH DIAGNOSTICS
  1336. A fairly informative usage message appears if you run it with a bad command
  1337. line.
  1338. X.SH AUTHOR
  1339. X.nf
  1340. Paul Vixie, paul@vixie.sf.ca.us
  1341. END_OF_FILE
  1342. if test 2789 -ne `wc -c <'crontab.1'`; then
  1343.     echo shar: \"'crontab.1'\" unpacked with wrong size!
  1344. fi
  1345. # end of 'crontab.1'
  1346. fi
  1347. if test -f 'env.c' -a "${1}" != "-c" ; then 
  1348.   echo shar: Will not clobber existing file \"'env.c'\"
  1349. else
  1350. echo shar: Extracting \"'env.c'\" \(3475 characters\)
  1351. sed "s/^X//" >'env.c' <<'END_OF_FILE'
  1352. X#if !defined(lint) && !defined(LINT)
  1353. static char rcsid[] = "$Header: env.c,v 2.2 90/07/18 00:23:48 vixie Exp $";
  1354. X#endif
  1355. X
  1356. X/* Copyright 1988,1990 by Paul Vixie
  1357. X * All rights reserved
  1358. X *
  1359. X * Distribute freely, except: don't remove my name from the source or
  1360. X * documentation (don't take credit for my work), mark your changes (don't
  1361. X * get me blamed for your possible bugs), don't alter or remove this
  1362. X * notice.  May be sold if buildable source is provided to buyer.  No
  1363. X * warrantee of any kind, express or implied, is included with this
  1364. X * software; use at your own risk, responsibility for damages (if any) to
  1365. X * anyone resulting from the use of this software rests entirely with the
  1366. X * user.
  1367. X *
  1368. X * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  1369. X * I'll try to keep a version up to date.  I can be reached as follows:
  1370. X * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  1371. X * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  1372. X */
  1373. X
  1374. X
  1375. X#include "cron.h"
  1376. X
  1377. X
  1378. char **
  1379. env_init()
  1380. X{
  1381. X    extern char    *malloc();
  1382. X    register char    **p = (char **) malloc(sizeof(char **));
  1383. X
  1384. X    p[0] = NULL;
  1385. X    return p;
  1386. X}
  1387. X
  1388. X
  1389. char **
  1390. env_set(envp, envstr)
  1391. X    char    **envp;
  1392. X    char    *envstr;
  1393. X{
  1394. X    extern char    *realloc(), *savestr();
  1395. X    register int    count, found;
  1396. X    register char    **p;
  1397. X
  1398. X    /*
  1399. X     * count the number of elements, including the null pointer;
  1400. X     * also set 'found' to -1 or index of entry if already in here.
  1401. X     */
  1402. X    found = -1;
  1403. X    for (count = 0;  envp[count] != NULL;  count++)
  1404. X    {
  1405. X        if (!strcmp_until(envp[count], envstr, '='))
  1406. X            found = count;
  1407. X    }
  1408. X    count++;        /* for the null pointer
  1409. X                 */
  1410. X
  1411. X    if (found != -1)
  1412. X    {
  1413. X        /*
  1414. X         * it exists already, so just free the existing setting,
  1415. X         * save our new one there, and return the existing array.
  1416. X         */
  1417. X        free(envp[found]);
  1418. X        envp[found] = savestr(envstr);
  1419. X        return envp;
  1420. X    }
  1421. X
  1422. X    /*
  1423. X     * it doesn't exist yet, so resize the array, move null pointer over
  1424. X     * one, save our string over the old null pointer, and return resized
  1425. X     * array.
  1426. X     */
  1427. X    p = (char **) realloc(
  1428. X            (char *)   envp,
  1429. X            (unsigned) ((count+1) * sizeof(char **))
  1430. X    );
  1431. X    p[count] = p[count-1];
  1432. X    p[count-1] = savestr(envstr);
  1433. X    return p;
  1434. X}
  1435. X
  1436. X
  1437. int
  1438. load_env(envstr, f)
  1439. X    char    *envstr;
  1440. X    FILE    *f;
  1441. X{
  1442. X    /* return    ERR = end of file
  1443. X     *        FALSE = not an env setting (file was repositioned)
  1444. X     *        TRUE = was an env setting
  1445. X     */
  1446. X    char    *strcpy(), *sprintf();
  1447. X    long    filepos;
  1448. X    int    fileline;
  1449. X    char    name[MAX_TEMPSTR], val[MAX_ENVSTR];
  1450. X    int    fields, strdtb();
  1451. X    void    skip_comments();
  1452. X
  1453. X    filepos = ftell(f);
  1454. X    fileline = LineNumber;
  1455. X    skip_comments(f);
  1456. X    if (EOF == get_string(envstr, MAX_ENVSTR, f, "\n"))
  1457. X        return ERR;
  1458. X
  1459. X    Debug(DPARS, ("load_env, read <%s>\n", envstr))
  1460. X
  1461. X    name[0] = val[0] = '\0';
  1462. X    fields = sscanf(envstr, "%[^ =] = %[^\n#]", name, val);
  1463. X    if (fields != 2)
  1464. X    {
  1465. X        Debug(DPARS, ("load_env, not 2 fields (%d)\n", fields))
  1466. X        fseek(f, filepos, 0);
  1467. X        Set_LineNum(fileline);
  1468. X        return FALSE;
  1469. X    }
  1470. X
  1471. X    /* 2 fields from scanf; looks like an env setting
  1472. X     */
  1473. X
  1474. X    /*
  1475. X     * process value string
  1476. X     */
  1477. X    {
  1478. X        int    len = strdtb(val);
  1479. X
  1480. X        if (len >= 2)
  1481. X            if (val[0] == '\'' || val[0] == '"')
  1482. X                if (val[len-1] == val[0])
  1483. X                {
  1484. X                    val[len-1] = '\0';
  1485. X                    (void) strcpy(val, val+1);
  1486. X                }
  1487. X    }
  1488. X
  1489. X    (void) sprintf(envstr, "%s=%s", name, val);
  1490. X    Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr))
  1491. X    return TRUE;
  1492. X}
  1493. X
  1494. X
  1495. char *
  1496. env_get(name, envp)
  1497. X    char    *name;
  1498. X    char    **envp;
  1499. X{
  1500. X    char    *index();
  1501. X
  1502. X    for (;  *envp;  envp++)
  1503. X        if (!strcmp_until(*envp, name, '='))
  1504. X            return index(*envp, '=') + 1;
  1505. X    return NULL;
  1506. X}
  1507. END_OF_FILE
  1508. if test 3475 -ne `wc -c <'env.c'`; then
  1509.     echo shar: \"'env.c'\" unpacked with wrong size!
  1510. fi
  1511. # end of 'env.c'
  1512. fi
  1513. if test -f 'job.c' -a "${1}" != "-c" ; then 
  1514.   echo shar: Will not clobber existing file \"'job.c'\"
  1515. else
  1516. echo shar: Extracting \"'job.c'\" \(1722 characters\)
  1517. sed "s/^X//" >'job.c' <<'END_OF_FILE'
  1518. X#if !defined(lint) && !defined(LINT)
  1519. static char rcsid[] = "$Header: job.c,v 1.2 90/07/18 00:23:59 vixie Exp $";
  1520. X#endif
  1521. X
  1522. X/* Copyright 1988,1990 by Paul Vixie
  1523. X * All rights reserved
  1524. X *
  1525. X * Distribute freely, except: don't remove my name from the source or
  1526. X * documentation (don't take credit for my work), mark your changes (don't
  1527. X * get me blamed for your possible bugs), don't alter or remove this
  1528. X * notice.  May be sold if buildable source is provided to buyer.  No
  1529. X * warrantee of any kind, express or implied, is included with this
  1530. X * software; use at your own risk, responsibility for damages (if any) to
  1531. X * anyone resulting from the use of this software rests entirely with the
  1532. X * user.
  1533. X *
  1534. X * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  1535. X * I'll try to keep a version up to date.  I can be reached as follows:
  1536. X * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  1537. X * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  1538. X */
  1539. X
  1540. X
  1541. X#include "cron.h"
  1542. X
  1543. X
  1544. typedef    struct    _job
  1545. X    {
  1546. X        struct _job    *next;
  1547. X        char        *cmd;
  1548. X        user        *u;
  1549. X    }
  1550. X    job;
  1551. X
  1552. X
  1553. static job    *jhead = NULL, *jtail = NULL;
  1554. X
  1555. X
  1556. void
  1557. job_add(cmd, u)
  1558. X    register char *cmd;
  1559. X    register user *u;
  1560. X{
  1561. X    register job *j;
  1562. X
  1563. X    /* if already on queue, keep going */
  1564. X    for (j=jhead; j; j=j->next)
  1565. X        if (j->cmd == cmd && j->u == u) { return; }
  1566. X
  1567. X    /* build a job queue element */
  1568. X    j = (job*)malloc(sizeof(job));
  1569. X    j->next = (job*) NULL;
  1570. X    j->cmd = cmd;
  1571. X    j->u = u;
  1572. X
  1573. X    /* add it to the tail */
  1574. X    if (!jhead) { jhead=j; }
  1575. X    else { jtail->next=j; }
  1576. X    jtail = j;
  1577. X}
  1578. X
  1579. X
  1580. int
  1581. job_runqueue()
  1582. X{
  1583. X    register job    *j;
  1584. X    register int    run = 0;
  1585. X
  1586. X    for (j=jhead; j; j=j->next) {
  1587. X        do_command(j->cmd, j->u);
  1588. X        free(j);
  1589. X        run++;
  1590. X    }
  1591. X    jhead = jtail = NULL;
  1592. X    return run;
  1593. X}
  1594. END_OF_FILE
  1595. if test 1722 -ne `wc -c <'job.c'`; then
  1596.     echo shar: \"'job.c'\" unpacked with wrong size!
  1597. fi
  1598. # end of 'job.c'
  1599. fi
  1600. if test -f 'user.c' -a "${1}" != "-c" ; then 
  1601.   echo shar: Will not clobber existing file \"'user.c'\"
  1602. else
  1603. echo shar: Extracting \"'user.c'\" \(2780 characters\)
  1604. sed "s/^X//" >'user.c' <<'END_OF_FILE'
  1605. X#if !defined(lint) && !defined(LINT)
  1606. static char rcsid[] = "$Header: user.c,v 2.1 90/07/18 00:23:45 vixie Exp $";
  1607. X#endif
  1608. X
  1609. X/* vix 26jan87 [log is in RCS file]
  1610. X */
  1611. X
  1612. X/* Copyright 1988,1990 by Paul Vixie
  1613. X * All rights reserved
  1614. X *
  1615. X * Distribute freely, except: don't remove my name from the source or
  1616. X * documentation (don't take credit for my work), mark your changes (don't
  1617. X * get me blamed for your possible bugs), don't alter or remove this
  1618. X * notice.  May be sold if buildable source is provided to buyer.  No
  1619. X * warrantee of any kind, express or implied, is included with this
  1620. X * software; use at your own risk, responsibility for damages (if any) to
  1621. X * anyone resulting from the use of this software rests entirely with the
  1622. X * user.
  1623. X *
  1624. X * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  1625. X * I'll try to keep a version up to date.  I can be reached as follows:
  1626. X * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  1627. X * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  1628. X */
  1629. X
  1630. X
  1631. X#include "cron.h"
  1632. X
  1633. X
  1634. void
  1635. free_user(u)
  1636. X    user    *u;
  1637. X{
  1638. X    void    free_entry();
  1639. X    int    free();
  1640. X    entry    *e;
  1641. X    char    **env;
  1642. X
  1643. X    for (e = u->crontab;  e != NULL;  e = e->next)
  1644. X        free_entry(e);
  1645. X    for (env = u->envp;  *env;  env++)
  1646. X        (void) free(*env);
  1647. X    (void) free(u->envp);
  1648. X    (void) free(u);
  1649. X}
  1650. X
  1651. X
  1652. user *
  1653. load_user(crontab_fd, name, uid, gid, dir, shell)
  1654. X    int    crontab_fd;
  1655. X    char    *name;
  1656. X    int    uid;
  1657. X    int    gid;
  1658. X    char    *dir;
  1659. X    char    *shell;
  1660. X{
  1661. X    char    *malloc(), *sprintf(), **env_init(), **env_set();
  1662. X    int    load_env();
  1663. X    entry    *load_entry();
  1664. X
  1665. X    char    envstr[MAX_ENVSTR];
  1666. X    FILE    *file;
  1667. X    user    *u;
  1668. X    entry    *e;
  1669. X    int    status;
  1670. X
  1671. X    if (!(file = fdopen(crontab_fd, "r")))
  1672. X    {
  1673. X        perror("fdopen on crontab_fd in load_user");
  1674. X        return NULL;
  1675. X    }
  1676. X
  1677. X    Debug(DPARS, ("load_user()\n"))
  1678. X
  1679. X    /* file is open.  build user entry, then read the crontab file.
  1680. X     */
  1681. X    u = (user *) malloc(sizeof(user));
  1682. X    u->uid     = uid;
  1683. X    u->gid     = gid;
  1684. X    u->envp    = env_init();
  1685. X    u->crontab = NULL;
  1686. X
  1687. X    /*
  1688. X     * do auto env settings that the user could reset in the cron tab
  1689. X     */
  1690. X    sprintf(envstr, "SHELL=%s", (*shell) ?shell :"/bin/sh");
  1691. X    u->envp = env_set(u->envp, envstr);
  1692. X
  1693. X    sprintf(envstr, "HOME=%s", dir);
  1694. X    u->envp = env_set(u->envp, envstr);
  1695. X
  1696. X    /* load the crontab
  1697. X     */
  1698. X    while ((status = load_env(envstr, file)) >= OK)
  1699. X    {
  1700. X        if (status == TRUE)
  1701. X        {
  1702. X            u->envp = env_set(u->envp, envstr);
  1703. X        }
  1704. X        else
  1705. X        {
  1706. X            if (NULL != (e = load_entry(file, NULL)))
  1707. X            {
  1708. X                e->next = u->crontab;
  1709. X                u->crontab = e;
  1710. X            }
  1711. X        }
  1712. X    }
  1713. X
  1714. X    /*
  1715. X     * do automatic env settings that should have precedence over any
  1716. X     * set in the cron tab.
  1717. X     */
  1718. X    (void) sprintf(envstr, "%s=%s", USERENV, name);
  1719. X    u->envp = env_set(u->envp, envstr);
  1720. X
  1721. X    /*
  1722. X     * done. close file, return pointer to 'user' structure
  1723. X     */
  1724. X    fclose(file);
  1725. X
  1726. X    Debug(DPARS, ("...load_user() done\n"))
  1727. X
  1728. X    return u;
  1729. X}
  1730. END_OF_FILE
  1731. if test 2780 -ne `wc -c <'user.c'`; then
  1732.     echo shar: \"'user.c'\" unpacked with wrong size!
  1733. fi
  1734. # end of 'user.c'
  1735. fi
  1736. echo shar: End of archive 1 \(of 3\).
  1737. cp /dev/null ark1isdone
  1738. MISSING=""
  1739. for I in 1 2 3 ; do
  1740.     if test ! -f ark${I}isdone ; then
  1741.     MISSING="${MISSING} ${I}"
  1742.     fi
  1743. done
  1744. if test "${MISSING}" = "" ; then
  1745.     echo You have unpacked all 3 archives.
  1746.     rm -f ark[1-9]isdone
  1747. else
  1748.     echo You still need to unpack the following archives:
  1749.     echo "        " ${MISSING}
  1750. fi
  1751. ##  End of shell archive.
  1752. exit 0
  1753.  
  1754. exit 0 # Just in case...
  1755.