Re: crontab and editors (was Re: Editor Priorities)
Steve Greenland <firstname.lastname@example.org> writes:
> On 08-May-02, 16:12 (CDT), Richard Kettlewell <email@example.com> wrote:
>> Steve Greenland <firstname.lastname@example.org> writes:
>> > Richard Kettlewell <email@example.com> wrote:
>> >> Steve Greenland <firstname.lastname@example.org> writes:
>> >>> * Edits files in place, rather than moving/copying +20
>> >>> See crontab(1) for why.
>> >> Why can't crontab be fixed?
>> > Crontab isn't broken.
>> Well, it certainly sounds like it's broken to me...
> Crontab works like this roughly:
> 0. open /tmp/funnyname
> 1. copy existing /var/spool/cron/crontabs/whatever to /tmp/funnyname
> 2. start ($VISUAL|$EDITOR|/usr/bin/editor) on /tmp/funnyname, wait for child
> to exit.
> 3. if stat.modtime(/tmp/funnyname) hasn't changed, then goto 7.
> 4. rewind(/tmp/funnyname)
> 5. check that /tmp/funnyname parses
> 6. copy /tmp/funnyname /var/spool/cron/crontabs/whatever
> 7. rm /tmp/funnyname
> (All without closing /tmp/funnyname between 1 and 7).
That's a blatantly obvious bug.
> How is this broken - Other than in the presence of editors that do
> backups incorrectly. :-)
Rename-into-place is a desirable feature in editors (and in many other
programs) because it means that if the process has to stop writing
part way through saving, the original is still available via the
expected name. It might have to stop due to an error such as ENOSPC,
receiving a fatal signal, or power failure.
If you just truncate and rewrite the file to save it, then any of
these conditions can lose you data, which is at least a grave bug on
If you save a separate backup copy, and then truncate and rewrite,
then you don't lose any data when things go wrong, but the data is in
the wrong place and the file you were editing is mangled in some way.
That's at least inconvenient, and is disastrous for some files.
Obviously in the case of crontab since you're only editing a temporary
copy it doesn't matter if it gets trashed in this way. But crontab is
not the only application for these editors; they are used for data
that we care about, too.
crontab should be fixed, both to avoid /tmp and to use a sensible
algorithm for detecting when the file changes. Or not bothering to
detect when the file changes - why does it need to know anyway?
To UNSUBSCRIBE, email to email@example.com
with a subject of "unsubscribe". Trouble? Contact firstname.lastname@example.org