]>
jfr.im git - irc/quakenet/newserv.git/blob - core/error.c
12 static corehandler
*coreh
, *coret
;
14 char *sevtostring(int severity
) {
32 return "terminal error";
35 return "unknown error";
39 void reopen_logfile(int hooknum
, void *arg
) {
43 logfile
=fopen("newserv.log","a");
47 logfile
=fopen("newserv.log","a");
48 registerhook(HOOK_CORE_SIGUSR1
, reopen_logfile
);
51 void Error(char *source
, int severity
, char *reason
, ... ) {
57 struct error_event evt
;
60 vsnprintf(buf
,512,reason
,va
);
63 evt
.severity
=severity
;
66 triggerhook(HOOK_CORE_ERROR
, &evt
);
68 if (severity
>ERR_DEBUG
) {
71 strftime(timebuf
,100,"%Y-%m-%d %H:%M:%S",tm
);
72 fprintf(stderr
,"[%s] %s(%s): %s\n",timebuf
,sevtostring(severity
),source
,buf
);
74 fprintf(logfile
,"[%s] %s(%s): %s\n",timebuf
,sevtostring(severity
),source
,buf
);
77 if (severity
>=ERR_STOP
) {
78 fprintf(stderr
,"Terminal error occured, exiting...\n");
79 triggerhook(HOOK_CORE_STOPERROR
, NULL
);
84 void handlecore(void) {
87 /* no attempt is made to clean these up */
88 for(n
=coreh
;coreh
;n
=coreh
->next
)
92 corehandler
*registercorehandler(CoreHandlerFn fn
, void *arg
) {
93 corehandler
*c
= (corehandler
*)malloc(sizeof(corehandler
));
94 /* core if we can't allocate!! */
108 void deregistercorehandler(corehandler
*c
) {
112 c
->prev
->next
= c
->next
;
118 c
->next
->prev
= c
->prev
;