🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
4 messages
4 total messages Started by john hood Wed, 15 Nov 1995 00:00
trn, sh -c and interrupts-- bug or misfeature?
#17568
Author: john hood
Date: Wed, 15 Nov 1995 00:00
70 lines
2390 bytes
so, i've been having this problem with trn for a couple of
years now, and i'm finally getting motivated to try and fix it.

with /bin/sh on DEC OSF/1 v1.3 and 2.0 (i don't know about later
versions), and every variant of the Almquist shell I've used on Linux,
NetBSD and FreeBSD, a SIGINT from the keyboard will kill the shell, or
at least cause it to to exit, while it's waiting for a child in 'sh -c
command'.  every other shell i've tried, except for a fairly antique
bash, ignores the signal.

this causes considerable annoyance in trn, which uses sh -c to get
Pnews started.  When you hit ^G in emacs or ^C in vi, you have a
problem...sadly, there is no simple, general workaround/fix for trn.

now, i'm not a shell wizard, and i can't find any documentation that
says that this is legitimate or that it's not.  it's not a subtle
problem; it's hard for me to believe nobody's noticed it. :)

So, shell wizards:  bug or misfeature?  simple test script below.

  --john hood

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	t
#
echo x - t
sed 's/^X//' >t << 'END-of-t'
X#!/bin/sh
X#
X# test sig handling in sh -c
X#
X# create second script
XTF=/tmp/test.$$
Xcat > $TF <<\/EOF
X#!/bin/sh
Xecho -e "shell c flags: $-"
Xtrap
Xtrap : 2 3
Xecho "Type ^C and ^\\"
Xfor i in a b c d e
Xdo
X  sleep 1
X  echo shell c: $i
Xdone
X/EOF
Xchmod a+x $TF
X
Xif [ $# != 1 ]
Xthen
X  echo "$0 shell-to-test"
X  exit 1
Xfi
XSHELL=$1
Xecho -e "shell a flags: $-"
Xtrap
Xtrap : 2 3
X$SHELL -c "echo shell b flags: $-; trap; $TF"
Xecho 'shell a exit: ' $?
Xrm $TF
END-of-t
exit


Re: trn, sh -c and interrupts-- bug or misfeature?
#17571
Author: Ralph Jennings
Date: Wed, 15 Nov 1995 00:00
33 lines
2097 bytes
john hood (cgull@smoke.marlboro.vt.us) wrote:
: with /bin/sh on DEC OSF/1 v1.3 and 2.0 (i don't know about later
: versions), and every variant of the Almquist shell I've used on Linux,
: NetBSD and FreeBSD, a SIGINT from the keyboard will kill the shell, or
: at least cause it to to exit, while it's waiting for a child in 'sh -c
: command'.  every other shell i've tried, except for a fairly antique
: bash, ignores the signal.

: this causes considerable annoyance in trn, which uses sh -c to get
: Pnews started.  When you hit ^G in emacs or ^C in vi, you have a
: problem...sadly, there is no simple, general workaround/fix for trn.

: now, i'm not a shell wizard, and i can't find any documentation that
: says that this is legitimate or that it's not.  it's not a subtle
: problem; it's hard for me to believe nobody's noticed it. :)

: So, shell wizards:  bug or misfeature?  simple test script below.

Feature, you can use ^C to kill the program if you decide 
  that you don't want to wait for it finish doing what it's
  doing.  It's a feature for all of us impatient people.

Use trap like this, if you don't like that feature.

trap '' <interupts>

using trap with a : like you were makes the shell do nothing
  but all child processes get terminated.  Using it with a
  null tells even the child processes to ignore it.
-- 
F u cn rd ths u cnt spl wrth a dm!

Re: trn, sh -c and interrupts-- bug or misfeature?
#17579
Author: Olaf Titz
Date: Thu, 16 Nov 1995 00:00
38 lines
2589 bytes
john hood <cgull@smoke.marlboro.vt.us> wrote:
> with /bin/sh on DEC OSF/1 v1.3 and 2.0 (i don't know about later
> versions), and every variant of the Almquist shell I've used on Linux,
> NetBSD and FreeBSD, a SIGINT from the keyboard will kill the shell, or
> at least cause it to to exit, while it's waiting for a child in 'sh -c
> command'.  every other shell i've tried, except for a fairly antique
> bash, ignores the signal.
> this causes considerable annoyance in trn, which uses sh -c to get
> Pnews started.  When you hit ^G in emacs or ^C in vi, you have a
> problem...sadly, there is no simple, general workaround/fix for trn.

