1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-14 10:09:48 +00:00

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

This commit is contained in:
Philippe Charnier 1997-09-15 06:39:25 +00:00
parent d58316915f
commit 401e64688b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=29452
14 changed files with 352 additions and 348 deletions

View File

@ -15,47 +15,61 @@
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $Id$
.\" $Id: cron.8,v 1.4 1997/02/22 16:04:39 peter Exp $
.\"
.TH CRON 8 "20 December 1993"
.UC 4
.SH NAME
cron \- daemon to execute scheduled commands (Vixie Cron)
.SH SYNOPSIS
.B cron [-x debugflag[,...]]
.SH DESCRIPTION
.I Cron
should be started from /etc/rc or /etc/rc.local. It will return immediately,
.Dd December 20, 1993
.Dt CRON 8
.Os
.Sh NAME
.Nm cron
.Nd daemon to execute scheduled commands (Vixie Cron)
.Sh SYNOPSIS
.Nm cron
.Op Fl x Ar debugflag Ns Op ,...
.Sh DESCRIPTION
.Nm Cron
should be started from
.Pa /etc/rc
or
.Pa /etc/rc.local .
It will return immediately,
so you don't need to start it with '&'.
.PP
.I Cron
searches /var/cron/tabs for crontab files which are named after accounts in
/etc/passwd; crontabs found are loaded into memory.
.I Cron
also searches for /etc/crontab which is in a different format (see
.IR crontab(5)).
.I Cron
.Pp
.Nm Cron
searches
.Pa /var/cron/tabs
for crontab files which are named after accounts in
.Pa /etc/passwd ;
crontabs found are loaded into memory.
.Nm Cron
also searches for
.Pa /etc/crontab
which is in a different format (see
.Xr crontab 5 ).
.Nm Cron
then wakes up every minute, examining all stored crontabs, checking each
command to see if it should be run in the current minute. When executing
commands, any output is mailed to the owner of the crontab (or to the user
named in the MAILTO environment variable in the crontab, if such exists).
.PP
named in the
.Ev MAILTO
environment variable in the crontab, if such exists).
.Pp
Additionally,
.I cron
.Nm
checks each minute to see if its spool directory's modtime (or the modtime
on
.IR /etc/crontab)
.Pa /etc/crontab )
has changed, and if it has,
.I cron
.Nm
will then examine the modtime on all crontabs and reload those which have
changed. Thus
.I cron
.Nm
need not be restarted whenever a crontab file is modified. Note that the
.IR Crontab (1)
.Xr crontab 1
command updates the modtime of the spool directory whenever it changes a
crontab.
.SH "SEE ALSO"
crontab(1), crontab(5)
.SH AUTHOR
.nf
Paul Vixie <paul@vix.com>
.Sh SEE ALSO
.Xr crontab 1 ,
.Xr crontab 5
.Sh AUTHOR
.An Paul Vixie Aq paul@vix.com

View File

