mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 15:10:33 +00:00
macro: introduce a nice macro for disabling -Wformat-nonliteral temporarily
This commit is contained in:
@@ -610,8 +610,6 @@ _pure_ static const char *job_get_status_message_format_try_harder(Unit *u, JobT
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
static void job_print_status_message(Unit *u, JobType t, JobResult result) {
|
||||
const char *format;
|
||||
|
||||
@@ -619,6 +617,8 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
|
||||
assert(t >= 0);
|
||||
assert(t < _JOB_TYPE_MAX);
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
|
||||
if (t == JOB_START) {
|
||||
format = job_get_status_message_format(u, t, result);
|
||||
if (!format)
|
||||
@@ -681,11 +681,10 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
|
||||
if (result == JOB_SKIPPED)
|
||||
unit_status_printf(u, ANSI_HIGHLIGHT_ON " INFO " ANSI_HIGHLIGHT_OFF, "%s is not active.");
|
||||
}
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
|
||||
static void job_log_status_message(Unit *u, JobType t, JobResult result) {
|
||||
const char *format;
|
||||
char buf[LINE_MAX];
|
||||
@@ -704,8 +703,10 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
|
||||
if (!format)
|
||||
return;
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
snprintf(buf, sizeof(buf), format, unit_description(u));
|
||||
char_array_0(buf);
|
||||
REENABLE_WARNING;
|
||||
|
||||
if (t == JOB_START) {
|
||||
sd_id128_t mid;
|
||||
@@ -734,7 +735,6 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
|
||||
"MESSAGE=%s", buf,
|
||||
NULL);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
|
||||
Unit *u;
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
|
||||
#include "kmod-setup.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
|
||||
static void systemd_kmod_log(
|
||||
void *data,
|
||||
int priority,
|
||||
@@ -42,11 +39,11 @@ static void systemd_kmod_log(
|
||||
va_list args) {
|
||||
|
||||
/* library logging is enabled at debug only */
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
log_metav(LOG_DEBUG, file, line, fn, format, args);
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
static bool cmdline_check_kdbus(void) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
|
||||
|
||||
@@ -1140,8 +1140,6 @@ _pure_ static const char *unit_get_status_message_format_try_harder(Unit *u, Job
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
static void unit_status_print_starting_stopping(Unit *u, JobType t) {
|
||||
const char *format;
|
||||
|
||||
@@ -1154,12 +1152,11 @@ static void unit_status_print_starting_stopping(Unit *u, JobType t) {
|
||||
if (!format)
|
||||
return;
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
unit_status_printf(u, "", format);
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
|
||||
const char *format;
|
||||
char buf[LINE_MAX];
|
||||
@@ -1179,8 +1176,10 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
|
||||
if (!format)
|
||||
return;
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
snprintf(buf, sizeof(buf), format, unit_description(u));
|
||||
char_array_0(buf);
|
||||
REENABLE_WARNING;
|
||||
|
||||
mid = t == JOB_START ? SD_MESSAGE_UNIT_STARTING :
|
||||
t == JOB_STOP ? SD_MESSAGE_UNIT_STOPPING :
|
||||
@@ -1192,7 +1191,6 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
|
||||
"MESSAGE=%s", buf,
|
||||
NULL);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* Errors:
|
||||
* -EBADR: This unit type does not support starting.
|
||||
@@ -2525,12 +2523,11 @@ int unit_coldplug(Unit *u) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
void unit_status_printf(Unit *u, const char *status, const char *unit_status_msg_format) {
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
manager_status_printf(u->manager, false, status, unit_status_msg_format, unit_description(u));
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
bool unit_need_daemon_reload(Unit *u) {
|
||||
_cleanup_strv_free_ char **t = NULL;
|
||||
|
||||
@@ -27,14 +27,15 @@
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
void microhttpd_logger(void *arg, const char *fmt, va_list ap) {
|
||||
_cleanup_free_ char *f;
|
||||
_cleanup_free_ char *f = NULL;
|
||||
|
||||
if (asprintf(&f, "microhttpd: %s", fmt) <= 0) {
|
||||
log_oom();
|
||||
return;
|
||||
}
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
log_metav(LOG_INFO, NULL, 0, NULL, f, ap);
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
@@ -48,13 +48,13 @@ static const char conf_file_dirs[] =
|
||||
#endif
|
||||
;
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
static void systemd_kmod_log(void *data, int priority, const char *file, int line,
|
||||
const char *fn, const char *format, va_list args) {
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
static int add_modules(const char *p) {
|
||||
_cleanup_strv_free_ char **k = NULL;
|
||||
|
||||
@@ -703,22 +703,21 @@ int log_meta_object(
|
||||
return r;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
static void log_assert(int level, const char *text, const char *file, int line, const char *func, const char *format) {
|
||||
static char buffer[LINE_MAX];
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level))
|
||||
return;
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
snprintf(buffer, sizeof(buffer), format, text, file, line, func);
|
||||
REENABLE_WARNING;
|
||||
|
||||
char_array_0(buffer);
|
||||
log_abort_msg = buffer;
|
||||
|
||||
log_dispatch(level, file, line, func, NULL, NULL, buffer);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
noreturn void log_assert_failed(const char *text, const char *file, int line, const char *func) {
|
||||
log_assert(LOG_CRIT, text, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Aborting.");
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
_Pragma("GCC diagnostic push"); \
|
||||
_Pragma("GCC diagnostic ignored \"-Wdeclaration-after-statement\"")
|
||||
|
||||
#define DISABLE_WARNING_FORMAT_NONLITERAL \
|
||||
_Pragma("GCC diagnostic push"); \
|
||||
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
|
||||
|
||||
#define REENABLE_WARNING \
|
||||
_Pragma("GCC diagnostic pop")
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
#define LONG(x) ((x)/BITS_PER_LONG)
|
||||
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/*
|
||||
* Read a capability attribute and return bitmask.
|
||||
* @param dev udev_device
|
||||
@@ -84,11 +82,13 @@ static void get_cap_mask(struct udev_device *dev,
|
||||
/* skip over leading zeros */
|
||||
while (bitmask[val-1] == 0 && val > 0)
|
||||
--val;
|
||||
for (i = 0; i < val; ++i)
|
||||
for (i = 0; i < val; ++i) {
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
log_debug(text, i * BITS_PER_LONG, bitmask[i]);
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* pointer devices */
|
||||
static void test_pointers (struct udev_device *dev,
|
||||
|
||||
Reference in New Issue
Block a user