|
|
Power 6/32 Unix version 1.21
/*
* @(#)main.c 2.1
*/
#include <stdio.h>
#include <signal.h>
#include "../libI77/fiodefs.h"
#define ILL_ALIGN_FAULT 14
extern int errno;
char *getenv();
int xargc;
char **xargv;
main(argc, argv, arge)
int argc;
char **argv;
char **arge;
{
int sigdie();
long int (*sigf)();
int signum;
xargc = argc;
xargv = argv;
for (signum=1; signum<=16; signum++)
{
if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf);
}
f_init();
MAIN_();
f_exit();
return 0;
}
struct action {
char *mesg;
int core;
} sig_act[16] = {
{"Hangup", 0}, /* SIGHUP */
{"Interrupt!", 0}, /* SIGINT */
{"Quit!", 1}, /* SIGQUIT */
{"Illegal ", 1}, /* SIGILL */
{"Trace Trap", 1}, /* SIGTRAP */
{"IOT Trap", 1}, /* SIGIOT */
{"EMT Trap", 1}, /* SIGEMT */
{"Arithmetic Exception", 1}, /* SIGFPE */
{ 0, 0}, /* SIGKILL */
{"Bus error", 1}, /* SIGBUS */
{"Segmentation violation", 1}, /* SIGSEGV */
{"Sys arg", 1}, /* SIGSYS */
{"Open pipe", 0}, /* SIGPIPE */
{"Alarm", 0}, /* SIGALRM */
{"Terminated", 0}, /* SIGTERM */
{"Sig 16", 0}, /* unassigned */
};
/* The following arrays are defined & used assuming that signal codes are
1 to 5 for SIGFPE, and 0 to 3 for SIGILL.
Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */
#define N_ACT_FPE 5 /* number of entries in act_fpe[] */
struct action act_fpe[] = {
{"Integer overflow", 1},
{"Integer divide by 0", 1},
{"Floating divide by zero", 1},
{"Floating point overflow", 1},
{"Floating point underflow", 1},
};
#define N_ACT_ILL 4 /* number of entries in act_ill[] */
struct action act_ill[] = {
{"addr mode", 1},
{"instruction", 1},
{"operand", 0},
{"alignment", 1},
};
sigdie(s, t, sc)
int s; int t; struct sigcontext *sc;
{
extern unit units[];
register struct action *act = &sig_act[s-1];
/* print error message, then flush buffers */
if (s == SIGHUP || s == SIGINT || s == SIGQUIT)
signal(s, SIG_IGN); /* don't allow it again */
else
signal(s, SIG_DFL); /* shouldn't happen again, but ... */
if (act->mesg)
{
fprintf(units[STDERR].ufd, "*** %s", act->mesg);
if (s == SIGFPE)
{
if ((t-1) >= 0 && t < N_ACT_FPE)
fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg);
else
fprintf(units[STDERR].ufd, ": Type=%d?", t);
}
else if (s == SIGILL)
{
if (t == ILL_ALIGN_FAULT) /* ILL_ALIGN_FAULT maps to last
t = N_ACT_ILL-1; entry in act_ill[] */
if (t >= 0 && t < N_ACT_ILL)
fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg);
else
fprintf(units[STDERR].ufd, "compat mode: Code=%d", t);
}
putc('\n', units[STDERR].ufd);
}
f77_abort( s, act->core );
}
extern int _dbsubc; /* dbsubc is non-zero if -lg was specified to ld */
f77_abort( err_val, act_core )
{
char first_char, *env_var;
int core_dump;
env_var = getenv("f77_dump_flag");
first_char = (env_var == NULL) ? 0 : *env_var;
signal(SIGILL, SIG_DFL);
sigsetmask(0); /* don't block */
/* see if we want a core dump:
first line checks for signals like hangup - don't dump then.
second line checks if -lg specified to ld (e.g. by saying
-g to f77) and checks the f77_dump_flag var. */
core_dump = ((nargs() != 2) || act_core) &&
( (_dbsubc && (first_char != 'n')) || first_char == 'y');
if( !core_dump )
fprintf(units[STDERR].ufd,"*** Execution terminated\n");
f_exit();
_cleanup();
if( nargs() ) errno = err_val;
else errno = -2; /* prior value will be meaningless,
so set it to undefined value */
if( core_dump ) abort();
else exit( errno );
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.