1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <fcntl.h>
#define import_kernel
#define import_knames
#define import_prtype
#define import_spp
#include <iraf.h>
extern char os_process_name[]; /* process name, set in zmain */
extern PKCHAR osfn_bkgfile[]; /* bkgfile fname if detached */
extern int save_prtype; /* process type saved by zmain */
extern int debug_sig;
/* ZPANIC -- Unconditionally terminate process. Normal termination occurs
* when the IRAF Main returns to the zmain. We are called if a nasty error
* occurs in the kernel (a "can't happen" type error) or if an error occurs
* during error recovery, and error recursion would otherwise result.
*/
int
ZPANIC (
XINT *errcode, /* integer error code at time of crash */
PKCHAR *errmsg /* packed error message string */
)
{
char msg[512];
int fd;
/* \nPANIC in `procname': error message\n
*/
strcpy (msg, "\n");
strcat (msg, "PANIC in `");
strcat (msg, os_process_name);
strcat (msg, "': ");
strcat (msg, (char *)errmsg);
strcat (msg, "\n");
write (2, msg, strlen(msg));
/* Echo the error message on the console if we are a bkg process,
* in case the user has logged off.
*/
if (save_prtype == PR_DETACHED) {
fd = open ("/dev/console", O_WRONLY);
if (fd > 0) {
write (fd, &msg[1], strlen(&msg[1]));
close (fd);
}
}
/* Delete the bkgfile if run as a detached process. Deletion of the
* bkgfile signals process termination.
*/
if (save_prtype == PR_DETACHED)
unlink ((char *)osfn_bkgfile);
/* Terminate process with a core dump if the debug_sig flag is set.
*/
if (debug_sig) {
#ifdef __linux__
signal (SIGABRT, SIG_DFL);
kill (getpid(), SIGABRT);
#else
signal (SIGEMT, SIG_DFL);
kill (getpid(), SIGEMT);
#endif
} else
_exit ((int)*errcode);
return (XOK);
}
/* KERNEL_PANIC -- Called by a kernel routine if a fatal error occurs in the
* kernel.
*/
int
kernel_panic (char *errmsg)
{
XINT errcode = 0;
PKCHAR pkmsg[SZ_LINE];
register char *ip, *op;
extern int ZPANIC(XINT *errcode, PKCHAR *errmsg);
/* It is necessary to copy the error message string to get a PKCHAR
* type string since misalignment is possible when coercing from char
* to PKCHAR.
*/
for (ip=errmsg, op=(char *)pkmsg; (*op++ = *ip++) != EOS; )
;
ZPANIC (&errcode, pkmsg);
return (XOK);
}
|