diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2005-01-30 21:00:32 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2005-01-30 21:00:32 +0000 |
commit | ce591249a075911ea583030f68c67b2b95304975 (patch) | |
tree | 56cdb8d1f3c0305fb90acead8666a38dc56ef64f /usr.sbin | |
parent | bdfd97d0af68226f324606ff683cb43aaa06e2be (diff) |
Detect editors that move the edited file out from underneath us and warn.
Based on an idea from Han Boetes.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/cron/crontab.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index cc44af45d25..aa1a78c91b6 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crontab.c,v 1.47 2004/11/04 18:44:59 millert Exp $ */ +/* $OpenBSD: crontab.c,v 1.48 2005/01/30 21:00:31 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: crontab.c,v 1.47 2004/11/04 18:44:59 millert Exp $"; +static char const rcsid[] = "$OpenBSD: crontab.c,v 1.48 2005/01/30 21:00:31 millert Exp $"; #endif /* crontab - install and manage per-user crontab files @@ -284,7 +284,7 @@ edit_cmd(void) { char n[MAX_FNAME], q[MAX_TEMPSTR], *editor; FILE *f; int ch, t, x; - struct stat statbuf; + struct stat statbuf, xstatbuf; struct timespec mtimespec; struct timeval tv[2]; WAIT_T waiter; @@ -448,6 +448,11 @@ edit_cmd(void) { goto fatal; } if (timespeccmp(&mtimespec, &statbuf.st_mtimespec, -) == 0) { + if (lstat(Filename, &xstatbuf) == 0 && + statbuf.st_ino != xstatbuf.st_ino) { + fprintf(stderr, "%s: crontab temp file moved, editor " + "may create backup files improperly\n", ProgramName); + } fprintf(stderr, "%s: no changes made to crontab\n", ProgramName); goto remove; |