| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/util/exception.cc |
| Date: | 2025-11-02 02:35:35 |
| 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 | 537 | void Panic(const char *coordinates, const LogSource source, const int mask, | |
| 22 | const char *format, ...) { | ||
| 23 | 537 | char *msg = NULL; | |
| 24 | va_list variadic_list; | ||
| 25 | |||
| 26 | // Format the message string | ||
| 27 | 537 | va_start(variadic_list, format); | |
| 28 | 537 | int retval = vasprintf(&msg, format, variadic_list); | |
| 29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 537 times.
|
537 | assert(retval != -1); // else: out of memory |
| 30 | 537 | va_end(variadic_list); | |
| 31 | |||
| 32 | // Add the coordinates | ||
| 33 | 537 | char *msg_with_coordinates = NULL; | |
| 34 | 537 | retval = asprintf(&msg_with_coordinates, "%s\n%s", coordinates, msg); | |
| 35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 537 times.
|
537 | if (retval == -1) { |
| 36 | ✗ | free(msg_with_coordinates); | |
| 37 | } else { | ||
| 38 | 537 | free(msg); | |
| 39 | 537 | 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 537 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 537 times.
✗ Branch 7 not taken.
|
537 | throw ECvmfsException(msg); |
| 48 | #else | ||
| 49 | ✗ | LogCvmfs(source, mask, "%s", msg); | |
| 50 | ✗ | abort(); | |
| 51 | #endif | ||
| 52 | } | ||
| 53 | |||
| 54 | 40 | void Panic(const char *coordinates, const LogSource _source, const char *nul) { | |
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | assert(nul == NULL); |
| 56 | 40 | Panic(coordinates, _source, kLogDebug | kLogStderr | kLogSyslogErr, ""); | |
| 57 | } | ||
| 58 | |||
| 59 | #ifdef CVMFS_NAMESPACE_GUARD | ||
| 60 | } // namespace CVMFS_NAMESPACE_GUARD | ||
| 61 | #endif | ||
| 62 |