summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2003-10-02 16:12:36 +1000
committerDarren Tucker <dtucker@zip.com.au>2003-10-02 16:12:36 +1000
commit3e33cecf71860f73656a73b754cc7b7b9ec0b0ce (patch)
tree4c993022225dc70faeb42e23ff3323fd1deb717a /log.c
parentb210aa2cfa546d8c31f8c725d1de3050c747bd6e (diff)
- markus@cvs.openbsd.org 2003/09/23 20:17:11
[Makefile.in auth1.c auth2.c auth.c auth.h auth-krb5.c canohost.c cleanup.c clientloop.c fatal.c gss-serv.c log.c log.h monitor.c monitor.h monitor_wrap.c monitor_wrap.h packet.c serverloop.c session.c session.h ssh-agent.c sshd.c] replace fatal_cleanup() and linked list of fatal callbacks with static cleanup_exit() function. re-refine cleanup_exit() where appropriate, allocate sshd's authctxt eary to allow simpler cleanup in sshd. tested by many, ok deraadt@
Diffstat (limited to 'log.c')
-rw-r--r--log.c79
1 files changed, 1 insertions, 78 deletions
diff --git a/log.c b/log.c
index 9bce2555b..686a2a43c 100644
--- a/log.c
+++ b/log.c
@@ -34,7 +34,7 @@
34 */ 34 */
35 35
36#include "includes.h" 36#include "includes.h"
37RCSID("$OpenBSD: log.c,v 1.28 2003/05/24 09:02:22 djm Exp $"); 37RCSID("$OpenBSD: log.c,v 1.29 2003/09/23 20:17:11 markus Exp $");
38 38
39#include "log.h" 39#include "log.h"
40#include "xmalloc.h" 40#include "xmalloc.h"
@@ -183,83 +183,6 @@ debug3(const char *fmt,...)
183 va_end(args); 183 va_end(args);
184} 184}
185 185
186/* Fatal cleanup */
187
188struct fatal_cleanup {
189 struct fatal_cleanup *next;
190 void (*proc) (void *);
191 void *context;
192};
193
194static struct fatal_cleanup *fatal_cleanups = NULL;
195
196/* Registers a cleanup function to be called by fatal() before exiting. */
197
198void
199fatal_add_cleanup(void (*proc) (void *), void *context)
200{
201 struct fatal_cleanup *cu;
202
203 cu = xmalloc(sizeof(*cu));
204 cu->proc = proc;
205 cu->context = context;
206 cu->next = fatal_cleanups;
207 fatal_cleanups = cu;
208}
209
210/* Removes a cleanup frunction to be called at fatal(). */
211
212void
213fatal_remove_cleanup(void (*proc) (void *context), void *context)
214{
215 struct fatal_cleanup **cup, *cu;
216
217 for (cup = &fatal_cleanups; *cup; cup = &cu->next) {
218 cu = *cup;
219 if (cu->proc == proc && cu->context == context) {
220 *cup = cu->next;
221 xfree(cu);
222 return;
223 }
224 }
225 fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx",
226 (u_long) proc, (u_long) context);
227}
228
229/* Remove all cleanups, to be called after fork() */
230void
231fatal_remove_all_cleanups(void)
232{
233 struct fatal_cleanup *cu, *next_cu;
234
235 for (cu = fatal_cleanups; cu; cu = next_cu) {
236 next_cu = cu->next;
237 xfree(cu);
238 }
239 fatal_cleanups = NULL;
240}
241
242/* Cleanup and exit */
243void
244fatal_cleanup(void)
245{
246 struct fatal_cleanup *cu, *next_cu;
247 static int called = 0;
248
249 if (called)
250 exit(255);
251 called = 1;
252 /* Call cleanup functions. */
253 for (cu = fatal_cleanups; cu; cu = next_cu) {
254 next_cu = cu->next;
255 debug("Calling cleanup 0x%lx(0x%lx)",
256 (u_long) cu->proc, (u_long) cu->context);
257 (*cu->proc) (cu->context);
258 }
259 exit(255);
260}
261
262
263/* 186/*
264 * Initialize the log. 187 * Initialize the log.
265 */ 188 */