Bug 149561 - crontab -e fails to notice change in tmp file if edit is under 1 second
crontab -e fails to notice change in tmp file if edit is under 1 second
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: crontabs (Show other bugs)
i686 Linux
medium Severity low
: ---
: ---
Assigned To: Jason Vas Dias
Brock Organ
Depends On:
  Show dependency treegraph
Reported: 2005-02-23 18:04 EST by David Cohen
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-02-23 18:20:01 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description David Cohen 2005-02-23 18:04:54 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041107 Firefox/1.0

Description of problem:
If the temporary crontab file provided by crontab -e for the editor is
edited in under 1 second, the edit is not noticed, and not loaded.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1.create a script that accepts a filename as argument, and adds valid
crontab lines (eg: * * * * * /bin/echo "something") to that file.
2.set that script to be the editor for crontab -e by doing: export
3.run crontab -e

Actual Results:  the temp file gets modified in under 1 second, so the
modtime of the tempfile that crontab -e created is not updated.
Crontab checks the modtime and finds no change, so it doesn't load the
(modtime being the value of st_mtime in the stat struct)

Expected Results:  This change should be detected, regardless of how
fast it the editor edits the script.
Perhaps if it checked st_size and st_mtime instead of just st_mtime.

Additional info:

Since st_mtime is in seconds, any edit that takes less than one second
is not visible to crontab -e.

A simple work around for scripts that act as editors for crontab is to
make them sleep for a couple seconds before writing to the file, so
that  st_mtime can be updated.
Comment 1 Jason Vas Dias 2005-02-23 18:20:01 EST
An even simpler workaround is just to use stdin, ie.:
   $ myscript | crontab
would replace the current user's crontab with the output of 'myscript'.

The 'crontab -e' mode exists to enable crontab editing by human users.
No human users could ever complete an edit in less than a second ,
(if you can prove otherwise, please feel free to do so!:) and we 
already provide a way for non-human users to replace crontabs - see
above. Hence, this bug is being closed as "not a bug" .  

However, I will look at using the 64-bit time in stat->st_mtim.tv_usec
in future releases (st_mtime is #define'd to st_mtim.seconds on 2.4+

Note You need to log in before you can comment on or make changes to this bug.