On Thu, May 30, 2002 at 11:44:00AM +0200, Tobias Ulbricht wrote:
> 
> please cc. to me [EMAIL PROTECTED]
> 
> Hi.
> 
> I had the stupid idea to set
> EDITOR=my-prog
> and execute
> crontab -e
> to be able to "edit" crontabs in the right way, i.e. without touching the
> crontab-files directly but with my own "editor" (here a
> cron-gui-interface)
> 
> 1. this doesn't work, since my c-program returns too quickly or too slow,
> anyway crontab *seldomly* "installs" the new file, mostly says it "didn't
> change".
> 
> 2. I tried it with "vi" as editor and if I was fast enough to enter ":wq",
> crontab doesn't install it.
> (ok. i didn't change a thing but the file was written, accessed, whatever
> and crontab should be installed. if you do it slowly, crontab installs
> it.)
> [EMAIL PROTECTED]:/home# crontab -e
> crontab: installing new crontab
> [EMAIL PROTECTED]:/home# crontab -e
> crontab: no changes made to crontab
> 
> second time I was fast enough typing ":wq"
> 
> 3. Anyway: any recommendations how to modify crontab from a c-program
> without messing with crontabs/user files?
> I know gcrontab accesses them directly. but I thought this shouldn't be
> dnoe.

A quick glance at the crontab source code (apt-get source cron, then
look in crontab.c) turned up the following lines:

        if (mtime == statbuf.st_mtime) {
                fprintf(stderr, "%s: no changes made to crontab\n",
                        ProgramName);
                goto remove;
        }
        fprintf(stderr, "%s: installing new crontab\n", ProgramName);

Basically what it's doing is saving the modification time of the file
you're about to edit, then sending it off to the editor, then checking
the new modification time of the file.  The granularity of st_mtime is
in seconds.  This normally wouldn't be a problem for humans (except
for *really* fast typists :-) but it's possible your program is
updating it faster than that.

Try sleeping for a second before exiting and see if that fixes the
problem.

Walt

Attachment: pgpKxHUQMdNz1.pgp
Description: PGP signature

Reply via email to