summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron/crontab
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-09-15 06:39:25 +0000
committercharnier <charnier@FreeBSD.org>1997-09-15 06:39:25 +0000
commitbdee4a3e4bcaeb996f0a5f6081f49d2b42cd0001 (patch)
tree62741259da03c9d124c89e3590b84512939c0733 /usr.sbin/cron/crontab
parentb8c46235c5b5fcd433f224674a9be99e69acc8ee (diff)
downloadFreeBSD-src-bdee4a3e4bcaeb996f0a5f6081f49d2b42cd0001.zip
FreeBSD-src-bdee4a3e4bcaeb996f0a5f6081f49d2b42cd0001.tar.gz
Use err(3). Rewrote man page in mdoc format.
Diffstat (limited to 'usr.sbin/cron/crontab')
-rw-r--r--usr.sbin/cron/crontab/crontab.1131
-rw-r--r--usr.sbin/cron/crontab/crontab.5187
-rw-r--r--usr.sbin/cron/crontab/crontab.c174
3 files changed, 246 insertions, 246 deletions
diff --git a/usr.sbin/cron/crontab/crontab.1 b/usr.sbin/cron/crontab/crontab.1
index d83aa38..9d13f4b 100644
--- a/usr.sbin/cron/crontab/crontab.1
+++ b/usr.sbin/cron/crontab/crontab.1
@@ -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
+.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 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,
-.I crontab
+.Nm
examines "your" crontab, i.e., the crontab of the person executing the
command. Note that
-.IR su (8)
+.Xr su 8
can confuse
-.I crontab
+.Nm
and that if you are running inside of
-.IR su (8)
+.Xr su 8
you should always use the
-.I -u
+.Fl u
option for safety's sake.
-.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
+.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
diff --git a/usr.sbin/cron/crontab/crontab.5 b/usr.sbin/cron/crontab/crontab.5
index 7aa5940..5b1191b 100644
--- a/usr.sbin/cron/crontab/crontab.5
+++ b/usr.sbin/cron/crontab/crontab.5
@@ -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
diff --git a/usr.sbin/cron/crontab/crontab.c b/usr.sbin/cron/crontab/crontab.c
index 7fc79d8..89a2d75 100644
--- a/usr.sbin/cron/crontab/crontab.c
+++ b/usr.sbin/cron/crontab/crontab.c
@@ -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*/
OpenPOWER on IntegriCloud