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