PR/3713: Aaron Brown: crontab fails with signals.
While I am here eliminate forking a shell for the editor.
This commit is contained in:
parent
2a820a18cf
commit
c7e6b87cad
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: crontab.c,v 1.17 2003/04/04 01:24:09 perry Exp $ */
|
||||
/* $NetBSD: crontab.c,v 1.18 2003/04/20 01:24:05 christos Exp $ */
|
||||
|
||||
/* Copyright 1988,1990,1993,1994 by Paul Vixie
|
||||
* All rights reserved
|
||||
@ -22,7 +22,7 @@
|
||||
#if 0
|
||||
static char rcsid[] = "Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: crontab.c,v 1.17 2003/04/04 01:24:09 perry Exp $");
|
||||
__RCSID("$NetBSD: crontab.c,v 1.18 2003/04/20 01:24:05 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -52,6 +52,7 @@ __RCSID("$NetBSD: crontab.c,v 1.17 2003/04/04 01:24:09 perry Exp $");
|
||||
# include <locale.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#define NHEADER_LINES 3
|
||||
@ -306,11 +307,10 @@ check_error(msg)
|
||||
fprintf(stderr, "\"%s\":%d: %s\n", Filename, LineNumber-1, msg);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
edit_cmd() {
|
||||
char n[MAX_FNAME], q[MAX_TEMPSTR];
|
||||
const char *editor;
|
||||
char *editor;
|
||||
FILE *f;
|
||||
int ch, t, x;
|
||||
struct stat statbuf;
|
||||
@ -318,6 +318,8 @@ edit_cmd() {
|
||||
long mtimensec;
|
||||
WAIT_T waiter;
|
||||
PID_T pid, xpid;
|
||||
sig_t oint, oabrt;
|
||||
char *argv[3];
|
||||
|
||||
log_it(RealUser, Pid, "BEGIN EDIT", User);
|
||||
(void) snprintf(n, sizeof(n), CRON_TAB(User));
|
||||
@ -413,6 +415,8 @@ edit_cmd() {
|
||||
* then don't use it. the security problems are more severe if we
|
||||
* close and reopen the file around the edit.
|
||||
*/
|
||||
oint = signal(SIGINT, SIG_IGN);
|
||||
oabrt = signal(SIGABRT, SIG_IGN);
|
||||
|
||||
switch (pid = fork()) {
|
||||
case -1:
|
||||
@ -428,13 +432,10 @@ edit_cmd() {
|
||||
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);
|
||||
}
|
||||
snprintf(q, sizeof(q), "%s %s", editor, Filename);
|
||||
execlp(_PATH_BSHELL, _PATH_BSHELL, "-c", q, NULL);
|
||||
argv[0] = editor;
|
||||
argv[1] = Filename;
|
||||
argv[2] = NULL;
|
||||
execvp(editor, argv);
|
||||
perror(editor);
|
||||
exit(ERROR_EXIT);
|
||||
/*NOTREACHED*/
|
||||
@ -442,7 +443,6 @@ edit_cmd() {
|
||||
/* parent */
|
||||
break;
|
||||
}
|
||||
|
||||
/* parent */
|
||||
xpid = wait(&waiter);
|
||||
if (xpid != pid) {
|
||||
@ -450,6 +450,9 @@ edit_cmd() {
|
||||
ProgramName, xpid, pid, editor);
|
||||
goto fatal;
|
||||
}
|
||||
(void)signal(SIGINT, oint);
|
||||
(void)signal(SIGABRT, oabrt);
|
||||
|
||||
if (WIFEXITED(waiter) && WEXITSTATUS(waiter)) {
|
||||
fprintf(stderr, "%s: \"%s\" exited with status %d\n",
|
||||
ProgramName, editor, WEXITSTATUS(waiter));
|
||||
@ -571,7 +574,7 @@ replace_cmd() {
|
||||
fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n");
|
||||
fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
|
||||
fprintf(tmp, "# (Cron version -- %s)\n",
|
||||
"$NetBSD: crontab.c,v 1.17 2003/04/04 01:24:09 perry Exp $");
|
||||
"$NetBSD: crontab.c,v 1.18 2003/04/20 01:24:05 christos Exp $");
|
||||
|
||||
/* copy the crontab to the tmp
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user