mirror of
https://github.com/systemd/systemd.git
synced 2025-01-09 01:18:19 +03:00
Merge pull request #5774 from keszybz/printf-annotations
Printf annotation improvements
This commit is contained in:
commit
74e941c022
@ -553,7 +553,7 @@ static int write_to_journal(
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int log_dispatch(
|
||||
int log_dispatch_internal(
|
||||
int level,
|
||||
int error,
|
||||
const char *file,
|
||||
@ -653,7 +653,7 @@ int log_dump_internal(
|
||||
if (_likely_(LOG_PRI(level) > log_max_level))
|
||||
return -error;
|
||||
|
||||
return log_dispatch(level, error, file, line, func, NULL, NULL, NULL, NULL, buffer);
|
||||
return log_dispatch_internal(level, error, file, line, func, NULL, NULL, NULL, NULL, buffer);
|
||||
}
|
||||
|
||||
int log_internalv(
|
||||
@ -680,7 +680,7 @@ int log_internalv(
|
||||
|
||||
vsnprintf(buffer, sizeof(buffer), format, ap);
|
||||
|
||||
return log_dispatch(level, error, file, line, func, NULL, NULL, NULL, NULL, buffer);
|
||||
return log_dispatch_internal(level, error, file, line, func, NULL, NULL, NULL, NULL, buffer);
|
||||
}
|
||||
|
||||
int log_internal(
|
||||
@ -744,7 +744,8 @@ int log_object_internalv(
|
||||
|
||||
vsnprintf(b, l, format, ap);
|
||||
|
||||
return log_dispatch(level, error, file, line, func, object_field, object, extra_field, extra, buffer);
|
||||
return log_dispatch_internal(level, error, file, line, func,
|
||||
object_field, object, extra_field, extra, buffer);
|
||||
}
|
||||
|
||||
int log_object_internal(
|
||||
@ -788,7 +789,7 @@ static void log_assert(
|
||||
|
||||
log_abort_msg = buffer;
|
||||
|
||||
log_dispatch(level, 0, file, line, func, NULL, NULL, NULL, NULL, buffer);
|
||||
log_dispatch_internal(level, 0, file, line, func, NULL, NULL, NULL, NULL, buffer);
|
||||
}
|
||||
|
||||
noreturn void log_assert_failed(const char *text, const char *file, int line, const char *func) {
|
||||
@ -943,7 +944,7 @@ int log_struct_internal(
|
||||
if (!found)
|
||||
return -error;
|
||||
|
||||
return log_dispatch(level, error, file, line, func, NULL, NULL, NULL, NULL, buf + 8);
|
||||
return log_dispatch_internal(level, error, file, line, func, NULL, NULL, NULL, NULL, buf + 8);
|
||||
}
|
||||
|
||||
int log_set_target_from_string(const char *e) {
|
||||
|
@ -75,6 +75,18 @@ void log_close_console(void);
|
||||
|
||||
void log_parse_environment(void);
|
||||
|
||||
int log_dispatch_internal(
|
||||
int level,
|
||||
int error,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *object_field,
|
||||
const char *object,
|
||||
const char *extra,
|
||||
const char *extra_field,
|
||||
char *buffer);
|
||||
|
||||
int log_internal(
|
||||
int level,
|
||||
int error,
|
||||
@ -115,7 +127,7 @@ int log_object_internalv(
|
||||
const char *extra_field,
|
||||
const char *extra,
|
||||
const char *format,
|
||||
va_list ap) _printf_(9,0);
|
||||
va_list ap) _printf_(10,0);
|
||||
|
||||
int log_struct_internal(
|
||||
int level,
|
||||
@ -137,7 +149,7 @@ int log_format_iovec(
|
||||
bool newline_separator,
|
||||
int error,
|
||||
const char *format,
|
||||
va_list ap);
|
||||
va_list ap) _printf_(6, 0);
|
||||
|
||||
/* This modifies the buffer passed! */
|
||||
int log_dump_internal(
|
||||
@ -167,6 +179,9 @@ void log_assert_failed_return(
|
||||
int line,
|
||||
const char *func);
|
||||
|
||||
#define log_dispatch(level, error, buffer) \
|
||||
log_dispatch_internal(level, error, __FILE__, __LINE__, __func__, NULL, NULL, NULL, NULL, buffer)
|
||||
|
||||
/* Logging with level */
|
||||
#define log_full_errno(level, error, ...) \
|
||||
({ \
|
||||
|
@ -2887,9 +2887,9 @@ static int exec_child(
|
||||
if (line) {
|
||||
log_open();
|
||||
log_struct(LOG_DEBUG,
|
||||
LOG_UNIT_ID(unit),
|
||||
"EXECUTABLE=%s", command->path,
|
||||
LOG_UNIT_MESSAGE(unit, "Executing: %s", line),
|
||||
LOG_UNIT_ID(unit),
|
||||
NULL);
|
||||
log_close();
|
||||
}
|
||||
@ -2953,9 +2953,9 @@ int exec_spawn(Unit *unit,
|
||||
return log_oom();
|
||||
|
||||
log_struct(LOG_DEBUG,
|
||||
LOG_UNIT_ID(unit),
|
||||
LOG_UNIT_MESSAGE(unit, "About to execute: %s", line),
|
||||
"EXECUTABLE=%s", command->path,
|
||||
LOG_UNIT_ID(unit),
|
||||
NULL);
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
|
@ -800,18 +800,18 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
|
||||
|
||||
default:
|
||||
log_struct(job_result_log_level[result],
|
||||
LOG_UNIT_ID(u),
|
||||
LOG_MESSAGE("%s", buf),
|
||||
"RESULT=%s", job_result_to_string(result),
|
||||
LOG_UNIT_ID(u),
|
||||
NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
log_struct(job_result_log_level[result],
|
||||
mid,
|
||||
LOG_UNIT_ID(u),
|
||||
LOG_MESSAGE("%s", buf),
|
||||
"RESULT=%s", job_result_to_string(result),
|
||||
LOG_UNIT_ID(u),
|
||||
mid,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,12 @@ _printf_(2, 3) static int log_callback(int type, const char *fmt, ...) {
|
||||
fmt2 = strjoina("selinux: ", fmt);
|
||||
|
||||
va_start(ap, fmt);
|
||||
log_internalv(LOG_AUTH | callback_type_to_priority(type), 0, __FILE__, __LINE__, __FUNCTION__, fmt2, ap);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
log_internalv(LOG_AUTH | callback_type_to_priority(type),
|
||||
0, __FILE__, __LINE__, __FUNCTION__,
|
||||
fmt2, ap);
|
||||
#pragma GCC diagnostic pop
|
||||
va_end(ap);
|
||||
|
||||
return 0;
|
||||
|
@ -2693,7 +2693,6 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
|
||||
log_struct(f == SERVICE_SUCCESS ? LOG_DEBUG :
|
||||
(code == CLD_EXITED ? LOG_NOTICE : LOG_WARNING),
|
||||
LOG_UNIT_ID(u),
|
||||
LOG_UNIT_MESSAGE(u, "Main process exited, code=%s, status=%i/%s",
|
||||
sigchld_code_to_string(code), status,
|
||||
strna(code == CLD_EXITED
|
||||
@ -2701,6 +2700,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
: signal_to_string(status))),
|
||||
"EXIT_CODE=%s", sigchld_code_to_string(code),
|
||||
"EXIT_STATUS=%i", status,
|
||||
LOG_UNIT_ID(u),
|
||||
NULL);
|
||||
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
|
@ -1497,9 +1497,9 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
|
||||
* possible, which means we should avoid the low-level unit
|
||||
* name. */
|
||||
log_struct(LOG_INFO,
|
||||
mid,
|
||||
LOG_UNIT_ID(u),
|
||||
LOG_MESSAGE("%s", buf),
|
||||
LOG_UNIT_ID(u),
|
||||
mid,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@ -800,12 +800,11 @@ log:
|
||||
if (journald_crash) {
|
||||
/* We cannot log to the journal, so just print the MESSAGE.
|
||||
* The target was set previously to something safe. */
|
||||
log_struct(LOG_ERR, core_message, NULL);
|
||||
log_dispatch(LOG_ERR, 0, core_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (core_message)
|
||||
IOVEC_SET_STRING(iovec[n_iovec++], core_message);
|
||||
IOVEC_SET_STRING(iovec[n_iovec++], core_message);
|
||||
|
||||
if (truncated)
|
||||
IOVEC_SET_STRING(iovec[n_iovec++], "COREDUMP_TRUNCATED=1");
|
||||
|
@ -103,7 +103,10 @@ int mhd_respondf(struct MHD_Connection *connection,
|
||||
errno = -error;
|
||||
fmt = strjoina(format, "\n");
|
||||
va_start(ap, format);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
r = vasprintf(&m, fmt, ap);
|
||||
#pragma GCC diagnostic pop
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0)
|
||||
|
@ -436,7 +436,10 @@ static void log_xkb(struct xkb_context *ctx, enum xkb_log_level lvl, const char
|
||||
const char *fmt;
|
||||
|
||||
fmt = strjoina("libxkbcommon: ", format);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
log_internalv(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, fmt, args);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
#define LOAD_SYMBOL(symbol, dl, name) \
|
||||
|
Loading…
Reference in New Issue
Block a user