Subject: Re: question about signals and system() and mutt
To: Christos Zoulas <christos@zoulas.com>
From: Andrew Brown <atatat@atatdot.net>
List: tech-userlevel
Date: 07/09/2001 23:29:13
>>My questions are this: given that a user ought to be able to send
>>SIGINT to their editor without unduly affecting the process that
>>spawned the editor, which piece of code is misbehaving (mutt,
>>system(), or sh) and what would be more correct behavior?
>
>You are correct. What happens is that the shell dies, after the
>interrupt and exits with 2. This happens with both ksh zsh and sh,
>csh and tcsh [returns 256], but not bash.

this is the "normal" behavior for netbsd's sh, which is kinda dull.
it stems from the fact that sh, when processing a -c command, will not
ignore interrupts and will die (or something similar) when an
interrupt it sent.

my favorite is to press control-g in emacs (as the editor) from mutt.
emacs sets up control-g to send the quit character when it starts.
previously this was a problem in crontab as well (see bin/3713) but a
workaround was installed in crontab to deal with this.  in mutt, the
same code path is used for several things, so they refuse to accept
the responsibility for this behavior and recommand that you

	set editor="exec emacs -nw"

or similar.

>From the onint() code in sh:
>
>	if (rootshell && iflag)
>		exraise(EXINT);
>	else {
>		signal(SIGINT, SIG_DFL);
>		raise(SIGINT);
>	}
>
>This behavior is intentional in a non-interactive shell. I don't
>think that anything is misbehaving. Maybe mutt should be fixed
>to handle the error more gracefully [or not use system].

it would be nice if sh was taught not to die unceremoniously like
this.  the mutt people made sense in their argument.  a quick check of
solaris and freebsd (as two random base points) shows that their
versions of sh (all of /usr/xpg4/bin/sh, /usr/bin/sh, and /sbin/sh
under solaris) do not die under the simple test:

     % cat > sigs << EOF
     $SIG{'QUIT'} = 'IGNORE';
     sleep(10);         
     EOF         
     % sh -c 'perl sigs'
     (repeatedly pound on control-\ here)

yet netbsd does.

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
andrew@crossbar.com       * "information is power -- share the wealth."