Directory: | cvmfs/ |
---|---|
File: | cvmfs/util/exception.cc |
Date: | 2025-04-20 02:34:28 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 15 | 18 | 83.3% |
Branches: | 5 | 14 | 35.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * This file is part of the CernVM File System. | ||
3 | */ | ||
4 | |||
5 | |||
6 | #include "exception.h" | ||
7 | |||
8 | #include <cassert> | ||
9 | #include <cstdarg> | ||
10 | #include <cstdio> | ||
11 | #include <cstdlib> | ||
12 | |||
13 | #include "util/logging.h" | ||
14 | |||
15 | #ifdef CVMFS_NAMESPACE_GUARD | ||
16 | namespace CVMFS_NAMESPACE_GUARD { | ||
17 | #endif | ||
18 | |||
19 | 19 | void Panic(const char* coordinates, const LogSource source, const int mask, | |
20 | const char* format, ...) { | ||
21 | 19 | char* msg = NULL; | |
22 | va_list variadic_list; | ||
23 | |||
24 | // Format the message string | ||
25 | 19 | va_start(variadic_list, format); | |
26 | 19 | int retval = vasprintf(&msg, format, variadic_list); | |
27 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | assert(retval != -1); // else: out of memory |
28 | 19 | va_end(variadic_list); | |
29 | |||
30 | // Add the coordinates | ||
31 | 19 | char* msg_with_coordinates = NULL; | |
32 | 19 | retval = asprintf(&msg_with_coordinates, "%s\n%s", coordinates, msg); | |
33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (retval == -1) { |
34 | ✗ | free(msg_with_coordinates); | |
35 | } else { | ||
36 | 19 | free(msg); | |
37 | 19 | msg = msg_with_coordinates; | |
38 | } | ||
39 | // From now on we deal only with `msg` | ||
40 | |||
41 | // Either throw the exception or log + abort | ||
42 | #ifdef CVMFS_RAISE_EXCEPTIONS | ||
43 | (void) source; | ||
44 | (void) mask; | ||
45 |
2/4✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 19 times.
✗ Branch 7 not taken.
|
19 | throw ECvmfsException(msg); |
46 | #else | ||
47 | ✗ | LogCvmfs(source, mask, "%s", msg); | |
48 | ✗ | abort(); | |
49 | #endif | ||
50 | } | ||
51 | |||
52 | 2 | void Panic(const char* coordinates, const LogSource _source, const char *nul) { | |
53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert(nul == NULL); |
54 | 2 | Panic(coordinates, _source, kLogDebug | kLogStderr | kLogSyslogErr, ""); | |
55 | } | ||
56 | |||
57 | #ifdef CVMFS_NAMESPACE_GUARD | ||
58 | } // namespace CVMFS_NAMESPACE_GUARD | ||
59 | #endif | ||
60 |