Vixie Cron 3.0-release

This commit is contained in:
jtc 1994-01-20 02:46:53 +00:00
parent 042650fe85
commit 44fa25f9b7
18 changed files with 116 additions and 88 deletions

View File

@ -15,7 +15,7 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
$Id: INSTALL,v 1.1.1.2 1994/01/12 18:34:24 jtc Exp $
$Id: INSTALL,v 1.1.1.3 1994/01/20 02:46:53 jtc Exp $
Read the comments at the top of the Makefile, then edit the area marked
'configurable stuff'.

View File

@ -1,6 +1,6 @@
File Name Archive # Description
-----------------------------------------------------------
CHANGES 1
CHANGES 2
CONVERSION 1
FEATURES 1
INSTALL 1
@ -11,6 +11,8 @@
THANKS 1
bitstring.3 1
bitstring.h 1
compat.c 1
compat.h 1
config.h 1
cron.8 1
cron.c 1
@ -27,4 +29,5 @@
misc.c 2
pathnames.h 1
popen.c 1
putman.sh 1
user.c 1

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: compat.c,v 1.1.1.2 1994/01/12 18:35:27 jtc Exp $";
static char rcsid[] = "$Id: compat.c,v 1.1.1.3 1994/01/20 02:47:03 jtc Exp $";
#endif
/* vix 30dec93 [broke this out of misc.c - see RCS log for history]

View File

@ -16,7 +16,7 @@
*/
/*
* $Id: compat.h,v 1.1.1.2 1994/01/12 18:35:45 jtc Exp $
* $Id: compat.h,v 1.1.1.3 1994/01/20 02:47:05 jtc Exp $
*/
#ifndef __P

View File

@ -17,7 +17,7 @@
/* config.h - configurables for Vixie Cron
*
* $Id: config.h,v 1.1.1.2 1994/01/12 18:35:59 jtc Exp $
* $Id: config.h,v 1.1.1.3 1994/01/20 02:47:07 jtc Exp $
*/
#if !defined(_PATH_SENDMAIL)

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: cron.c,v 1.1.1.3 1994/01/12 18:36:09 jtc Exp $";
static char rcsid[] = "$Id: cron.c,v 1.1.1.4 1994/01/20 02:47:09 jtc Exp $";
#endif

View File

