aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_panic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_panic.c')
-rw-r--r--src/microhttpd/mhd_panic.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_panic.c b/src/microhttpd/mhd_panic.c
new file mode 100644
index 00000000..1efba20d
--- /dev/null
+++ b/src/microhttpd/mhd_panic.c
@@ -0,0 +1,101 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4 Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21/**
22 * @file microhttpd/mhd_panic.h
23 * @brief MHD_panic() function and helpers
24 * @author Daniel Pittman
25 * @author Christian Grothoff
26 * @author Karlson2k (Evgeny Grin)
27 */
28
29#include "mhd_panic.h"
30#include "platform.h"
31#include "microhttpd.h"
32
33/**
34 * Handler for fatal errors.
35 */
36MHD_PanicCallback mhd_panic = (MHD_PanicCallback) NULL;
37
38/**
39 * Closure argument for #mhd_panic.
40 */
41void *mhd_panic_cls = NULL;
42
43
44/**
45 * Default implementation of the panic function,
46 * prints an error message and aborts.
47 *
48 * @param cls unused
49 * @param file name of the file with the problem
50 * @param line line number with the problem
51 * @param reason error message with details
52 */
53_MHD_NORETURN static void
54mhd_panic_std (void *cls,
55 const char *file,
56 unsigned int line,
57 const char *reason)
58{
59 (void) cls; /* Mute compiler warning. */
60#ifdef HAVE_MESSAGES
61 fprintf (stderr,
62 _ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"),
63 file,
64 line,
65 reason);
66#else /* ! HAVE_MESSAGES */
67 (void) file; /* Mute compiler warning. */
68 (void) line; /* Mute compiler warning. */
69 (void) reason; /* Mute compiler warning. */
70#endif
71 abort ();
72}
73
74
75/**
76 * Sets the global error handler to a different implementation. @a cb
77 * will only be called in the case of typically fatal, serious
78 * internal consistency issues. These issues should only arise in the
79 * case of serious memory corruption or similar problems with the
80 * architecture. While @a cb is allowed to return and MHD will then
81 * try to continue, this is never safe.
82 *
83 * The default implementation that is used if no panic function is set
84 * simply prints an error message and calls `abort()`. Alternative
85 * implementations might call `exit()` or other similar functions.
86 *
87 * @param cb new error handler or NULL to use default handler
88 * @param cls passed to @a cb
89 * @ingroup logging
90 */
91void
92MHD_set_panic_func (MHD_PanicCallback cb,
93 void *cls)
94{
95 if ((MHD_PanicCallback) NULL != cb)
96 mhd_panic = cb;
97 else
98 mhd_panic = &mhd_panic_std;
99
100 mhd_panic_cls = cls;
101}