diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/log.c | 54 | ||||
-rw-r--r-- | src/shared/macro.h | 61 | ||||
-rw-r--r-- | src/shared/util.c | 16 |
3 files changed, 82 insertions, 49 deletions
diff --git a/src/shared/log.c b/src/shared/log.c index 2bac998bcd..b730ac921a 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -871,27 +871,47 @@ int log_set_max_level_from_string(const char *e) { return 0; } +static int parse_proc_cmdline_item(const char *key, const char *value) { + + /* + * The systemd.log_xyz= settings are parsed by all tools, and + * so is "debug". + * + * However, "quiet" is only parsed by PID 1! + */ + + if (streq(key, "debug") && !value) + log_set_max_level(LOG_DEBUG); + + else if (streq(key, "systemd.log_target") && value) { + + if (log_set_target_from_string(value) < 0) + log_warning("Failed to parse log target '%s'. Ignoring.", value); + + } else if (streq(key, "systemd.log_level") && value) { + + if (log_set_max_level_from_string(value) < 0) + log_warning("Failed to parse log level '%s'. Ignoring.", value); + + } else if (streq(key, "systemd.log_color") && value) { + + if (log_show_color_from_string(value) < 0) + log_warning("Failed to parse log color setting '%s'. Ignoring.", value); + + } else if (streq(key, "systemd.log_location") && value) { + + if (log_show_location_from_string(value) < 0) + log_warning("Failed to parse log location setting '%s'. Ignoring.", value); + } + + return 0; +} + void log_parse_environment(void) { _cleanup_free_ char *line = NULL; const char *e; - int r; - r = proc_cmdline(&line); - if (r < 0) - log_warning("Failed to read /proc/cmdline. Ignoring: %s", strerror(-r)); - else if (r > 0) { - const char *word, *state; - size_t l; - - FOREACH_WORD_QUOTED(word, l, line, state) { - if (l == 5 && startswith(word, "debug")) { - log_set_max_level(LOG_DEBUG); - break; - } - } - if (!isempty(state)) - log_warning("Trailing garbage and the end of kernel commandline, ignoring."); - } + parse_proc_cmdline(parse_proc_cmdline_item); e = secure_getenv("SYSTEMD_LOG_TARGET"); if (e && log_set_target_from_string(e) < 0) diff --git a/src/shared/macro.h b/src/shared/macro.h index 5619c32e45..179b24c983 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -133,46 +133,55 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { }) #undef MAX -#define MAX(a,b) \ - __extension__ ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a > _b ? _a : _b; \ +#define MAX(a,b) \ + __extension__ ({ \ + const typeof(a) _a = (a); \ + const typeof(b) _b = (b); \ + _a > _b ? _a : _b; \ }) -#define MAX3(x,y,z) \ - __extension__ ({ \ - typeof(x) _c = MAX(x,y); \ - MAX(_c, z); \ +/* evaluates to (void) if _A or _B are not constant or of different types */ +#define CONST_MAX(_A, _B) \ + __extension__ (__builtin_choose_expr( \ + __builtin_constant_p(_A) && \ + __builtin_constant_p(_B) && \ + __builtin_types_compatible_p(typeof(_A), typeof(_B)), \ + ((_A) > (_B)) ? (_A) : (_B), \ + (void)0)) + +#define MAX3(x,y,z) \ + __extension__ ({ \ + const typeof(x) _c = MAX(x,y); \ + MAX(_c, z); \ }) #undef MIN -#define MIN(a,b) \ - __extension__ ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a < _b ? _a : _b; \ +#define MIN(a,b) \ + __extension__ ({ \ + const typeof(a) _a = (a); \ + const typeof(b) _b = (b); \ + _a < _b ? _a : _b; \ }) -#define MIN3(x,y,z) \ - __extension__ ({ \ - typeof(x) _c = MIN(x,y); \ - MIN(_c, z); \ +#define MIN3(x,y,z) \ + __extension__ ({ \ + const typeof(x) _c = MIN(x,y); \ + MIN(_c, z); \ }) -#define LESS_BY(A,B) \ - __extension__ ({ \ - typeof(A) _A = (A); \ - typeof(B) _B = (B); \ - _A > _B ? _A - _B : 0; \ +#define LESS_BY(A,B) \ + __extension__ ({ \ + const typeof(A) _A = (A); \ + const typeof(B) _B = (B); \ + _A > _B ? _A - _B : 0; \ }) #ifndef CLAMP #define CLAMP(x, low, high) \ __extension__ ({ \ - typeof(x) _x = (x); \ - typeof(low) _low = (low); \ - typeof(high) _high = (high); \ + const typeof(x) _x = (x); \ + const typeof(low) _low = (low); \ + const typeof(high) _high = (high); \ ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ }) #endif diff --git a/src/shared/util.c b/src/shared/util.c index 0db4bd90e8..18d40f398f 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2084,12 +2084,14 @@ fail: } int release_terminal(void) { - int r = 0; - struct sigaction sa_old, sa_new = { + static const struct sigaction sa_new = { .sa_handler = SIG_IGN, .sa_flags = SA_RESTART, }; - _cleanup_close_ int fd; + + _cleanup_close_ int fd = -1; + struct sigaction sa_old; + int r = 0; fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY|O_CLOEXEC); if (fd < 0) @@ -6868,11 +6870,13 @@ char *tempfn_random(const char *p) { bool is_localhost(const char *hostname) { assert(hostname); - /* This tries to identify local hostnames described in RFC6761 - * plus the redhatism of .localdomain */ + /* This tries to identify local host and domain names + * described in RFC6761 plus the redhatism of .localdomain */ return streq(hostname, "localhost") || streq(hostname, "localhost.") || + streq(hostname, "localdomain.") || + streq(hostname, "localdomain") || endswith(hostname, ".localhost") || endswith(hostname, ".localhost.") || endswith(hostname, ".localdomain") || @@ -6929,4 +6933,4 @@ int is_symlink(const char *path) { return 1; return 0; -}
\ No newline at end of file +} |