@ -17,7 +17,7 @@
/* cron.h - header for vixie's cron
*
* $Id: cron.h,v 1.1.1.3 1994/01/12 18:36:21 jtc Exp $
* $Id: cron.h,v 1.1.1.4 1994/01/20 02:47:12 jtc Exp $
*
* vix 14nov88 [rest of log is in RCS]
* vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley]

View File

@ -15,7 +15,7 @@
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $Id: crontab.1,v 1.1.1.1 1994/01/05 20:40:13 jtc Exp $
.\" $Id: crontab.1,v 1.1.1.2 1994/01/20 02:47:15 jtc Exp $
.\"
.TH CRONTAB 1 "29 December 1993"
.UC 4

View File

@ -15,7 +15,7 @@
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $Id: crontab.5,v 1.1.1.3 1994/01/12 18:36:59 jtc Exp $
.\" $Id: crontab.5,v 1.1.1.4 1994/01/20 02:47:16 jtc Exp $
.\"
.TH CRONTAB 5 "7 January 1994"
.UC 4

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: crontab.c,v 1.1.1.3 1994/01/12 18:37:20 jtc Exp $";
static char rcsid[] = "$Id: crontab.c,v 1.1.1.4 1994/01/20 02:47:18 jtc Exp $";
#endif
/* crontab - install and manage per-user crontab files
@ -44,29 +44,30 @@ static char rcsid[] = "$Id: crontab.c,v 1.1.1.3 1994/01/12 18:37:20 jtc Exp $";
#endif
#define NHEADER_LINES 3
enum opt_t { opt_unknown, opt_list, opt_delete, opt_edit, opt_replace };
#if DEBUGGING
static char *Options[] = { "???", "list", "delete", "edit", "replace" };
#endif
static PID_T Pid;
static char User[MAX_UNAME], RealUser[MAX_UNAME];
static char Filename[MAX_FNAME];
static FILE *NewCrontab;
static int CheckErrorCount;
static enum { opt_unknown, opt_list, opt_delete, opt_edit, opt_replace }
Option;
static enum opt_t Option;
static struct passwd *pw;
static void list_cmd __P((void)),
delete_cmd __P((void)),
edit_cmd __P((void)),
replace_cmd __P((void)),
poke_daemon __P((void)),
check_error __P((char *)),
parse_args __P((int c, char *v[]));
#define NHEADER_LINES 3
#if DEBUGGING
static char *Options[] = { "???", "list", "delete", "edit", "replace" };
#endif
static int replace_cmd __P((void));
static void
@ -89,6 +90,8 @@ main(argc, argv)
int argc;
char *argv[];
{
int exitstatus;
Pid = getpid();
ProgramName = argv[0];
@ -110,15 +113,16 @@ main(argc, argv)
log_it(RealUser, Pid, "AUTH", "crontab command not allowed");
exit(ERROR_EXIT);
}
switch (Option)
{
exitstatus = OK_EXIT;
switch (Option) {
case opt_list: list_cmd();
break;
case opt_delete: delete_cmd();
break;
case opt_edit: edit_cmd();
break;
case opt_replace: replace_cmd();
case opt_replace: if (replace_cmd() < 0)
exitstatus = ERROR_EXIT;
break;
}
exit(0);
@ -281,14 +285,14 @@ static void
check_error(msg)
char *msg;
{
CheckErrorCount += 1;
fprintf(stderr, "\"%s\", line %d: %s\n", Filename, LineNumber, msg);
CheckErrorCount++;
fprintf(stderr, "\"%s\":%d: %s\n", Filename, LineNumber-1, msg);
}
static void
edit_cmd() {
char n[MAX_FNAME], *editor;
char n[MAX_FNAME], q[MAX_TEMPSTR], *editor;
FILE *f;
int ch, t, x;
struct stat statbuf;
@ -297,7 +301,6 @@ edit_cmd() {
PID_T pid, xpid;
log_it(RealUser, Pid, "BEGIN EDIT", User);
NewCrontab = NULL;
(void) sprintf(n, CRON_TAB(User));
if (!(f = fopen(n, "r"))) {
if (errno != ENOENT) {
@ -313,7 +316,7 @@ edit_cmd() {
}
(void) sprintf(Filename, "/tmp/crontab.%d", Pid);
if (-1 == (t = open(Filename, O_CREAT|O_EXCL|O_RDWR, 0700))) {
if (-1 == (t = open(Filename, O_CREAT|O_EXCL|O_RDWR, 0600))) {
perror(Filename);
goto fatal;
}
@ -355,12 +358,16 @@ edit_cmd() {
while (EOF != (ch = get_char(f)))
putc(ch, NewCrontab);
fclose(f);
fflush(NewCrontab); rewind(NewCrontab);
if (fflush(NewCrontab) < OK) {
perror(Filename);
exit(ERROR_EXIT);
}
again:
rewind(NewCrontab);
if (ferror(NewCrontab)) {
fprintf(stderr, "%s: error while writing new crontab to %s\n",
ProgramName, Filename);
fatal: if (NewCrontab) fclose(NewCrontab);
unlink(Filename);
fatal: unlink(Filename);
exit(ERROR_EXIT);
}
if (fstat(t, &statbuf) < 0) {
@ -432,17 +439,49 @@ edit_cmd() {
if (mtime == statbuf.st_mtime) {
fprintf(stderr, "%s: no changes made to crontab\n",
ProgramName);
} else {
fprintf(stderr, "%s: installing new crontab\n",
ProgramName);
replace_cmd();
goto remove;
}
fclose(NewCrontab); unlink(Filename);
fprintf(stderr, "%s: installing new crontab\n", ProgramName);
switch (replace_cmd()) {
case 0:
break;
case -1:
for (;;) {
printf("Do you want to retry the same edit? ");
fflush(stdout);
q[0] = '\0';
(void) fgets(q, sizeof q, stdin);
switch (islower(q[0]) ? q[0] : tolower(q[0])) {
case 'y':
goto again;
case 'n':
goto abandon;
default:
fprintf(stderr, "Enter Y or N\n");
}
}
/*NOTREACHED*/
case -2:
abandon:
fprintf(stderr, "%s: edits left in %s\n",
ProgramName, Filename);
goto done;
default:
fprintf(stderr, "%s: panic: bad switch() in replace_cmd()\n");
goto fatal;
}
remove:
unlink(Filename);
done:
log_it(RealUser, Pid, "END EDIT", User);
}
static void
/* returns 0 on success
* -1 on syntax error
* -2 on install error
*/
static int
replace_cmd() {
char n[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME];
FILE *tmp;
@ -455,7 +494,7 @@ replace_cmd() {
(void) sprintf(tn, CRON_TAB(n));
if (!(tmp = fopen(tn, "w+"))) {
perror(tn);
exit(ERROR_EXIT);
return (-2);
}
/* write a signature at the top of the file.
@ -468,10 +507,10 @@ replace_cmd() {
/* copy the crontab to the tmp
*/
rewind(NewCrontab);
Set_LineNum(1)
while (EOF != (ch = get_char(NewCrontab)))
putc(ch, tmp);
fclose(NewCrontab);
ftruncate(fileno(tmp), ftell(tmp));
fflush(tmp); rewind(tmp);
@ -479,7 +518,7 @@ replace_cmd() {
fprintf(stderr, "%s: error while writing new crontab to %s\n",
ProgramName, tn);
fclose(tmp); unlink(tn);
exit(ERROR_EXIT);
return (-2);
}
/* check the syntax of the file being installed.
@ -489,7 +528,7 @@ replace_cmd() {
* in the file proper -- kludged it by stopping after first error.
* vix 31mar87
*/
Set_LineNum(1)
Set_LineNum(1 - NHEADER_LINES)
CheckErrorCount = 0; eof = FALSE;
while (!CheckErrorCount && !eof) {
switch (load_env(envstr, tmp)) {
@ -498,7 +537,8 @@ replace_cmd() {
break;
case FALSE:
e = load_entry(tmp, check_error, pw, envp);
if (e) free(e);
if (e)
free(e);
break;
case TRUE:
break;
@ -508,33 +548,35 @@ replace_cmd() {
if (CheckErrorCount != 0) {
fprintf(stderr, "errors in crontab file, can't install.\n");
fclose(tmp); unlink(tn);
exit(ERROR_EXIT);
return (-1);
}
#ifdef HAS_FCHOWN
if (fchown(fileno(tmp), ROOT_UID, -1) < OK) {
if (fchown(fileno(tmp), ROOT_UID, -1) < OK)
#else
if (chown(tn, ROOT_UID, -1) < OK) {
if (chown(tn, ROOT_UID, -1) < OK)
#endif
{
perror("chown");
fclose(tmp); unlink(tn);
exit(ERROR_EXIT);
return (-2);
}
#ifdef HAS_FCHMOD
if (fchmod(fileno(tmp), 0600) < OK) {
if (fchmod(fileno(tmp), 0600) < OK)
#else
if (chmod(tn, 0600) < OK) {
if (chmod(tn, 0600) < OK)
#endif
{
perror("chown");
fclose(tmp); unlink(tn);
exit(ERROR_EXIT);
return (-2);
}
if (fclose(tmp) == EOF) {
perror("fclose");
unlink(tn);
exit(ERROR_EXIT);
return (-2);
}
(void) sprintf(n, CRON_TAB(User));
@ -543,11 +585,13 @@ replace_cmd() {
ProgramName, tn, n);
perror("rename");
unlink(tn);
exit(ERROR_EXIT);
return (-2);
}
log_it(RealUser, Pid, "REPLACE", User);
poke_daemon();
return (0);
}

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: database.c,v 1.1.1.3 1994/01/12 18:37:31 jtc Exp $";
static char rcsid[] = "$Id: database.c,v 1.1.1.4 1994/01/20 02:47:20 jtc Exp $";
#endif
/* vix 26jan87 [RCS has the log]

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: do_command.c,v 1.1.1.3 1994/01/12 18:37:36 jtc Exp $";
static char rcsid[] = "$Id: do_command.c,v 1.1.1.4 1994/01/20 02:47:22 jtc Exp $";
#endif

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: entry.c,v 1.1.1.3 1994/01/12 18:37:40 jtc Exp $";
static char rcsid[] = "$Id: entry.c,v 1.1.1.4 1994/01/20 02:47:23 jtc Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
@ -63,6 +63,9 @@ free_entry(e)
}
/* return NULL if eof or syntax error occurs;
* otherwise return a pointer to a new entry.
*/
entry *
load_entry(file, error_func, pw, envp)
FILE *file;
@ -290,35 +293,13 @@ load_entry(file, error_func, pw, envp)
*/
return e;
eof: /* if we want to return EOF, we have to jump down here and
* free the entry we've been building.
*
* now, in some cases, a parse routine will have returned EOF to
* indicate an error, but the file is not actually done. since, in
* that case, we only want to skip the line with the error on it,
* we'll do that here.
*
* many, including the author, see what's below as evil programming
* practice: since I didn't want to change the structure of this
* whole function to support this error recovery, I recurse. Cursed!
* (At least it's tail-recursion, as if it matters in C - vix/8feb88)
* I'm seriously considering using (another) GOTO... argh!
* (this does not get less disgusting over time. vix/15nov88)
* (indeed not. vix/20dec93)
*/
(void) free(e);
if (feof(file))
return NULL;
if (error_func)
eof:
free(e);
if (ecode != e_none && error_func)
(*error_func)(ecodes[(int)ecode]);
do {ch = get_char(file);}
while (ch != EOF && ch != '\n');
if (ch == EOF)
return NULL;
return load_entry(file, error_func, pw, envp);
while (ch != EOF && ch != '\n')
ch = get_char(file);
return NULL;
}

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: env.c,v 1.1.1.3 1994/01/12 18:37:43 jtc Exp $";
static char rcsid[] = "$Id: env.c,v 1.1.1.4 1994/01/20 02:47:25 jtc Exp $";
#endif

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: job.c,v 1.1.1.2 1994/01/12 18:37:50 jtc Exp $";
static char rcsid[] = "$Id: job.c,v 1.1.1.3 1994/01/20 02:47:28 jtc Exp $";
#endif

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: misc.c,v 1.1.1.2 1994/01/12 18:37:54 jtc Exp $";
static char rcsid[] = "$Id: misc.c,v 1.1.1.3 1994/01/20 02:47:29 jtc Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]

View File

@ -24,7 +24,7 @@
*/
#ifndef lint
static char rcsid[] = "$Id: popen.c,v 1.1.1.2 1994/01/12 18:38:01 jtc Exp $";
static char rcsid[] = "$Id: popen.c,v 1.1.1.3 1994/01/20 02:47:32 jtc Exp $";
static char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89";
#endif /* not lint */

View File

@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: user.c,v 1.1.1.3 1994/01/12 18:38:09 jtc Exp $";
static char rcsid[] = "$Id: user.c,v 1.1.1.4 1994/01/20 02:47:34 jtc Exp $";
#endif
/* vix 26jan87 [log is in RCS file]