Re: Mutt 1.5.16 editor exit status brain damage
On 2007-06-15 17:51:52 -0400, Derek Martin wrote:
> IIRC, the POSIX standard mandates the exit status of "standard
> utilities" -- an author of a program which is not a "standard utility"
> can use the exit status in whatever way is convenient. It could
> be used to pass interesting numerical information back to the OS
> (calling process). There's no reason an author should avoid this
> behavior if it makes sense for his application.
Well, so... vi reports interesting numerical information back to Mutt
and Mutt reports it to the user. What's wrong with that?
> No, that's not correct. Strictly speaking, the shell assumes an exit
> status of 0 evaluates to TRUE, and any non-zero exit status evaluates
> to FALSE. Any interpretation about whether that means success or
> failure is open to interpretation by the author. Over time, shell
> programmers, and in some cases shell man page writers have assumed
> what you are assuming: that the meaning is success or failure. But
> that is false.
The shell treats nonzero values as if they were errors (e.g. "set -e"
makes the shell script exit in such a case). In such a case, if the
user doesn't want a nonzero value to be regarded as an error, he needs
to write some code (e.g. use "if ... then", or write a wrapper).
> Case in point: fsck returns an exit status of 1 when it repaired
> filesystem errors. This is not an error condition of the program, it
> is actually a success.
Not necessarily a success: there were filesystem errors, and though
they were corrected, files may have been lost or may be corrupt.
This must be reported to the user, hence the nonzero exit status.
> It has been doing nothing (based on the exit code) for 9 years, and
> AFAIK only 1 person has complained. By contrast, the current behavior
> is broken for users of vi on 2 major operating systems (at least,
> possibly more). Which behavior is correct? The answer is obvious:
> the old behavior is correct.
The GNU cmp utility has been buggy for at least 15 years. And during
this time, no-one reported the problem. Still, this was really a bug,
which has eventually been fixed.
Note that some error cases may occur very rarely, and that's why
problems are not reported very often (and even when they occur,
they may remain unnoticed, which may be very bad).
> That doesn't seem worthwhile to me. Mutt can detect if the user was
> able to edit the file by seeing if it changed after the editor ran on
> it.
The fact that the file has changed doesn't mean that the user could
edit it successfully. For instance, the user may save the file a
first time (so, the file has changed), continue to edit it, then
save-and-close, but at this time, the editor may crash or fail (e.g.
exit with a nonzero status).
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)