2
* gam_error.c: the debugging intrastructure
4
* Allow to use GAM_DEBUG environment variable or SIG_USR2 for
5
* dynamic debugging of clients and server.
7
* Daniel Veillard <veillard@redhat.com>
8
* See the Copyright file.
6
16
#include "gam_error.h"
8
typedef void (*signal_handler)(int);
18
typedef void (*signal_handler) (int);
20
extern void gam_show_debug(void);
21
extern void gam_got_signal (void);
23
int gam_debug_active = 0;
10
24
static int initialized = 0;
11
25
static int do_debug = 0;
12
26
static int got_signal = 0;
13
27
static FILE *debug_out = NULL;
16
gam_error_handle_signal(void) {
30
gam_error_handle_signal(void)
17
32
if (got_signal == 0)
20
37
if (do_debug == 0) {
21
char path[50] = "/tmp/gamin_debug_XXXXXX";
22
int fd = mkstemp(path);
24
debug_out = fdopen(fd, "a");
25
if (debug_out != NULL)
38
if (debug_out != stderr) {
39
char path[50] = "/tmp/gamin_debug_XXXXXX";
40
int fd = mkstemp(path);
43
debug_out = fdopen(fd, "a");
44
if (debug_out != NULL) {
30
if (debug_out != NULL) {
52
if (debug_out != stderr) {
55
if (debug_out != NULL) {
39
gam_error_signal(int no) {
66
gam_error_signal(int no)
40
68
got_signal = !got_signal;
69
gam_debug_active = -1; /* force going into gam_debug() */
76
* Initialization routine for the error and debug handling.
44
gam_error_init(void) {
46
81
if (initialized == 0) {
82
struct sigaction oldact;
50
if (getenv("GAM_DEBUG") != NULL)
52
prev = signal(SIGUSR2, gam_error_signal);
53
/* if there is already an handler switch back to the original
54
to avoid disturbing the application behaviour */
55
if ((prev != SIG_IGN) && (prev != SIG_DFL) && (prev != NULL))
56
signal(SIGUSR2, prev);
86
if (getenv("GAM_DEBUG") != NULL) {
92
gam_error_handle_signal();
95
/* if there is already an handler, leave it as is to
96
* avoid disturbing the application's behaviour */
97
if (sigaction (SIGUSR2, NULL, &oldact) == 0) {
98
if (oldact.sa_handler == NULL && oldact.sa_sigaction == NULL)
99
signal(SIGUSR2, gam_error_signal);
107
* Checking routine to call from time to time to handle asynchronous
108
* error debugging events.
111
gam_error_check(void)
113
if (initialized == 0)
117
gam_error_handle_signal();
62
128
* @file: the filename where the error was detected
63
129
* @line: the line where the error was detected