Header And Logo

PostgreSQL
| The world's most advanced open source database.

halt.c

Go to the documentation of this file.
00001 /*
00002 **
00003 **      halt.c
00004 **
00005 ** src/tools/entab/halt.c
00006 **
00007 **      This is used to print out error messages and exit
00008 */
00009 
00010 #include <stdarg.h>
00011 #include <signal.h>
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <string.h>
00015 #include <errno.h>
00016 
00017 
00018 /*-------------------------------------------------------------------------
00019 **
00020 **      halt - print error message, and call clean up routine or exit
00021 **
00022 **------------------------------------------------------------------------*/
00023 
00024 /*VARARGS*/
00025 void
00026 halt(const char *format,...)
00027 {
00028     va_list     arg_ptr;
00029     const char *pstr;
00030     void        (*sig_func) ();
00031 
00032     va_start(arg_ptr, format);
00033     if (strncmp(format, "PERROR", 6) != 0)
00034         vfprintf(stderr, format, arg_ptr);
00035     else
00036     {
00037         for (pstr = format + 6; *pstr == ' ' || *pstr == ':'; pstr++)
00038             ;
00039         vfprintf(stderr, pstr, arg_ptr);
00040         perror("");
00041     }
00042     va_end(arg_ptr);
00043     fflush(stderr);
00044 
00045     /* call one clean up function if defined */
00046     if ((sig_func = signal(SIGTERM, SIG_DFL)) != SIG_DFL &&
00047         sig_func != SIG_IGN)
00048         (*sig_func) (0);
00049     else if ((sig_func = signal(SIGHUP, SIG_DFL)) != SIG_DFL &&
00050              sig_func != SIG_IGN)
00051         (*sig_func) (0);
00052     else if ((sig_func = signal(SIGINT, SIG_DFL)) != SIG_DFL &&
00053              sig_func != SIG_IGN)
00054         (*sig_func) (0);
00055     else if ((sig_func = signal(SIGQUIT, SIG_DFL)) != SIG_DFL &&
00056              sig_func != SIG_IGN)
00057         (*sig_func) (0);
00058     exit(1);
00059 }