From dread@mw5.texas.net  Sat Nov  4 20:50:25 2000
Return-Path: <dread@mw5.texas.net>
Received: from mw5.texas.net (mw5.texas.net [206.127.30.15])
	by hub.freebsd.org (Postfix) with ESMTP id C0E8437B479
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  4 Nov 2000 20:50:24 -0800 (PST)
Received: from localhost.texas.net (tcnet05-11.austin.texas.net [209.99.42.11])
          by mw5.texas.net (2.4/2.4) with ESMTP
	  id WAA25368 for <FreeBSD-gnats-submit@freebsd.org>; Sat, 4 Nov 2000 22:50:22 -0600 (CST)
Received: (from dread@localhost)
	by localhost.texas.net (8.9.3/8.9.3) id WAA46127;
	Sat, 4 Nov 2000 22:50:21 -0600 (CST)
	(envelope-from dread)
Message-Id: <200011050450.WAA46127@localhost.texas.net>
Date: Sat, 4 Nov 2000 22:50:21 -0600 (CST)
From: Don Read <dread@texas.net>
Sender: dread@mw5.texas.net
Reply-To: dread@texas.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: crontab -e failures <Synopsis of the problem (one line)>
X-Send-Pr-Version: 3.2

>Number:         22612
>Category:       bin
>Synopsis:       crontab -e failures
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    dds
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 04 21:00:01 PST 2000
>Closed-Date:    Mon Aug 08 12:54:12 GMT 2005
>Last-Modified:  Mon Aug 08 12:54:12 GMT 2005
>Originator:     Don Read
>Release:        FreeBSD 4.2-BETA i386
>Organization:
>Environment:
non-POSIX

>Description:
crontab -e won't recognize a changed edit (Patch incl)
 ... if the editor exits in < 1 second.

See discussion in freebsd-questions Subject 'crontab -e' woes

In $SRC/usr.sbin/cron/crontab/crontab.c 
edit_cmd() (non-POSIX) has a stat.mtime resolution of 1 second,
so if the tmpfile is created, & the editor finishes within 
the same interval second, crontab decides the file is unchanged.

>How-To-Repeat:

EDITOR=ed
(echo '1s/^/#/'; echo 'wq') | crontab -e

/* may require multiple attempts */

>Fix:

--- old/crontab.c       Sat Nov  4 21:18:41 2000
+++ crontab.c   Sat Nov  4 22:09:41 2000
@@ -43,7 +43,7 @@
 # include <locale.h>
 #endif
 
-
+#include <string.h>
 #define NHEADER_LINES 3
 
 
@@ -269,14 +269,16 @@
        fprintf(stderr, "\"%s\":%d: %s\n", Filename, LineNumber-1, msg);
 }
 
+/* dwr 2000-11-04 compare entire statbuf instead of mtime's
+ * (avoids some nasty #ifdef POSIX).
+ */
 
 static void
 edit_cmd() {
        char            n[MAX_FNAME], q[MAX_TEMPSTR], *editor;
        FILE            *f;
        int             ch, t, x;
-       struct stat     statbuf;
-       time_t          mtime;
+       struct stat     statbuf, statprev;
        WAIT_T          waiter;
        PID_T           pid, xpid;
        mode_t          um;
@@ -340,12 +342,11 @@
        if (fclose(NewCrontab))
                err(ERROR_EXIT, "%s", Filename);
  again:
-       if (stat(Filename, &statbuf) < 0) {
+       if (stat(Filename, &statprev) < 0) {
                warn("stat");
  fatal:                unlink(Filename);
                exit(ERROR_EXIT);
        }
-       mtime = statbuf.st_mtime;
 
        if ((!(editor = getenv("VISUAL")))
         && (!(editor = getenv("EDITOR")))
@@ -409,7 +410,7 @@
                warn("stat");
                goto fatal;
        }
-       if (mtime == statbuf.st_mtime) {
+       if (0 == (memcmp(&statprev, &statbuf, sizeof(statprev))) ){
                warnx("no changes made to crontab");
                goto remove;
        }



>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: jedgar 
Responsible-Changed-When: Mon Nov 6 05:16:24 PST 2000 
Responsible-Changed-Why:  
Misfiled PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22612 
Responsible-Changed-From-To: freebsd-bugs->schweikh 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Mon Mar 18 02:00:46 PST 2002 
Responsible-Changed-Why:  
I'll take a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22612 
Responsible-Changed-From-To: schweikh->freebsd-bugs 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Sat Dec 20 04:53:42 PST 2003 
Responsible-Changed-Why:  
Back to the pool - I'm swamped. 
If anyone addresses this problem, it would be best to 
compute md5s of old and new crontabs instead of looking at modification times. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22612 
Responsible-Changed-From-To: freebsd-bugs->dds 
Responsible-Changed-By: dds 
Responsible-Changed-When: Tue Sep 14 22:07:05 EST 2004 
Responsible-Changed-Why:  
Was prompted to examine the problem by Ceri Davies after a related 
commit. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22612 
State-Changed-From-To: open->feedback 
State-Changed-By: dds 
State-Changed-When: Tue Sep 14 22:12:23 EST 2004 
State-Changed-Why:  
Fixed in crontab.c 1.22 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22612 
State-Changed-From-To: feedback->closed 
State-Changed-By: dds 
State-Changed-When: Mon Aug 8 12:53:42 GMT 2005 
State-Changed-Why:  
MFC changes to RELENG_5 


http://www.freebsd.org/cgi/query-pr.cgi?pr=22612 
>Unformatted:
