blob: a25067de9a2ba2141407ec9506cf71af03814234 [file] [log] [blame]
Sylvain Munautac3e61a2010-07-25 18:08:54 +02001/* Panic handling */
2/*
3 * (C) 2010 by Sylvain Munaut <tnt@246tNt.com>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <osmocore/panic.h>
24
25#include "../config.h"
26
27
28static osmo_panic_handler_t osmo_panic_handler = (void*)0;
29
30
31#ifndef PANIC_INFLOOP
32
33#include <stdio.h>
34#include <stdlib.h>
35
36static void osmo_panic_default(const char *fmt, va_list args)
37{
38 vfprintf(stderr, fmt, args);
39 abort();
40}
41
42#else
43
44static void osmo_panic_default(const char *fmt, va_list args)
45{
46 while (1);
47}
48
49#endif
50
51
52void osmo_panic(const char *fmt, ...)
53{
54 va_list args;
55
56 va_start(args, fmt);
57
58 if (osmo_panic_handler)
59 osmo_panic_handler(fmt, args);
60 else
61 osmo_panic_default(fmt, args);
62
63 va_end(args);
64}
65
66
67void osmo_set_panic_handler(osmo_panic_handler_t *h)
68{
69 osmo_panic_handler = h;
70}
71