Rename liblttng-ust-libc to liblttng-ust-libc-wrapper
[lttng-ust.git] / include / usterr.h
1 #ifndef _USTERR_H
2 #define _USTERR_H
3
4 /*
5 * Copyright (C) 2009 Pierre-Marc Fournier
6 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; version 2.1 of
11 * the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <string.h>
24 #include <sys/types.h>
25 #include <sys/syscall.h>
26 #include <errno.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #include "share.h"
31
32 enum ust_loglevel {
33 UST_LOGLEVEL_UNKNOWN = 0,
34 UST_LOGLEVEL_NORMAL,
35 UST_LOGLEVEL_DEBUG,
36 };
37
38 extern volatile enum ust_loglevel ust_loglevel;
39 void init_usterr(void);
40
41 static inline int ust_debug(void)
42 {
43 return ust_loglevel == UST_LOGLEVEL_DEBUG;
44 }
45
46 #ifndef UST_COMPONENT
47 #define UST_COMPONENT libust
48 #endif
49
50 /* To stringify the expansion of a define */
51 #define XSTR(d) STR(d)
52 #define STR(s) #s
53
54 #define UST_STR_COMPONENT XSTR(UST_COMPONENT)
55
56 #define ERRMSG(fmt, args...) \
57 do { \
58 fprintf(stderr, UST_STR_COMPONENT "[%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \
59 (long) getpid(), \
60 (long) syscall(SYS_gettid), \
61 ## args, \
62 __func__); \
63 } while(0)
64
65 #ifdef LTTNG_UST_DEBUG
66 # define DBG(fmt, args...) ERRMSG(fmt, ## args)
67 # define DBG_raw(fmt, args...) \
68 do { \
69 fprintf(stderr, fmt, ## args); \
70 } while(0)
71 #else
72 # define DBG(fmt, args...) \
73 do { \
74 if (ust_debug()) \
75 ERRMSG(fmt, ## args); \
76 } while (0)
77 # define DBG_raw(fmt, args...) \
78 do { \
79 if (ust_debug()) { \
80 fprintf(stderr, fmt, ## args); \
81 } \
82 } while(0)
83 #endif
84
85 #define WARN(fmt, args...) ERRMSG("Warning: " fmt, ## args)
86 #define ERR(fmt, args...) ERRMSG("Error: " fmt, ## args)
87 #define BUG(fmt, args...) ERRMSG("BUG: " fmt, ## args)
88
89 #if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)
90 #define PERROR(call, args...)\
91 do { \
92 char buf[200] = "Error in strerror_r()"; \
93 strerror_r(errno, buf, sizeof(buf)); \
94 ERRMSG("Error: " call ": %s", ## args, buf); \
95 } while(0);
96 #else
97 #define PERROR(call, args...)\
98 do { \
99 char *buf; \
100 char tmp[200]; \
101 buf = strerror_r(errno, tmp, sizeof(tmp)); \
102 ERRMSG("Error: " call ": %s", ## args, buf); \
103 } while(0);
104 #endif
105
106 #define BUG_ON(condition) \
107 do { \
108 if (caa_unlikely(condition)) \
109 ERR("condition not respected (BUG) on line %s:%d", __FILE__, __LINE__); \
110 } while(0)
111 #define WARN_ON(condition) \
112 do { \
113 if (caa_unlikely(condition)) \
114 WARN("condition not respected on line %s:%d", __FILE__, __LINE__); \
115 } while(0)
116 #define WARN_ON_ONCE(condition) WARN_ON(condition)
117
118 #endif /* _USTERR_H */
This page took 0.032941 seconds and 4 git commands to generate.