diff options
author | ache <ache@FreeBSD.org> | 1994-12-21 11:06:08 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1994-12-21 11:06:08 +0000 |
commit | bf3a1964a989fe3228f4391142660e1c88e2fbe7 (patch) | |
tree | 1807ebca4042184757e6d3dc4a7f4335f4e88810 /usr.sbin/cron/crontab/crontab.c | |
parent | f1a8be07df557b520417ca377bb35518f2f80e57 (diff) | |
download | FreeBSD-src-bf3a1964a989fe3228f4391142660e1c88e2fbe7.zip FreeBSD-src-bf3a1964a989fe3228f4391142660e1c88e2fbe7.tar.gz |
Now crontab works not only for vi editor, i.e. refers to
file name not to file fd
Diffstat (limited to 'usr.sbin/cron/crontab/crontab.c')
-rw-r--r-- | usr.sbin/cron/crontab/crontab.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/usr.sbin/cron/crontab/crontab.c b/usr.sbin/cron/crontab/crontab.c index 657af71..2caf78c 100644 --- a/usr.sbin/cron/crontab/crontab.c +++ b/usr.sbin/cron/crontab/crontab.c @@ -13,10 +13,11 @@ * Send bug reports, bug fixes, enhancements, requests, flames, etc., and * I'll try to keep a version up to date. I can be reached as follows: * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul + * From Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp */ #if !defined(lint) && !defined(LINT) -static char rcsid[] = "$Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $"; +static char rcsid[] = "$Id: crontab.c,v 1.4 1994/04/13 21:57:55 wollman Exp $"; #endif /* crontab - install and manage per-user crontab files @@ -328,7 +329,7 @@ edit_cmd() { perror("fchown"); goto fatal; } - if (!(NewCrontab = fdopen(t, "r+"))) { + if (!(NewCrontab = fdopen(t, "w"))) { perror("fdopen"); goto fatal; } @@ -358,22 +359,16 @@ edit_cmd() { while (EOF != (ch = get_char(f))) putc(ch, NewCrontab); fclose(f); - if (fflush(NewCrontab) < OK) { + if (fclose(NewCrontab)) { perror(Filename); exit(ERROR_EXIT); } again: - rewind(NewCrontab); - if (ferror(NewCrontab)) { - fprintf(stderr, "%s: error while writing new crontab to %s\n", - ProgramName, Filename); + if (stat(Filename, &statbuf) < 0) { + perror("stat"); fatal: unlink(Filename); exit(ERROR_EXIT); } - if (fstat(t, &statbuf) < 0) { - perror("fstat"); - goto fatal; - } mtime = statbuf.st_mtime; if ((!(editor = getenv("VISUAL"))) @@ -438,8 +433,8 @@ edit_cmd() { WCOREDUMP(waiter) ?"" :"no "); goto fatal; } - if (fstat(t, &statbuf) < 0) { - perror("fstat"); + if (stat(Filename, &statbuf) < 0) { + perror("stat"); goto fatal; } if (mtime == statbuf.st_mtime) { @@ -448,6 +443,10 @@ edit_cmd() { goto remove; } fprintf(stderr, "%s: installing new crontab\n", ProgramName); + if (!(NewCrontab = fopen(Filename, "r"))) { + perror(Filename); + goto fatal; + } switch (replace_cmd()) { case 0: break; @@ -513,10 +512,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); |