Subject: Re: question about signals and system() and mutt
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 07/10/2001 02:21:22
In article <20010709194056.A29258@panix.com>,
Ben Rosengart <br@panix.com> wrote:
>Hello NetBSDers,
>  We are having a problem at Panix which we think we understand;
>however, we are not sure what the correct solution is.  I am hoping
>that someone here can enlighten me.
>
>Here's the scenario: a user uses mutt to compose a message.  Mutt
>spawns $EDITOR using system(3).  At some point during the composition
>of the message, the user presses ^C, which is caught by the editor
>and handled appropriately.  However, when the user quits the editor
>in order to send their message, mutt reports something like "Error
>running "vi '/tmp/mutt-panix1-28255-0'"!  This is only a problem
>because the user thinks it is, and calls us.
>
>We think that system() is returning non-zero because the shell is
>terminating abnormally, and we think the shell is terminating
>abnormally because it gets the SIGINT delivered to it as soon as
>the editor terminates, but we're not sure.
>
>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.

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].

christos