3 Shared versions of debug(), log(), etc.
8 RCSID("$OpenBSD: log.c,v 1.1 1999/11/10 23:36:44 markus Exp $");
13 /* Fatal messages. This function never returns. */
16 fatal(const char *fmt, ...)
20 do_log(SYSLOG_LEVEL_FATAL, fmt, args);
25 /* Error messages that should be logged. */
28 error(const char *fmt, ...)
32 do_log(SYSLOG_LEVEL_ERROR, fmt, args);
36 /* Log this message (information that usually should go to the log). */
39 log(const char *fmt, ...)
43 do_log(SYSLOG_LEVEL_INFO, fmt, args);
47 /* More detailed messages (information that does not need to go to the log). */
50 chat(const char *fmt, ...)
54 do_log(SYSLOG_LEVEL_CHAT, fmt, args);
58 /* Debugging messages that should not be logged during normal operation. */
61 debug(const char *fmt, ...)
65 do_log(SYSLOG_LEVEL_DEBUG, fmt, args);
73 struct fatal_cleanup *next;
78 static struct fatal_cleanup *fatal_cleanups = NULL;
80 /* Registers a cleanup function to be called by fatal() before exiting. */
83 fatal_add_cleanup(void (*proc)(void *), void *context)
85 struct fatal_cleanup *cu;
87 cu = xmalloc(sizeof(*cu));
89 cu->context = context;
90 cu->next = fatal_cleanups;
94 /* Removes a cleanup frunction to be called at fatal(). */
97 fatal_remove_cleanup(void (*proc)(void *context), void *context)
99 struct fatal_cleanup **cup, *cu;
101 for (cup = &fatal_cleanups; *cup; cup = &cu->next)
104 if (cu->proc == proc && cu->context == context)
111 fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx\n",
112 (unsigned long)proc, (unsigned long)context);
115 /* Cleanup and exit */
119 struct fatal_cleanup *cu, *next_cu;
120 static int called = 0;
125 /* Call cleanup functions. */
126 for (cu = fatal_cleanups; cu; cu = next_cu)
129 debug("Calling cleanup 0x%lx(0x%lx)",
130 (unsigned long)cu->proc, (unsigned long)cu->context);
131 (*cu->proc)(cu->context);