@ -16,10 +16,10 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: cron.c,v 1.4 1997/02/22 16:04:40 peter Exp $";
static const char rcsid[] =
"$Id: cron.c,v 1.5 1997/03/31 05:09:54 imp Exp $";
#endif
#define MAIN_PROGRAM
@ -48,7 +48,7 @@ static void
usage() {
char **dflags;
fprintf(stderr, "usage: %s [-x debugflag[,...]]\n", ProgramName);
fprintf(stderr, "usage: cron [-x debugflag[,...]]\n");
fprintf(stderr, "\ndebugflags: ");
for(dflags = DebugFlagNames; *dflags; dflags++) {

View File

@ -17,7 +17,7 @@
/* cron.h - header for vixie's cron
*
* $Id$
* $Id: cron.h,v 1.6 1997/02/22 16:04:41 peter Exp $
*
* vix 14nov88 [rest of log is in RCS]
* vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley]
@ -30,14 +30,15 @@
#include <sys/param.h>
#include "compat.h"
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <bitstring.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <pwd.h>
#include <sys/wait.h>
#include <time.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <sys/wait.h>
#include "pathnames.h"
#include "config.h"

View File

@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id$";
static const char rcsid[] =
"$Id: database.c,v 1.6 1997/02/22 16:04:42 peter Exp $";
#endif
/* vix 26jan87 [RCS has the log]

View File

@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: do_command.c,v 1.11 1997/03/14 13:48:04 peter Exp $";
static const char rcsid[] =
"$Id: do_command.c,v 1.12 1997/03/14 14:45:30 peter Exp $";
#endif
@ -136,7 +137,7 @@ child_process(e, u)
register int ch;
register char *p;
for (input_data = p = e->cmd; ch = *input_data;
for (input_data = p = e->cmd; (ch = *input_data);
input_data++, p++) {
if (p != input_data)
*p = ch;
@ -260,8 +261,7 @@ child_process(e, u)
}
# endif /*DEBUGGING*/
execle(shell, shell, "-c", e->cmd, (char *)0, e->envp);
fprintf(stderr, "execl: couldn't exec `%s'\n", shell);
perror("execl");
warn("execl: couldn't exec `%s'", shell);
_exit(ERROR_EXIT);
}
break;
@ -313,7 +313,7 @@ child_process(e, u)
* % -> \n
* \x -> \x for all x != %
*/
while (ch = *input_data++) {
while ((ch = *input_data++)) {
if (escaped) {
if (ch != '%')
putc('\\', out);
@ -401,7 +401,7 @@ child_process(e, u)
(void) snprintf(mailcmd, sizeof(mailcmd),
MAILARGS, MAILCMD);
if (!(mail = cron_popen(mailcmd, "w"))) {
perror(MAILCMD);
warn("%s", MAILCMD);
(void) _exit(ERROR_EXIT);
}
fprintf(mail, "From: root (Cron Daemon)\n");

View File

@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id$";
static const char rcsid[] =
"$Id: job.c,v 1.4 1997/02/22 16:04:44 peter Exp $";
#endif

View File

@ -24,8 +24,11 @@
*/
#ifndef lint
static char rcsid[] = "$Id$";
#if 0
static char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include "cron.h"
@ -59,7 +62,7 @@ cron_popen(program, type)
extern char **glob(), **copyblk();
#endif
if (*type != 'r' && *type != 'w' || type[1])
if ((*type != 'r' && *type != 'w') || type[1])
return(NULL);
if (!pids) {

View File

@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id$";
static const char rcsid[] =
"$Id: user.c,v 1.5 1997/02/22 16:04:47 peter Exp $";
#endif
/* vix 26jan87 [log is in RCS file]
@ -55,7 +56,7 @@ load_user(crontab_fd, pw, name)
char **envp, **tenvp;
if (!(file = fdopen(crontab_fd, "r"))) {
perror("fdopen on crontab_fd in load_user");
warn("fdopen on crontab_fd in load_user");
return NULL;
}

View File

@ -15,86 +15,101 @@
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $Id$
.\" $Id: crontab.1,v 1.3 1997/02/22 16:04:51 peter Exp $
.\"
.TH CRONTAB 1 "29 December 1993"
.UC 4
.SH NAME
crontab \- maintain crontab files for individual users (V3)
.SH SYNOPSIS
crontab [ -u user ] file
.br
crontab [ -u user ] { -l | -r | -e }
.SH DESCRIPTION
.I Crontab
.Dd December 29, 1993
.Dt CRONTAB 1
.Os
.Sh NAME
.Nm crontab
.Nd maintain crontab files for individual users (V3)
.Sh SYNOPSIS
.Nm crontab
.Op Fl u Ar user
.Ar file
.Nm crontab
.Op Fl u Ar user
{
.Fl l |
.Fl r |
.Fl e
}
.Sh DESCRIPTION
.Nm Crontab
is the program used to install, deinstall or list the tables
used to drive the
.IR cron (8)
.Xr cron 8
daemon in Vixie Cron. Each user can have their own crontab, and though
these are files in /var, they are not intended to be edited directly.
.PP
these are files in
.Pa /var ,
they are not intended to be edited directly.
.Pp
If the
.I allow
.Pa allow
file exists, then you must be listed therein in order to be allowed to use
this command. If the
.I allow
.Pa allow
file does not exist but the
.I deny
file does exist, then you must \fBnot\fR be listed in the
.I deny
.Pa deny
file does exist, then you must
.Em not
be listed in the
.Pa deny
file in order to use this command. If neither of these files exists, then
depending on site-dependent configuration parameters, only the super user
will be allowed to use this command, or all users will be able to use this
command.
.PP
If the
.I -u
option is given, it specifies the name of the user whose crontab is to be
tweaked. If this option is not given,
.I crontab
examines "your" crontab, i.e., the crontab of the person executing the
command. Note that
.IR su (8)
can confuse
.I crontab
and that if you are running inside of
.IR su (8)
you should always use the
.I -u
option for safety's sake.
.PP
.Pp
The first form of this command is used to install a new crontab from some
named file or standard input if the pseudo-filename ``-'' is given.
.PP
The
.I -l
option causes the current crontab to be displayed on standard output.
.PP
The
.I -r
option causes the current crontab to be removed.
.PP
The
.I -e
option is used to edit the current crontab using the editor specified by
the \s-1VISUAL\s+1 or \s-1EDITOR\s+1 environment variables. After you exit
.Pp
The following options are available:
.Bl -tag -width indent
.It Fl u
Specify the name of the user whose crontab is to be
tweaked. If this option is not given,
.Nm
examines "your" crontab, i.e., the crontab of the person executing the
command. Note that
.Xr su 8
can confuse
.Nm
and that if you are running inside of
.Xr su 8
you should always use the
.Fl u
option for safety's sake.
.It Fl l
Display the current crontab on standard output.
.It Fl r
Remove the current crontab.
.It Fl e
Edit the current crontab using the editor specified by
the
.Ev VISUAL
or
.Ev EDITOR
environment variables. After you exit
from the editor, the modified crontab will be installed automatically.
.SH "SEE ALSO"
crontab(5), cron(8)
.SH FILES
.nf
/var/cron/allow
/var/cron/deny
.fi
.SH STANDARDS
.El
.Sh SEE ALSO
.Xr crontab 5 ,
.Xr cron 8
.Sh FILES
.Bl -tag -width /var/cron/allow -compact
.It Pa /var/cron/allow
.It Pa /var/cron/deny
.El
.Sh STANDARDS
The
.I crontab
command conforms to IEEE Std1003.2-1992 (``POSIX''). This new command syntax
.Nm
command conforms to
.St -p1003.2 .
This new command syntax
differs from previous versions of Vixie Cron, as well as from the classic
SVR3 syntax.
.SH DIAGNOSTICS
.Sh DIAGNOSTICS
A fairly informative usage message appears if you run it with a bad command
line.
.SH AUTHOR
.nf
Paul Vixie <paul@vix.com>
.Sh AUTHOR
.An Paul Vixie Aq paul@vix.com

View File

@ -15,105 +15,135 @@
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $Id$
.\" $Id: crontab.5,v 1.4 1997/02/22 16:04:52 peter Exp $
.\"
.TH CRONTAB 5 "24 January 1994"
.UC 4
.SH NAME
crontab \- tables for driving cron
.SH DESCRIPTION
.Dd January 24, 1994
.Dt CRONTAB 5
.Os
.Sh NAME
.Nm crontab
.Nd tables for driving cron
.Sh DESCRIPTION
A
.I crontab
.Nm
file contains instructions to the
.IR cron (8)
.Xr cron 8
daemon of the general form: ``run this command at this time on this date''.
Each user has their own crontab, and commands in any given crontab will be
executed as the user who owns the crontab. Uucp and News will usually have
their own crontabs, eliminating the need for explicitly running
.IR su (1)
.Xr su 1
as part of a cron command.
.PP
.Pp
Blank lines and leading spaces and tabs are ignored. Lines whose first
non-space character is a pound-sign (#) are comments, and are ignored.
Note that comments are not allowed on the same line as cron commands, since
they will be taken to be part of the command. Similarly, comments are not
allowed on the same line as environment variable settings.
.PP
.Pp
An active line in a crontab will be either an environment setting or a cron
command. An environment setting is of the form,
.PP
.Pp
name = value
.PP
.Pp
where the spaces around the equal-sign (=) are optional, and any subsequent
non-leading spaces in
.I value
.Em value
will be part of the value assigned to
.IR name .
.Em name .
The
.I value
.Em value
string may be placed in quotes (single or double, but matching) to preserve
leading or trailing blanks.
.PP
.Pp
Several environment variables are set up
automatically by the
.IR cron (8)
.Xr cron 8
daemon.
SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd
.Ev SHELL
is set to
.Pa /bin/sh ,
and
.Ev LOGNAME
and
.Ev HOME
are set from the
.Pa /etc/passwd
line of the crontab's owner.
HOME and SHELL may be overridden by settings in the crontab; LOGNAME may not.
.PP
(Another note: the LOGNAME variable is sometimes called USER on BSD systems...
on these systems, USER will be set also.)
.PP
In addition to LOGNAME, HOME, and SHELL,
.IR cron (8)
will look at MAILTO if it has any reason to send mail as a result of running
commands in ``this'' crontab. If MAILTO is defined (and non-empty), mail is
sent to the user so named. If MAILTO is defined but empty (MAILTO=""), no
.Ev HOME
and
.Ev SHELL
may be overridden by settings in the crontab;
.Ev LOGNAME
may not.
.Pp
(Another note: the
.Ev LOGNAME
variable is sometimes called
.Ev USER
on BSD systems...
on these systems,
.Ev USER
will be set also).
.Pp
In addition to
.Ev LOGNAME ,
.Ev HOME ,
and
.Ev SHELL ,
.Xr cron 8
will look at
.Ev MAILTO
if it has any reason to send mail as a result of running
commands in ``this'' crontab. If
.Ev MAILTO
is defined (and non-empty), mail is
sent to the user so named. If
.Ev MAILTO
is defined but empty (MAILTO=""), no
mail will be sent. Otherwise mail is sent to the owner of the crontab. This
option is useful if you decide on /bin/mail instead of /usr/lib/sendmail as
your mailer when you install cron -- /bin/mail doesn't do aliasing, and UUCP
option is useful if you decide on
.Pa /bin/mail
instead of
.Pa /usr/lib/sendmail
as
your mailer when you install cron --
.Pa /bin/mail
doesn't do aliasing, and UUCP
usually doesn't read its mail.
.PP
.Pp
The format of a cron command is very much the V7 standard, with a number of
upward-compatible extensions. Each line has five time and date fields,
followed by a user name if this is the system crontab file,
followed by a command. Commands are executed by
.IR cron (8)
.Xr cron 8
when the minute, hour, and month of year fields match the current time,
.I and
.Em and
when at least one of the two day fields (day of month, or day of week)
match the current time (see ``Note'' below).
.IR cron (8)
.Xr cron 8
examines cron entries once every minute.
The time and date fields are:
.IP
.ta 1.5i
field allowed values
.br
----- --------------
.br
minute 0-59
.br
hour 0-23
.br
day of month 1-31
.br
month 1-12 (or names, see below)
.br
day of week 0-7 (0 or 7 is Sun, or use names)
.br
.PP
.Bd -literal -offset indent
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
.Ed
.Pp
A field may be an asterisk (*), which always stands for ``first\-last''.
.PP
.Pp
Ranges of numbers are allowed. Ranges are two numbers separated
with a hyphen. The specified range is inclusive. For example,
8-11 for an ``hours'' entry specifies execution at hours 8, 9, 10
and 11.
.PP
.Pp
Lists are allowed. A list is a set of numbers (or ranges)
separated by commas. Examples: ``1,2,5,9'', ``0-4,8-12''.
.PP
.Pp
Step values can be used in conjunction with ranges. Following
a range with ``/<number>'' specifies skips of the number's value
through the range. For example, ``0-23/2'' can be used in the hours
@ -121,33 +151,37 @@ field to specify command execution every other hour (the alternative
in the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22''). Steps are
also permitted after an asterisk, so if you want to say ``every two
hours'', just use ``*/2''.
.PP
.Pp
Names can also be used for the ``month'' and ``day of week''
fields. Use the first three letters of the particular
day or month (case doesn't matter). Ranges or
lists of names are not allowed.
.PP
.Pp
The ``sixth'' field (the rest of the line) specifies the command to be
run.
The entire command portion of the line, up to a newline or %
character, will be executed by /bin/sh or by the shell
specified in the SHELL variable of the cronfile.
character, will be executed by
.Pa /bin/sh
or by the shell
specified in the
.Ev SHELL
variable of the cronfile.
Percent-signs (%) in the command, unless escaped with backslash
(\\), will be changed into newline characters, and all data
after the first % will be sent to the command as standard
input.
.PP
.Pp
Note: The day of a command's execution can be specified by two
fields \(em day of month, and day of week. If both fields are
restricted (ie, aren't *), the command will be run when
.I either
.Em either
field matches the current time. For example,
.br
``30 4 1,15 * 5''
would cause a command to be run at 4:30 am on the 1st and 15th of each
month, plus every Friday.
.SH EXAMPLE CRON FILE
.nf
.Sh EXAMPLE CRON FILE
.Bd -literal
# use /bin/sh to run commands, no matter what /etc/passwd says
SHELL=/bin/sh
@ -162,27 +196,28 @@ MAILTO=paul
0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every sunday"
.fi
.SH SEE ALSO
cron(8), crontab(1)
.SH EXTENSIONS
.Ed
.Sh SEE ALSO
.Xr cron 8 ,
.Xr crontab 1
.Sh EXTENSIONS
When specifying day of week, both day 0 and day 7 will be considered Sunday.
BSD and ATT seem to disagree about this.
.PP
.Pp
Lists and ranges are allowed to co-exist in the same field. "1-3,7-9" would
be rejected by ATT or BSD cron -- they want to see "1-3" or "7,8,9" ONLY.
.PP
.Pp
Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
.PP
.Pp
Names of months or days of the week can be specified by name.
.PP
.Pp
Environment variables can be set in the crontab. In BSD or ATT, the
environment handed to child processes is basically the one from /etc/rc.
.PP
environment handed to child processes is basically the one from
.Pa /etc/rc .
.Pp
Command output is mailed to the crontab owner (BSD can't do this), can be
mailed to a person other than the crontab owner (SysV can't do this), or the
feature can be turned off and no mail will be sent at all (SysV can't do this
either).
.SH AUTHOR
.nf
Paul Vixie <paul@vix.com>
.Sh AUTHOR
.An Paul Vixie Aq paul@vix.com

View File

@ -17,7 +17,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: crontab.c,v 1.9 1997/02/22 16:04:53 peter Exp $";
static const char rcsid[] =
"$Id: crontab.c,v 1.10 1997/03/31 05:09:58 imp Exp $";
#endif
/* crontab - install and manage per-user crontab files
@ -73,13 +74,10 @@ static void
usage(msg)
char *msg;
{
fprintf(stderr, "%s: usage error: %s\n", ProgramName, msg);
fprintf(stderr, "usage:\t%s [-u user] file\n", ProgramName);
fprintf(stderr, "\t%s [-u user] { -e | -l | -r }\n", ProgramName);
fprintf(stderr, "\t\t(default operation is replace, per 1003.2)\n");
fprintf(stderr, "\t-e\t(edit user's crontab)\n");
fprintf(stderr, "\t-l\t(list user's crontab)\n");
fprintf(stderr, "\t-r\t(delete user's crontab)\n");
fprintf(stderr, "crontab: usage error: %s\n", msg);
fprintf(stderr, "%s\n%s\n",
"usage: crontab [-u user] file",
" crontab [-u user] { -e | -l | -r }");
exit(ERROR_EXIT);
}
@ -105,10 +103,7 @@ main(argc, argv)
set_cron_uid();
set_cron_cwd();
if (!allowed(User)) {
fprintf(stderr,
"You (%s) are not allowed to use this program (%s)\n",
User, ProgramName);
fprintf(stderr, "See crontab(1) for more information\n");
warnx("you (%s) are not allowed to use this program", User);
log_it(RealUser, Pid, "AUTH", "crontab command not allowed");
exit(ERROR_EXIT);
}
@ -123,6 +118,8 @@ main(argc, argv)
case opt_replace: if (replace_cmd() < 0)
exitstatus = ERROR_EXIT;
break;
case opt_unknown:
break;
}
exit(0);
/*NOTREACHED*/
@ -136,12 +133,8 @@ parse_args(argc, argv)
{
int argch;
if (!(pw = getpwuid(getuid()))) {
fprintf(stderr, "%s: your UID isn't in the passwd file.\n",
ProgramName);
fprintf(stderr, "bailing out.\n");
exit(ERROR_EXIT);
}
if (!(pw = getpwuid(getuid())))
errx(ERROR_EXIT, "your UID isn't in the passwd file, bailing out");
(void) strncpy(User, pw->pw_name, (sizeof User)-1);
User[(sizeof User)-1] = '\0';
strcpy(RealUser, User);
@ -155,17 +148,9 @@ parse_args(argc, argv)
break;
case 'u':
if (getuid() != ROOT_UID)
{
fprintf(stderr,
"must be privileged to use -u\n");
exit(ERROR_EXIT);
}
errx(ERROR_EXIT, "must be privileged to use -u");
if (!(pw = getpwnam(optarg)))
{
fprintf(stderr, "%s: user `%s' unknown\n",
ProgramName, optarg);
exit(ERROR_EXIT);
}
errx(ERROR_EXIT, "user `%s' unknown", optarg);
(void) strncpy(User, pw->pw_name, (sizeof User)-1);
User[(sizeof User)-1] = '\0';
break;
@ -222,18 +207,12 @@ parse_args(argc, argv)
* the race.
*/
if (swap_uids() < OK) {
perror("swapping uids");
exit(ERROR_EXIT);
}
if (!(NewCrontab = fopen(Filename, "r"))) {
perror(Filename);
exit(ERROR_EXIT);
}
if (swap_uids() < OK) {
perror("swapping uids back");
exit(ERROR_EXIT);
}
if (swap_uids() < OK)
err(ERROR_EXIT, "swapping uids");
if (!(NewCrontab = fopen(Filename, "r")))
err(ERROR_EXIT, "%s", Filename);
if (swap_uids() < OK)
err(ERROR_EXIT, "swapping uids back");
}
}
@ -252,10 +231,9 @@ list_cmd() {
(void) sprintf(n, CRON_TAB(User));
if (!(f = fopen(n, "r"))) {
if (errno == ENOENT)
fprintf(stderr, "no crontab for %s\n", User);
errx(ERROR_EXIT, "no crontab for %s", User);
else
perror(n);
exit(ERROR_EXIT);
err(ERROR_EXIT, "%s", n);
}
/* file is open. copy to stdout, close.
@ -275,10 +253,9 @@ delete_cmd() {
(void) sprintf(n, CRON_TAB(User));
if (unlink(n)) {
if (errno == ENOENT)
fprintf(stderr, "no crontab for %s\n", User);
errx(ERROR_EXIT, "no crontab for %s", User);
else
perror(n);
exit(ERROR_EXIT);
err(ERROR_EXIT, "%s", n);
}
poke_daemon();
}
@ -307,22 +284,17 @@ edit_cmd() {
log_it(RealUser, Pid, "BEGIN EDIT", User);
(void) sprintf(n, CRON_TAB(User));
if (!(f = fopen(n, "r"))) {
if (errno != ENOENT) {
perror(n);
exit(ERROR_EXIT);
}
fprintf(stderr, "no crontab for %s - using an empty one\n",
User);
if (!(f = fopen("/dev/null", "r"))) {
perror("/dev/null");
exit(ERROR_EXIT);
}
if (errno != ENOENT)
err(ERROR_EXIT, "%s", n);
warnx("no crontab for %s - using an empty one", User);
if (!(f = fopen("/dev/null", "r")))
err(ERROR_EXIT, "/dev/null");
}
um = umask(077);
(void) sprintf(Filename, "/tmp/crontab.XXXXXXXXXX");
if ((t = mkstemp(Filename)) == -1) {
perror(Filename);
warn("%s", Filename);
(void) umask(um);
goto fatal;
}
@ -332,11 +304,11 @@ edit_cmd() {
#else
if (chown(Filename, getuid(), getgid()) < 0) {
#endif
perror("fchown");
warn("fchown");
goto fatal;
}
if (!(NewCrontab = fdopen(t, "w"))) {
perror("fdopen");
warn("fdopen");
goto fatal;
}
@ -365,13 +337,11 @@ edit_cmd() {
while (EOF != (ch = get_char(f)))
putc(ch, NewCrontab);
fclose(f);
if (fclose(NewCrontab)) {
perror(Filename);
exit(ERROR_EXIT);
}
if (fclose(NewCrontab))
err(ERROR_EXIT, "%s", Filename);
again:
if (stat(Filename, &statbuf) < 0) {
perror("stat");
warn("stat");
fatal: unlink(Filename);
exit(ERROR_EXIT);
}
@ -393,26 +363,18 @@ edit_cmd() {
switch (pid = fork()) {
case -1:
perror("fork");
warn("fork");
goto fatal;
case 0:
/* child */
if (setuid(getuid()) < 0) {
perror("setuid(getuid())");
exit(ERROR_EXIT);
}
if (chdir("/tmp") < 0) {
perror("chdir(/tmp)");
exit(ERROR_EXIT);
}
if (strlen(editor) + strlen(Filename) + 2 >= MAX_TEMPSTR) {
fprintf(stderr, "%s: editor or filename too long\n",
ProgramName);
exit(ERROR_EXIT);
}
if (setuid(getuid()) < 0)
err(ERROR_EXIT, "setuid(getuid())");
if (chdir("/tmp") < 0)
err(ERROR_EXIT, "chdir(/tmp)");
if (strlen(editor) + strlen(Filename) + 2 >= MAX_TEMPSTR)
errx(ERROR_EXIT, "editor or filename too long");
execlp(editor, editor, Filename, NULL);
perror(editor);
exit(ERROR_EXIT);
err(ERROR_EXIT, "%s", editor);
/*NOTREACHED*/
default:
/* parent */
@ -431,34 +393,29 @@ edit_cmd() {
signal(SIGTERM, f[2]);
}
if (xpid != pid) {
fprintf(stderr, "%s: wrong PID (%d != %d) from \"%s\"\n",
ProgramName, xpid, pid, editor);
warnx("wrong PID (%d != %d) from \"%s\"", xpid, pid, editor);
goto fatal;
}
if (WIFEXITED(waiter) && WEXITSTATUS(waiter)) {
fprintf(stderr, "%s: \"%s\" exited with status %d\n",
ProgramName, editor, WEXITSTATUS(waiter));
warnx("\"%s\" exited with status %d", editor, WEXITSTATUS(waiter));
goto fatal;
}
if (WIFSIGNALED(waiter)) {
fprintf(stderr,
"%s: \"%s\" killed; signal %d (%score dumped)\n",
ProgramName, editor, WTERMSIG(waiter),
WCOREDUMP(waiter) ?"" :"no ");
warnx("\"%s\" killed; signal %d (%score dumped)",
editor, WTERMSIG(waiter), WCOREDUMP(waiter) ?"" :"no ");
goto fatal;
}
if (stat(Filename, &statbuf) < 0) {
perror("stat");
warn("stat");
goto fatal;
}
if (mtime == statbuf.st_mtime) {
fprintf(stderr, "%s: no changes made to crontab\n",
ProgramName);
warnx("no changes made to crontab");
goto remove;
}
fprintf(stderr, "%s: installing new crontab\n", ProgramName);
warnx("installing new crontab");
if (!(NewCrontab = fopen(Filename, "r"))) {
perror(Filename);
warn("%s", Filename);
goto fatal;
}
switch (replace_cmd()) {
@ -482,12 +439,10 @@ edit_cmd() {
/*NOTREACHED*/
case -2:
abandon:
fprintf(stderr, "%s: edits left in %s\n",
ProgramName, Filename);
warnx("edits left in %s", Filename);
goto done;
default:
fprintf(stderr, "%s: panic: bad switch() in replace_cmd()\n",
ProgramName);
warnx("panic: bad switch() in replace_cmd()");
goto fatal;
}
remove:
@ -511,14 +466,14 @@ replace_cmd() {
char **envp = env_init();
if (envp == NULL) {
fprintf(stderr, "%s: Cannot allocate memory.\n", ProgramName);
warnx("cannot allocate memory");
return (-2);
}
(void) sprintf(n, "tmp.%d", Pid);
(void) sprintf(tn, CRON_TAB(n));
if (!(tmp = fopen(tn, "w+"))) {
perror(tn);
warn("%s", tn);
return (-2);
}
@ -540,8 +495,7 @@ replace_cmd() {
fflush(tmp); rewind(tmp);
if (ferror(tmp)) {
fprintf(stderr, "%s: error while writing new crontab to %s\n",
ProgramName, tn);
warnx("error while writing new crontab to %s", tn);
fclose(tmp); unlink(tn);
return (-2);
}
@ -571,7 +525,7 @@ replace_cmd() {
}
if (CheckErrorCount != 0) {
fprintf(stderr, "errors in crontab file, can't install.\n");
warnx("errors in crontab file, can't install");
fclose(tmp); unlink(tn);
return (-1);
}
@ -582,7 +536,7 @@ replace_cmd() {
if (chown(tn, ROOT_UID, -1) < OK)
#endif
{
perror("chown");
warn("chown");
fclose(tmp); unlink(tn);
return (-2);
}
@ -593,22 +547,20 @@ replace_cmd() {
if (chmod(tn, 0600) < OK)
#endif
{
perror("chown");
warn("chown");
fclose(tmp); unlink(tn);
return (-2);
}
if (fclose(tmp) == EOF) {
perror("fclose");
warn("fclose");
unlink(tn);
return (-2);
}
(void) sprintf(n, CRON_TAB(User));
if (rename(tn, n)) {
fprintf(stderr, "%s: error renaming %s to %s\n",
ProgramName, tn, n);
perror("rename");
warn("error renaming %s to %s", tn, n);
unlink(tn);
return (-2);
}
@ -629,14 +581,12 @@ poke_daemon() {
(void) gettimeofday(&tvs[0], &tz);
tvs[1] = tvs[0];
if (utimes(SPOOL_DIR, tvs) < OK) {
fprintf(stderr, "crontab: can't update mtime on spooldir\n");
perror(SPOOL_DIR);
warn("can't update mtime on spooldir %s", SPOOL_DIR);
return;
}
#else
if (utime(SPOOL_DIR, NULL) < OK) {
fprintf(stderr, "crontab: can't update mtime on spooldir\n");
perror(SPOOL_DIR);
warn("can't update mtime on spooldir %s", SPOOL_DIR);
return;
}
#endif /*USE_UTIMES*/

View File

@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id$";
static const char rcsid[] =
"$Id: entry.c,v 1.6 1997/02/22 16:05:06 peter Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]

View File

@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id$";
static const char rcsid[] =
"$Id: env.c,v 1.5 1997/02/22 16:05:07 peter Exp $";
#endif
@ -192,7 +193,7 @@ env_get(name, envp)
register int len = strlen(name);
register char *p, *q;
while (p = *envp++) {
while ((p = *envp++)) {
if (!(q = strchr(p, '=')))
continue;
if ((q - p) == len && !strncmp(p, name, len))

View File

@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id$";
static const char rcsid[] =
"$Id: misc.c,v 1.5 1997/02/22 16:05:08 peter Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
@ -32,6 +33,7 @@ static char rcsid[] = "$Id$";
#endif
#include <sys/file.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
@ -174,15 +176,11 @@ void
set_cron_uid()
{
#if defined(BSD) || defined(POSIX)
if (seteuid(ROOT_UID) < OK) {
perror("seteuid");
exit(ERROR_EXIT);
}
if (seteuid(ROOT_UID) < OK)
err(ERROR_EXIT, "seteuid");
#else
if (setuid(ROOT_UID) < OK) {
perror("setuid");
exit(ERROR_EXIT);
}
if (setuid(ROOT_UID) < OK)
err(ERROR_EXIT, "setuid");
#endif
}
@ -195,45 +193,32 @@ set_cron_cwd()
/* first check for CRONDIR ("/var/cron" or some such)
*/
if (stat(CRONDIR, &sb) < OK && errno == ENOENT) {
perror(CRONDIR);
warn("%s", CRONDIR);
if (OK == mkdir(CRONDIR, 0700)) {
fprintf(stderr, "%s: created\n", CRONDIR);
warnx("%s: created", CRONDIR);
stat(CRONDIR, &sb);
} else {
fprintf(stderr, "%s: ", CRONDIR);
perror("mkdir");
exit(ERROR_EXIT);
err(ERROR_EXIT, "%s: mkdir", CRONDIR);
}
}
if (!(sb.st_mode & S_IFDIR)) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
CRONDIR);
exit(ERROR_EXIT);
}
if (chdir(CRONDIR) < OK) {
fprintf(stderr, "cannot chdir(%s), bailing out.\n", CRONDIR);
perror(CRONDIR);
exit(ERROR_EXIT);
}
if (!(sb.st_mode & S_IFDIR))
err(ERROR_EXIT, "'%s' is not a directory, bailing out", CRONDIR);
if (chdir(CRONDIR) < OK)
err(ERROR_EXIT, "cannot chdir(%s), bailing out", CRONDIR);
/* CRONDIR okay (now==CWD), now look at SPOOL_DIR ("tabs" or some such)
*/
if (stat(SPOOL_DIR, &sb) < OK && errno == ENOENT) {
perror(SPOOL_DIR);
warn("%s", SPOOL_DIR);
if (OK == mkdir(SPOOL_DIR, 0700)) {
fprintf(stderr, "%s: created\n", SPOOL_DIR);
warnx("%s: created", SPOOL_DIR);
stat(SPOOL_DIR, &sb);
} else {
fprintf(stderr, "%s: ", SPOOL_DIR);
perror("mkdir");
exit(ERROR_EXIT);
err(ERROR_EXIT, "%s: mkdir", SPOOL_DIR);
}
}
if (!(sb.st_mode & S_IFDIR)) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
SPOOL_DIR);
exit(ERROR_EXIT);
}
if (!(sb.st_mode & S_IFDIR))
err(ERROR_EXIT, "'%s' is not a directory, bailing out", SPOOL_DIR);
}
@ -269,9 +254,8 @@ acquire_daemonlock(closeflag)
) {
sprintf(buf, "can't open or create %s: %s",
pidfile, strerror(errno));
fprintf(stderr, "%s: %s\n", ProgramName, buf);
log_it("CRON", getpid(), "DEATH", buf);
exit(ERROR_EXIT);
errx(ERROR_EXIT, "%s", buf);
}
if (flock(fd, LOCK_EX|LOCK_NB) < OK) {
@ -280,9 +264,8 @@ acquire_daemonlock(closeflag)
fscanf(fp, "%d", &otherpid);
sprintf(buf, "can't lock %s, otherpid may be %d: %s",
pidfile, otherpid, strerror(save_errno));
fprintf(stderr, "%s: %s\n", ProgramName, buf);
log_it("CRON", getpid(), "DEATH", buf);
exit(ERROR_EXIT);
errx(ERROR_EXIT, "%s", buf);
}
(void) fcntl(fd, F_SETFD, 1);
@ -483,9 +466,7 @@ log_it(username, xpid, event, detail)
if (LogFD < OK) {
LogFD = open(LOG_FILE, O_WRONLY|O_APPEND|O_CREAT, 0600);
if (LogFD < OK) {
fprintf(stderr, "%s: can't open log file\n",
ProgramName);
perror(LOG_FILE);
warn("can't open log file %s", LOG_FILE);
} else {
(void) fcntl(LogFD, F_SETFD, 1);
}
@ -504,8 +485,8 @@ log_it(username, xpid, event, detail)
*/
if (LogFD < OK || write(LogFD, msg, strlen(msg)) < OK) {
if (LogFD >= OK)
perror(LOG_FILE);
fprintf(stderr, "%s: can't write to log file\n", ProgramName);
warn("%s", LOG_FILE);
warnx("can't write to log file");
write(STDERR, msg, strlen(msg));
}