Merge pull request #20233 from maanyagoenka/log-error
systemd-analyze: add option to return an error value when unit verification fails
This commit is contained in:
@@ -39,6 +39,9 @@
|
||||
|
||||
#define SNDBUF_SIZE (8*1024*1024)
|
||||
|
||||
static log_syntax_callback_t log_syntax_callback = NULL;
|
||||
static void *log_syntax_callback_userdata = NULL;
|
||||
|
||||
static LogTarget log_target = LOG_TARGET_CONSOLE;
|
||||
static int log_max_level = LOG_INFO;
|
||||
static int log_facility = LOG_DAEMON;
|
||||
@@ -1341,6 +1344,14 @@ void log_received_signal(int level, const struct signalfd_siginfo *si) {
|
||||
signal_to_string(si->ssi_signo));
|
||||
}
|
||||
|
||||
void set_log_syntax_callback(log_syntax_callback_t cb, void *userdata) {
|
||||
assert(!log_syntax_callback || !cb);
|
||||
assert(!log_syntax_callback_userdata || !userdata);
|
||||
|
||||
log_syntax_callback = cb;
|
||||
log_syntax_callback_userdata = userdata;
|
||||
}
|
||||
|
||||
int log_syntax_internal(
|
||||
const char *unit,
|
||||
int level,
|
||||
@@ -1352,6 +1363,9 @@ int log_syntax_internal(
|
||||
const char *func,
|
||||
const char *format, ...) {
|
||||
|
||||
if (log_syntax_callback)
|
||||
log_syntax_callback(unit, level, log_syntax_callback_userdata);
|
||||
|
||||
PROTECT_ERRNO;
|
||||
char buffer[LINE_MAX];
|
||||
va_list ap;
|
||||
|
||||
@@ -32,6 +32,15 @@ typedef enum LogTarget{
|
||||
#define IS_SYNTHETIC_ERRNO(val) ((val) >> 30 & 1)
|
||||
#define ERRNO_VALUE(val) (abs(val) & 255)
|
||||
|
||||
/* The callback function to be invoked when syntax warnings are seen
|
||||
* in the unit files. */
|
||||
typedef void (*log_syntax_callback_t)(const char *unit, int level, void *userdata);
|
||||
void set_log_syntax_callback(log_syntax_callback_t cb, void *userdata);
|
||||
|
||||
static inline void clear_log_syntax_callback(dummy_t *dummy) {
|
||||
set_log_syntax_callback(/* cb= */ NULL, /* userdata= */ NULL);
|
||||
}
|
||||
|
||||
const char *log_target_to_string(LogTarget target) _const_;
|
||||
LogTarget log_target_from_string(const char *s) _pure_;
|
||||
void log_set_target(LogTarget target);
|
||||
|
||||
@@ -460,4 +460,10 @@ static inline size_t size_add(size_t x, size_t y) {
|
||||
return y >= SIZE_MAX - x ? SIZE_MAX : x + y;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int _empty[0];
|
||||
} dummy_t;
|
||||
|
||||
assert_cc(sizeof(dummy_t) == 0);
|
||||
|
||||
#include "log.h"
|
||||
|
||||
Reference in New Issue
Block a user