mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
Merge pull request #12411 from keszybz/pr/12394
run: when emitting the calendarspec warning, use red
This commit is contained in:
commit
e95be7def2
@ -474,6 +474,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
int r, n;
|
||||
int epoll_fd = -1;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -2104,6 +2104,7 @@ static int run(int argc, char *argv[]) {
|
||||
setlocale(LC_ALL, "");
|
||||
setlocale(LC_NUMERIC, "C"); /* we want to format/parse floats in C style */
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -158,6 +158,7 @@ static int run(int argc, char *argv[]) {
|
||||
char **p;
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -336,7 +336,7 @@ static int write_to_console(
|
||||
|
||||
char location[256], prefix[1 + DECIMAL_STR_MAX(int) + 2];
|
||||
struct iovec iovec[6] = {};
|
||||
bool highlight;
|
||||
const char *on = NULL, *off = NULL;
|
||||
size_t n = 0;
|
||||
|
||||
if (console_fd < 0)
|
||||
@ -347,18 +347,19 @@ static int write_to_console(
|
||||
iovec[n++] = IOVEC_MAKE_STRING(prefix);
|
||||
}
|
||||
|
||||
highlight = LOG_PRI(level) <= LOG_ERR && show_color;
|
||||
if (show_color)
|
||||
get_log_colors(LOG_PRI(level), &on, &off, NULL);
|
||||
|
||||
if (show_location) {
|
||||
(void) snprintf(location, sizeof location, "(%s:%i) ", file, line);
|
||||
iovec[n++] = IOVEC_MAKE_STRING(location);
|
||||
}
|
||||
|
||||
if (highlight)
|
||||
iovec[n++] = IOVEC_MAKE_STRING(ANSI_HIGHLIGHT_RED);
|
||||
if (on)
|
||||
iovec[n++] = IOVEC_MAKE_STRING(on);
|
||||
iovec[n++] = IOVEC_MAKE_STRING(buffer);
|
||||
if (highlight)
|
||||
iovec[n++] = IOVEC_MAKE_STRING(ANSI_NORMAL);
|
||||
if (off)
|
||||
iovec[n++] = IOVEC_MAKE_STRING(off);
|
||||
iovec[n++] = IOVEC_MAKE_STRING("\n");
|
||||
|
||||
if (writev(console_fd, iovec, n) < 0) {
|
||||
|
@ -1310,3 +1310,41 @@ int vt_release(int fd, bool restore) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void get_log_colors(int priority, const char **on, const char **off, const char **highlight) {
|
||||
/* Note that this will initialize output variables only when there's something to output.
|
||||
* The caller must pre-initalize to "" or NULL as appropriate. */
|
||||
|
||||
if (priority <= LOG_ERR) {
|
||||
if (on)
|
||||
*on = ANSI_HIGHLIGHT_RED;
|
||||
if (off)
|
||||
*off = ANSI_NORMAL;
|
||||
if (highlight)
|
||||
*highlight = ANSI_HIGHLIGHT;
|
||||
|
||||
} else if (priority <= LOG_WARNING) {
|
||||
if (on)
|
||||
*on = ANSI_HIGHLIGHT_YELLOW;
|
||||
if (off)
|
||||
*off = ANSI_NORMAL;
|
||||
if (highlight)
|
||||
*highlight = ANSI_HIGHLIGHT;
|
||||
|
||||
} else if (priority <= LOG_NOTICE) {
|
||||
if (on)
|
||||
*on = ANSI_HIGHLIGHT;
|
||||
if (off)
|
||||
*off = ANSI_NORMAL;
|
||||
if (highlight)
|
||||
*highlight = ANSI_HIGHLIGHT_RED;
|
||||
|
||||
} else if (priority >= LOG_DEBUG) {
|
||||
if (on)
|
||||
*on = ANSI_GREY;
|
||||
if (off)
|
||||
*off = ANSI_NORMAL;
|
||||
if (highlight)
|
||||
*highlight = ANSI_HIGHLIGHT_RED;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "macro.h"
|
||||
@ -158,3 +159,5 @@ int vt_default_utf8(void);
|
||||
int vt_reset_keyboard(int fd);
|
||||
int vt_restore(int fd);
|
||||
int vt_release(int fd, bool restore_vt);
|
||||
|
||||
void get_log_colors(int priority, const char **on, const char **off, const char **highlight);
|
||||
|
@ -2508,6 +2508,7 @@ static int busctl_main(int argc, char *argv[]) {
|
||||
static int run(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -165,6 +165,7 @@ static void show_cg_info(const char *controller, const char *path) {
|
||||
static int run(int argc, char *argv[]) {
|
||||
int r, output_flags;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -909,6 +909,7 @@ static int run(int argc, char *argv[]) {
|
||||
CGroupMask mask;
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -1069,6 +1069,7 @@ static int run(int argc, char *argv[]) {
|
||||
int r, units_active;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -639,6 +639,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
static int run(int argc, char *argv[]) {
|
||||
int r, k, n_found = 0;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -128,6 +128,7 @@ static int run(int argc, char *argv[]) {
|
||||
* to detect whether we are being run in a virtualized
|
||||
* environment or not */
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -159,6 +159,7 @@ static int run(int argc, char *argv[]) {
|
||||
char **i;
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -432,6 +432,7 @@ static int run(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -155,6 +155,7 @@ static int id128_main(int argc, char *argv[]) {
|
||||
static int run(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -127,6 +127,7 @@ static int run(int argc, char *argv[]) {
|
||||
_cleanup_close_ int outfd = -1, errfd = -1, saved_stderr = -1;
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -2100,6 +2100,7 @@ int main(int argc, char *argv[]) {
|
||||
int n_shown = 0, r, poll_fd = -1;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -510,6 +510,7 @@ static int run(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -270,6 +270,7 @@ static int run(int argc, char *argv[]) {
|
||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -1529,6 +1529,7 @@ static int run(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -3100,6 +3100,7 @@ static int run(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -1515,6 +1515,7 @@ static int run(int argc, char* argv[]) {
|
||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -1128,6 +1128,7 @@ static void warn_networkd_missing(void) {
|
||||
static int run(int argc, char* argv[]) {
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -151,6 +151,7 @@ static int run(int argc, char* argv[]) {
|
||||
unsigned i = 0;
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -171,6 +171,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
static int run(int argc, char* argv[]) {
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -956,6 +956,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
int r;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -3137,6 +3137,7 @@ static int run(int argc, char **argv) {
|
||||
int r;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -390,11 +390,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
r = calendar_spec_next_usec(cs, now(CLOCK_REALTIME), NULL);
|
||||
if (r == -ENOENT)
|
||||
/* The calendar event is in the past - let's warn about this, but install it
|
||||
* anyway as it is. The service manager will trigger the service right-away
|
||||
* then, but everything is discoverable as usual. Moreover, the server side
|
||||
* might have a different clock or timezone than we do, hence it should
|
||||
* decide when or whether to run something. */
|
||||
/* The calendar event is in the past — let's warn about this, but install it
|
||||
* anyway as is. The service manager will trigger the service right away.
|
||||
* Moreover, the server side might have a different clock or timezone than we
|
||||
* do, hence it should decide when or whether to run something. */
|
||||
log_warning("Specified calendar expression is in the past, proceeding anyway.");
|
||||
else if (r < 0)
|
||||
return log_error_errno(r, "Failed to calculate next time calendar expression elapses: %m");
|
||||
@ -1653,6 +1652,7 @@ static int run(int argc, char* argv[]) {
|
||||
_cleanup_free_ char *description = NULL;
|
||||
int r, retval = EXIT_SUCCESS;
|
||||
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
@ -163,21 +163,8 @@ static bool print_multiline(
|
||||
bool ellipsized = false;
|
||||
int line = 0;
|
||||
|
||||
if (flags & OUTPUT_COLOR) {
|
||||
if (priority <= LOG_ERR) {
|
||||
color_on = ANSI_HIGHLIGHT_RED;
|
||||
color_off = ANSI_NORMAL;
|
||||
highlight_on = ANSI_HIGHLIGHT;
|
||||
} else if (priority <= LOG_NOTICE) {
|
||||
color_on = ANSI_HIGHLIGHT;
|
||||
color_off = ANSI_NORMAL;
|
||||
highlight_on = ANSI_HIGHLIGHT_RED;
|
||||
} else if (priority >= LOG_DEBUG) {
|
||||
color_on = ANSI_GREY;
|
||||
color_off = ANSI_NORMAL;
|
||||
highlight_on = ANSI_HIGHLIGHT_RED;
|
||||
}
|
||||
}
|
||||
if (flags & OUTPUT_COLOR)
|
||||
get_log_colors(priority, &color_on, &color_off, &highlight_on);
|
||||
|
||||
/* A special case: make sure that we print a newline when
|
||||
the message is empty. */
|
||||
|
@ -866,6 +866,7 @@ static int run(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
log_show_color(true);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user