[comp.unix.wizards] Ksh signal anomoly

pgn@iwtpm.ATT.COM (XMPF50-Novorolsky) (11/17/87)

Has anyone using K-shell ever seen this anomoly, and have an explanation.
(i.e. Is it a bug or a feature )

When catching a signal and exiting from the program from within the
signal handling function, the exit value from a caught SIGINT
is the intended exit value plus 128. When other signal (SIGQUIT, SIGTERM
or SIGHUP) are caught, ksh reports the correct return value (2 in
the following example.

A search through the manuals resulted in some suspicion and confusion
surrounding the exit values returned by child processes.
(ksh may be retaining some of the information returned by the child
process, in this case, sig)

So, is ksh providing a feature that I don't understand, or does it have a bug?
(If it is a feature, it seems to be a little inconsistent)

For an example, try the following:

sig.c
-------------------------------------------------------
#include <signal.h>

#define INC 2

void sig_clean();
void exit();

main()
{

    (void) signal(SIGHUP, sig_clean);
    (void) signal(SIGINT, sig_clean);
    (void) signal(SIGQUIT, sig_clean);
    (void) signal(SIGTERM, sig_clean);

    (void) pause();
}

void
sig_clean(sig)
int sig;
{
    (void)signal(sig,SIG_IGN);
    (void)printf("Signal %d caught\n",sig);
    (void)signal(sig,sig_clean);
    exit(INC);
}

-------------------------------------------------------

From ksh:
$ sig

# Kill the sig process with the signal of your choice

$ echo $?
Any systems that I have tried this on show an exit value of 130.

If the call to sig and echo $? are placed in an executeable shell file,
the return value reported is 2.

					Paul Novorolsky

ekrell@ulysses.UUCP (11/20/87)

I tested your program on a BSD machine and it does the expected thing.
I'll assume you're on a system V machine. You don't say how you "kill"
the sig program.  Are you hitting interrupt on the keyboard or are
you sending it a signal as in "kill -INT pid"?
-- 
    
    Eduardo Krell                   AT&T Bell Laboratories, Murray Hill

    {ihnp4,seismo,ucbvax}!ulysses!ekrell