scheme shell
about
download
support
resources
docu
links
 
scsh.net
From: "Brian D. Carlstrom" <bdc at carlstrom com>
Message-ID: <16297.64419.512686.179043 at zot electricrain com>
Date: Wed, 5 Nov 2003 23:43:31 -0800
To: ZHAO Wei <zhaoway at public1 ptt js cn>
Cc: scsh at zurich csail mit edu
Subject: detect broken pipe

ZHAO Wei writes:
 > How could I detect broken pipe ? And how could I do anything graceful on
 > it ?

I assume you are talking about the SIGPIPE signal. looking at
scsh/doc/cheat.txt, I see there is a signal/pipe constant. The related
functions are in the cheat sheet after this. They led me to look at
scsh/doc/scsh-manual/syscalls.tex. There it says:

    Note that scsh does not support signal handlers for ``synchronous''
    Unix signals, such as signal/ill or signal/pipe. Synchronous
    occurrences of these signals are better handled by raising a Scheme
    exception. We recommend you avoid using signal handlers unless you
    absolutely have to; Section \ref{sec:event-interf-interr} describes
    a better interface to signals.

So it seems like the signal/pipe constant is meant for use to signal
other people, not for handling. sec:event-interf-interr is defined in
scsh/doc/scsh-manual/threads.tex, but doesn't seem immediately relevant
for this case. scsh/signals1.c seems to disable SIGPIPE. It's been a
while since I've dealt with SIGPIPE, but looking at the write(2) man
page, it seems if it's disabled you'll get an EPIPE instead, which in
scsh is errno/pipe. back to cheat.txt, I see

(with-errno-handler HANDLER-SPEC . BODY)
    HANDLER-SPEC is of the form
    	((ERRNO PACKET) CLAUSE ...)
    ERRNO and PACKET are variables bound to the errno error being raised.
    There are two forms for handler clauses:
    	((ERRNO ...) . BODY)
    	(else . BODY)
    ERRNO are expressions evaluating to errno integers.

which is also mentioned in the FAQ, but with no example. I see an
example in scsh/dot-locking.scm, so perhaps you just need to wrap your
body with a

(with-errno-handler
    ((errno packet)
      ((errno/pipe)
       ...error code here...
       #f))
    ...regular path here...

then you'd be happy?

-bri

Up