| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-bus-protocol.h" |
| 5 |
|
| 6 |
#include "errno-util.h" |
| 7 |
#include "sd-forward.h" |
| 8 |
|
| 9 |
bool bus_error_is_dirty(sd_bus_error *e); |
| 10 |
|
| 11 |
const char* _bus_error_message(const sd_bus_error *e, int error, char buf[static ERRNO_BUF_LEN]); |
| 12 |
|
| 13 |
/* Note: the lifetime of the compound literal is the immediately surrounding block, |
| 14 |
* see C11 §6.5.2.5, and |
| 15 |
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */ |
| 16 |
#define bus_error_message(e, error) _bus_error_message(e, error, (char[ERRNO_BUF_LEN]){}) |
| 17 |
|
| 18 |
#define BUS_ERROR_OOM SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_NO_MEMORY, "Out of memory") |
| 19 |
#define BUS_ERROR_FAILED SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_FAILED, "Operation failed") |
| 20 |
|
| 21 |
/* |
| 22 |
* There are two ways to register error maps with the error translation |
| 23 |
* logic: by using BUS_ERROR_MAP_ELF_REGISTER, which however only |
| 24 |
* works when linked into the same ELF module, or via |
| 25 |
* sd_bus_error_add_map() which is the official, external API, that |
| 26 |
* works from any module. |
| 27 |
* |
| 28 |
* Note that BUS_ERROR_MAP_ELF_REGISTER has to be used as decorator in |
| 29 |
* the bus error table, and BUS_ERROR_MAP_ELF_USE has to be used at |
| 30 |
* least once per compilation unit (i.e. per library), to ensure that |
| 31 |
* the error map is really added to the final binary. |
| 32 |
* |
| 33 |
* In addition, set the retain attribute so that the section cannot be |
| 34 |
* discarded by ld --gc-sections -z start-stop-gc. |
| 35 |
*/ |
| 36 |
|
| 37 |
#define BUS_ERROR_MAP_ELF_REGISTER \ |
| 38 |
_section_("SYSTEMD_BUS_ERROR_MAP") \ |
| 39 |
_used_ \ |
| 40 |
_retain_ \ |
| 41 |
_alignptr_ \ |
| 42 |
_variable_no_sanitize_address_ |
| 43 |
|
| 44 |
#define BUS_ERROR_MAP_ELF_USE(errors) \ |
| 45 |
extern const sd_bus_error_map errors[]; \ |
| 46 |
_used_ \ |
| 47 |
static const sd_bus_error_map * const CONCATENATE(errors ## _copy_, __COUNTER__) = errors; |
| 48 |
|
| 49 |
/* We use something exotic as end marker, to ensure people build the |
| 50 |
* maps using the macros. */ |
| 51 |
#define BUS_ERROR_MAP_END_MARKER -'x' |
| 52 |
|
| 53 |
BUS_ERROR_MAP_ELF_USE(bus_standard_errors); |