*e = BUS_ERROR_FAILED;
}
- /* Now, fill in the message from strerror() if we can */
+ /* Now, fill in the message from strerror_r() if we can */
bus_error_strerror(e, error);
return -error;
}
}
fail:
- /* If that didn't work, use strerror() for the message */
+ /* If that didn't work, use strerror_r() for the message */
bus_error_strerror(e, error);
return -error;
}
return sd_bus_error_set_errno(e, error);
}
-const char *bus_error_message(const sd_bus_error *e, int error) {
+const char* _bus_error_message(const sd_bus_error *e, int error, char buf[static ERRNO_BUF_LEN]) {
/* Sometimes, the D-Bus server is a little bit too verbose with
* its error messages, so let's override them here */
if (sd_bus_error_has_name(e, SD_BUS_ERROR_ACCESS_DENIED))
if (e && e->message)
return e->message;
- return strerror_safe(error);
+ return strerror_r(abs(error), buf, ERRNO_BUF_LEN);
}
static bool map_ok(const sd_bus_error_map *map) {
#include "sd-bus.h"
+#include "errno-util.h"
#include "macro.h"
bool bus_error_is_dirty(sd_bus_error *e);
-const char *bus_error_message(const sd_bus_error *e, int error);
+const char* _bus_error_message(const sd_bus_error *e, int error, char buf[static ERRNO_BUF_LEN]);
+
+/* Note: the lifetime of the compound literal is the immediately surrounding block,
+ * see C11 §6.5.2.5, and
+ * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
+#define bus_error_message(e, error) _bus_error_message(e, error, (char[ERRNO_BUF_LEN]){})
#define BUS_ERROR_OOM SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_NO_MEMORY, "Out of memory")
#define BUS_ERROR_FAILED SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_FAILED, "Operation failed")