summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_ggate/debug.cc
blob: b675ba5b3cae8ebbad537fb3b0ca95d756e000ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "common/debug.h"
#include "common/errno.h"
#include "debug.h"

#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
#define dout_prefix *_dout << "rbd::ggate: "

extern "C" void debugv(int level, const char *fmt, va_list ap) {
    char *msg;
    int saved_errno = errno;

    if (g_ceph_context == nullptr) {
        return;
    }

    vasprintf(&msg, fmt, ap);

    dout(ceph::dout::need_dynamic(level)) << msg << dendl;

    free(msg);
    errno = saved_errno;
}

extern "C" void debug(int level, const char *fmt, ...) {
    va_list ap;

    va_start(ap, fmt);
    debugv(level, fmt, ap);
    va_end(ap);
}

extern "C" void errx(const char *fmt, ...) {
    va_list ap;

    va_start(ap, fmt);
    debugv(-1, fmt, ap);
    va_end(ap);
}

extern "C" void err(const char *fmt, ...) {
    va_list ap;
    char *msg;
    int saved_errno = errno;

    va_start(ap, fmt);
    vasprintf(&msg, fmt, ap);
    va_end(ap);
    errno = saved_errno;

    errx("%s: %s", msg, cpp_strerror(errno).c_str());

    free(msg);
}