Since there is an existing "standard" for crontab error reporting
( check_error() diagnostic + non-zero exit ), I am suggesting
not inventing a new one ( warning message + zero exit ).


The crontab(1) manpage does not mention exit code; but it is
very common for zero to mean success / non-zero to mean failure.

I have no idea how other people use crontab, but I can easily
imagine someone has written automation code along the lines of:

        if crontab -n newfile 2>&-; then
                # looks good, do it for real now
                crontab - <newfile
        else
                : oops, do some error handling
        fi

For example:

        
https://github.com/sourcemage/grimoire/blob/9c3932d181e16dc2c0320f7bb189e42d445fd4d7/utils/fcrontabs/fcrontab#L25
        
https://github.com/brsf11/mugen-riscv/blob/9c474e23beb4834d6d87b7434edf94e0689d6a8d/testcases/cli-test/crontabs/oe_test_crontabs.sh#L56

I would like to support users; not belittle them.


-jonathan




georges.khaznadar wrote:
> To: Jonathan H N Chin <deb...@jhnc.org>, 1061...@bugs.debian.org
> From: Georges Khaznadar <georges.khazna...@free.fr>
> Date: Fri, 1 Mar 2024 14:08:08 +0100
> Subject: Re: Bug#1061155: closed by Debian FTP Masters
>  <ftpmas...@ftp-master.debian.org> (reply to Georges Khaznadar
>  <georg...@debian.org>) (Bug#1061155: fixed in cron 3.0pl1-186)
> 
> Dear Jonathan,
> 
> what is the right message to feed back to the user?
> 
> Warning ?
> 
> +---------+
> | Warning | ?
> +---------+
> 
> +-----------------------------------------+
> | +-------------------------------------+ |
> | | POOR MISGUIDED, YOU MADE AN ERROR ! | | ?
> | +-------------------------------------+ |
> +-----------------------------------------+
> 
> All in all, if the user does not want to read feedback messages, I
> ignore how to tell them the proper way.
> 
> About the exit status with -n: if one runs `crontab -n`, one expects
> somme feedback message, because nothing else is going to happen. The
> exit status is just an integer, far less expressive than a warning which
> points out some defect. Do you always check "$?" when you get an error
> or a warning message?
> 
> 
> 
> Jonathan H N Chin a écrit :
> > Hi, I just received the new package and tried it. Thanks.
> > 
> > It detects unacceptable MAILTO/MAILFROM, but because unacceptable
> > values will cause an error later, issuing only a warning feels
> > inadequate to me.
> > 
> > For usability, perhaps it would be better to use check_error().
> > Currently, warnings could be missed since the exit status with
> > `-n` is still 0.
> > 
> > Something like:
> > 
> >                 case TRUE:
> >                         /* here MAILTO and MAILFROM are checked */
> >                         if (
> >                           strncmp(envstr, "MAILTO=", 7) == 0 ||
> >                           strncmp(envstr, "MAILFROM=", 9) == 0
> >                         ){
> >                           if (! safe_p("", strstr(envstr,"=")+1)){
> >                             check_error("unsafe mail");
> >                           }
> >                         }
> >                         break;
> > 
> > 
> > 
> > The current safe_p() implementation may cause a syslog entry to be
> > generated with no associated username when called here, which feels
> > slightly wrong to me. It could be confusing to someone auditing logs
> > to see spurious "() UNSAFE MAIL" messages when `-n` is used.
> > 
> > 
> > 
> > -jonathan
> 
> -- 
> Georges KHAZNADAR et Jocelyne FOURNIER
> 22 rue des mouettes, 59240 Dunkerque France.
> Téléphone +33 (0)3 28 29 17 70
> 

Reply via email to