I've got bitten by the same problem long ago, when I used trn and
emacs under Linux with one of the first semi-usable "bash"s.

It is a shell bug. A shell that doesn't ignore SIGINT when spawning a
subprocess is broken. Rationale: as a shell implementer, you don't know
what the subprocesses your shell is spawning will do with SIGINT.
Emacs is a nice example in that its reaction to Ctrl-G (which goes via
SIGINT) is context-dependent. It does not always mean "exit" (in fact,
never except for the panic exit mode). So there is no reason to assume
that the subprocess will actually exit or do anything else in response
to SIGINT, and the only reaction that makes sense is "ignore".

This holds for the normal case (interactive commands) as well as for
the -c mode. Apparently, some shells get this right in interactive
mode (otherwise the users would complain very soon ;-) but -c mode
uses a different piece of program that has this overlooked.

In short: tell your vendors their shells are broken.

olaf
-- 
___        Olaf.Titz@inka.de or @{stud,informatik}.uni-karlsruhe.de       ____
__ o           <URL:http://www.inka.de/~bigred/>     <IRC:praetorius>
__/<_              >> Just as long as the wheels keep on turning round
_)>(_)______________ I will live for the groove 'til the sun goes down << ____

Re: trn, sh -c and interrupts-- bug or misfeature?
#17585
Author: john hood
Date: Thu, 16 Nov 1995 00:00
56 lines
2964 bytes
In article <48dtgj$ftb@hg.oro.net>, Ralph Jennings <knowbudy@au.oro.net> wrote:
>john hood (cgull@smoke.marlboro.vt.us) wrote:
>: with /bin/sh on DEC OSF/1 v1.3 and 2.0 (i don't know about later
>: versions), and every variant of the Almquist shell I've used on Linux,
>: NetBSD and FreeBSD, a SIGINT from the keyboard will kill the shell, or
>: at least cause it to to exit, while it's waiting for a child in 'sh -c
>: command'.  every other shell i've tried, except for a fairly antique
>: bash, ignores the signal.
>
>: this causes considerable annoyance in trn, which uses sh -c to get
>: Pnews started.  When you hit ^G in emacs or ^C in vi, you have a
>: problem...sadly, there is no simple, general workaround/fix for trn.
>
>: now, i'm not a shell wizard, and i can't find any documentation that
>: says that this is legitimate or that it's not.  it's not a subtle
>: problem; it's hard for me to believe nobody's noticed it. :)
>
>: So, shell wizards:  bug or misfeature?  simple test script below.
>
>Feature, you can use ^C to kill the program if you decide 
>  that you don't want to wait for it finish doing what it's
>  doing.  It's a feature for all of us impatient people.

no, you haven't got it, you're describing something slightly
different.  that's an interactive feature.

>Use trap like this, if you don't like that feature.
>
>trap '' <interupts>
>
>using trap with a : like you were makes the shell do nothing
>  but all child processes get terminated.  Using it with a
>  null tells even the child processes to ignore it.


trn essentially does fork()/exec("sh", "sh", "-c", Pnewsstring), where
the last string is usually "Pnews" but can be redefined by the user.
Pnews is a shell script.

trn can't ignore SIGINT before execing.  Pnews wants to use it, and
since it's a shell script, it can't turn it back on by itself.  trn
and Pnews are both working fine in this instance-- it's that sh -c in
the middle that's breaking, or so i think.  we can't tack "exec " onto
the front of Pnewsstring to get rid of it, because Pnewsstring may be
a list of commands.

the traps in my test script are just there to keep the real problem
from getting obscured; they do pretty much what trn and Pnews do, too.

  --jh
-- 
John Hood					Kosh-- just *see* it.
cgull@smoke.marlboro.vt.us


Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads