1996-09-19 22:19:05 +02:00
|
|
|
/*
|
|
|
|
**
|
1997-09-07 07:04:48 +02:00
|
|
|
** halt.c
|
1996-09-19 22:19:05 +02:00
|
|
|
**
|
1997-09-07 07:04:48 +02:00
|
|
|
** This is used to print out error messages and exit
|
1996-09-19 22:19:05 +02:00
|
|
|
*/
|
|
|
|
|
1999-10-11 20:51:10 +02:00
|
|
|
#include <stdarg.h>
|
1996-09-19 22:19:05 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
1999-10-11 20:51:10 +02:00
|
|
|
#include "halt.h"
|
1996-09-19 22:19:05 +02:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
**
|
1997-09-07 07:04:48 +02:00
|
|
|
** halt - print error message, and call clean up routine or exit
|
1996-09-19 22:19:05 +02:00
|
|
|
**
|
|
|
|
**------------------------------------------------------------------------*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
void
|
1999-10-11 20:51:10 +02:00
|
|
|
halt(char *format, ...)
|
1996-09-19 22:19:05 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
va_list arg_ptr;
|
1999-10-11 20:51:10 +02:00
|
|
|
char *pstr;
|
1997-09-08 04:41:22 +02:00
|
|
|
void (*sig_func) ();
|
1996-09-19 22:19:05 +02:00
|
|
|
|
1999-10-11 20:51:10 +02:00
|
|
|
va_start(arg_ptr, format);
|
1997-09-07 07:04:48 +02:00
|
|
|
if (strncmp(format, "PERROR", 6) != 0)
|
|
|
|
vfprintf(stderr, format, arg_ptr);
|
1996-09-19 22:19:05 +02:00
|
|
|
else
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
for (pstr = format + 6; *pstr == ' ' || *pstr == ':'; pstr++)
|
1996-09-19 22:19:05 +02:00
|
|
|
;
|
1997-09-07 07:04:48 +02:00
|
|
|
vfprintf(stderr, pstr, arg_ptr);
|
1996-09-19 22:19:05 +02:00
|
|
|
perror("");
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-09-19 22:19:05 +02:00
|
|
|
va_end(arg_ptr);
|
|
|
|
fflush(stderr);
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* call one clean up function if defined */
|
1997-09-08 23:56:23 +02:00
|
|
|
if ((sig_func = signal(SIGTERM, SIG_DFL)) !=SIG_DFL &&
|
|
|
|
sig_func !=SIG_IGN)
|
1997-09-07 07:04:48 +02:00
|
|
|
(*sig_func) (0);
|
1997-09-08 23:56:23 +02:00
|
|
|
else if ((sig_func = signal(SIGHUP, SIG_DFL)) !=SIG_DFL &&
|
|
|
|
sig_func !=SIG_IGN)
|
1997-09-07 07:04:48 +02:00
|
|
|
(*sig_func) (0);
|
1997-09-08 23:56:23 +02:00
|
|
|
else if ((sig_func = signal(SIGINT, SIG_DFL)) !=SIG_DFL &&
|
|
|
|
sig_func !=SIG_IGN)
|
1997-09-07 07:04:48 +02:00
|
|
|
(*sig_func) (0);
|
1997-09-08 23:56:23 +02:00
|
|
|
else if ((sig_func = signal(SIGQUIT, SIG_DFL)) !=SIG_DFL &&
|
|
|
|
sig_func !=SIG_IGN)
|
1997-09-07 07:04:48 +02:00
|
|
|
(*sig_func) (0);
|
1996-09-19 22:19:05 +02:00
|
|
|
exit(1);
|
|
|
|
}
|