[net.unix] 2.9BSD Termination codes

jwp@uwmacc.UUCP (jeffrey w percival) (05/21/85)

I was trying to get the recently posted "insults" program running
on my 11/70, and when the makefile tried "./kafka <whatever>.k"
I get the message "*** Termination code 138".  Whence comes this
message?  I grepped through the known universe (kernel, libraries,
include, everywhere I could think of) and couldn't even find the
source of this message, let alone what "138" means.  Any clues
would be appreciated.  Thanks!

-- 
	Jeff Percival ...!uwvax!uwmacc!jwp

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (05/22/85)

> I get the message "*** Termination code 138".

That's from "make".  It means your subprocess exited with status 138.
Who knows what status 138 means..

chris@umcp-cs.UUCP (Chris Torek) (05/22/85)

The ``*** Termination code $n$'' message comes from (surprise!) make.

Termination code 138 means ``Bus error (core dumped)'' in csh terminology.
(128+x means core dumped; 138-128 = 10 means signal 10, SIGBUS.)  Make
prints ``*** Error code $n$'' for normal exit($n$) (except exit(0)).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland

john@x.UUCP (John Woods) (05/24/85)

> I was trying to get the recently posted "insults" program running
> on my 11/70, and when the makefile tried "./kafka <whatever>.k"
> I get the message "*** Termination code 138".  Whence comes this
> message?  I grepped through the known universe (kernel, libraries,
> include, everywhere I could think of) and couldn't even find the
> source of this message, let alone what "138" means.  Any clues
> would be appreciated.  Thanks!
> 
Ah, you too.  I thought I was the only one.

First, the message is from make.  kafka returned an exit code of 138, which
means: bus error (10) + core dumped (128).  See EXIT(2) and WAIT(2) for
further enlightenment.

On the MITCCC 11/70, kafka seems to have lots of wild pointer references.
So far, it doesn't seem to be int/long confusion, nor does it seem to be
long names (though I had to change kn_nodenumber to kn_nodnumber to make
V7 cc happy).  If anyone else gets kafka to run on an 11, I'd be interested
in knowing what was wrong (and I'll mention it in net.sources.bugs if I
get it working, too).
-- 
John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101
...!decvax!frog!john, ...!mit-eddie!jfw, jfw%mit-ccc@MIT-XX.ARPA

"MU" said the Sacred Chao...

guy@sun.uucp (Guy Harris) (05/27/85)

> I was trying to get the recently posted "insults" program running
> on my 11/70, and when the makefile tried "./kafka <whatever>.k"
> I get the message "*** Termination code 138".  Whence comes this
> message?

When a program run by another program exits, it either returns an "exit
code" (labelled as an "Error code" by "make" if it isn't zero) if it
terminates normally by doing an "exit" system call", or a "termination code"
if it terminates due to a signal.  The termination code has the signal
number in the lower 7 bits; the eighth bit is a flag indicating whether a
memory image was dumped.  That information is what the shell uses to say
"Memory fault" - signal 11 - and, if a memory image was dumped, "core
dumped".  Unfortunately, "make" does an extremely poor job of decoding this
information, unlike the shell; it just throws the raw bits (TM of Minnesota
Public Radio?) at you.  138 (decimal) == 128 + 10.  The 128 is the eighth
bit, indicating that a memory image was dumped; the 10 indicates signal 10
which is SIGBUS.  On most UNIXes, this indicates that the machine got a "bus
error", which, under normal circumstances, means the program tried to
reference a 16-bit quantity on an odd-byte boundary or something like that.
4.xBSD for the VAX also gives this signal if a program tries to write to a
write-protected portion of memory or read from a read-protected portion of
memory.

In short, it means that the "kafka" program blew up; my guess is that it
tried to reference a 16-bit quantity on an odd-byte boundary, since the VAX
allows that but the PDP-11 doesn't.

For the benefit of those of you who are sick of "Termination code NNN"
messages from "make", the following lump of code can be stuck into
"doname.c".  The code is pretty much the same in the V7 "make" (which
appears in 4.xBSD) and the S3/S5 "make".  Just replace the code that calls
"dosys" and prints a message if the return status is non-zero with this code.
The "#ifdef BSD4_2" reflects the fact that 4.2BSD provides a standard list
of "signal messages"; V7, 4.1BSD, and S{3,5} don't.  You may have to adjust
the list of messages for your particular flavor of UNIX.

#include <sys/signal.h>

	if( status = dosys(comstring, nohalt) )
	{
		if( status>>8 )
			(void)printf("*** Error code %d", status>>8 );
		else
		{
#ifdef BSD4_2
			extern char *sys_siglist[];
#else
			static char *sys_siglist[] = {
				"Signal 0",
				"Hangup",
				"Interrupt",
				"Quit",
				"Illegal instruction",
				"Trace/BPT trap",
				"Abort",
				"EMT trap",
				"Floating exception",
				"Killed",
				"Bus error",
				"Memory fault",
				"Bad system call",
				"Broken pipe",
				"Alarm call",
				"Terminated",
				"Signal 16",
				"Signal 17",
				"Child death",
				"Power fail",
			};
#endif
			int coredumped;

			coredumped = status & 0200;
			status &= 0177;
			if (status > NSIG)
				(void)printf("*** Signal %d", status );
			else
				(void)printf("*** %s", sys_siglist[status] );
			if (coredumped)
				(void)printf(" - core dumped");
		}

		if(nohalt) (void)printf(" (ignored)\n");
		else	(void)printf("\n");
		(void)fflush(stdout);
	}

This code has compiled, but I haven't tested it, nor have I compiled it
except under 4.2BSD.

	Guy Harris

dan@haddock.UUCP (05/27/85)

The make status codes are actually not hard to "read", though you
won't necessarily be any the wiser when you're done.  They are
the actual values returned from wait(2).  A "termination code" indicates
the program was killed by a signal; see the description of the low-order byte
returned by wait(2).  "Termination code 138" means 128 (core dumped)
plus 10 (killed by signal 10; see signal(2) to find out what it is).

If make indicates an "Error code", then the program was not killed by
a signal but terminated intentionally.  The number is the exit() value
supplied by the program.

	Dan Franklin