usterr: do not include unused sys/syscall.h
[lttng-ust.git] / include / usterr.h
CommitLineData
5e96a467
MD
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>
a09dac63
PMF
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
5e96a467
MD
10 * License as published by the Free Software Foundation; version 2.1 of
11 * the License.
a09dac63
PMF
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
d61bfa72 23#include <string.h>
dd80aafe 24#include <sys/types.h>
dd80aafe 25#include <errno.h>
ff1fedb9 26#include <stdarg.h>
c1f20530 27#include <stdio.h>
ff1fedb9 28
d9ecffa9 29#include "lttng/ust-tid.h"
2f864739 30#include "share.h"
d61bfa72 31
5e96a467
MD
32enum ust_loglevel {
33 UST_LOGLEVEL_UNKNOWN = 0,
34 UST_LOGLEVEL_NORMAL,
35 UST_LOGLEVEL_DEBUG,
36};
37
38extern volatile enum ust_loglevel ust_loglevel;
39void init_usterr(void);
40
41static inline int ust_debug(void)
42{
43 return ust_loglevel == UST_LOGLEVEL_DEBUG;
44}
45
2028e7fd 46#ifndef UST_COMPONENT
2028e7fd
PMF
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
5e96a467
MD
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(), \
d9ecffa9 60 (long) gettid(), \
5e96a467
MD
61 ## args, \
62 __func__); \
63 } while(0)
dd80aafe 64
69400ac4 65#ifdef LTTNG_UST_DEBUG
5e96a467
MD
66# define DBG(fmt, args...) ERRMSG(fmt, ## args)
67# define DBG_raw(fmt, args...) \
68 do { \
69 fprintf(stderr, fmt, ## args); \
70 } while(0)
17674885 71#else
5e96a467
MD
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)
17674885 83#endif
5e96a467 84
dd80aafe
PMF
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)
d61bfa72 88
fb8c8e5f
MD
89#if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
90/*
91 * Version using XSI strerror_r.
92 */
d61bfa72
PMF
93#define PERROR(call, args...)\
94 do { \
95 char buf[200] = "Error in strerror_r()"; \
96 strerror_r(errno, buf, sizeof(buf)); \
dd80aafe 97 ERRMSG("Error: " call ": %s", ## args, buf); \
d61bfa72
PMF
98 } while(0);
99#else
fb8c8e5f
MD
100/*
101 * Version using GNU strerror_r, for linux with appropriate defines.
102 */
d61bfa72
PMF
103#define PERROR(call, args...)\
104 do { \
105 char *buf; \
106 char tmp[200]; \
107 buf = strerror_r(errno, tmp, sizeof(tmp)); \
dd80aafe 108 ERRMSG("Error: " call ": %s", ## args, buf); \
d61bfa72
PMF
109 } while(0);
110#endif
c9b64079 111
5e96a467
MD
112#define BUG_ON(condition) \
113 do { \
b5a3dfa5 114 if (caa_unlikely(condition)) \
5e96a467
MD
115 ERR("condition not respected (BUG) on line %s:%d", __FILE__, __LINE__); \
116 } while(0)
117#define WARN_ON(condition) \
118 do { \
b5a3dfa5 119 if (caa_unlikely(condition)) \
5e96a467
MD
120 WARN("condition not respected on line %s:%d", __FILE__, __LINE__); \
121 } while(0)
d6322067 122#define WARN_ON_ONCE(condition) WARN_ON(condition)
c9b64079 123
30ffe279 124#endif /* _USTERR_H */
This page took 0.032214 seconds and 4 git commands to generate.