Bugfix: memory and thread-deleting problems
[monky] / src / logging.h
1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2  *
3  * Conky, a system monitor, based on torsmo
4  *
5  * Any original torsmo code is licensed under the BSD license
6  *
7  * All code written since the fork of torsmo is licensed under the GPL
8  *
9  * Please see COPYING for details
10  *
11  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12  * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
13  *      (see AUTHORS)
14  * All rights reserved.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  *
28  */
29
30 #include "mail.h"
31
32 void clean_up(void *memtofree1, void* memtofree2);
33 void clean_up_without_threads(void *memtofree1, void* memtofree2);
34
35 #ifndef _LOGGING_H
36 #define _LOGGING_H
37
38 #define NORM_ERR(...) { \
39         fprintf(stderr, PACKAGE_NAME": "); \
40         fprintf(stderr, __VA_ARGS__); \
41         fprintf(stderr, "\n"); \
42 }
43
44 /* critical error */
45 #define CRIT_ERR(memtofree1, memtofree2, ...) \
46         { NORM_ERR(__VA_ARGS__); clean_up(memtofree1, memtofree2); free(current_mail_spool); exit(EXIT_FAILURE); }
47
48 #define THREAD_CRIT_ERR(memtofree1, memtofree2, ...) \
49         { NORM_ERR(__VA_ARGS__); clean_up_without_threads(memtofree1, memtofree2); free(current_mail_spool); return; }
50
51 /* debugging output */
52 extern int global_debug_level;
53 #define __DBGP(level, ...) \
54         if (global_debug_level > level) { \
55                 fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__); \
56                 fprintf(stderr, __VA_ARGS__); \
57                 fprintf(stderr, "\n"); \
58         }
59 #define DBGP(...) __DBGP(0, __VA_ARGS__)
60 #define DBGP2(...) __DBGP(1, __VA_ARGS__)
61
62 #endif /* _LOGGING_H */