1
0
mirror of https://github.com/systemd/systemd synced 2025-09-26 23:34:44 +02:00

Compare commits

..

No commits in common. "0727a75a3bd321dce2e8f8ed66f845c901cd9cf5" and "9e36b885b894f1b2a53fa234a238e736582021c4" have entirely different histories.

6 changed files with 45 additions and 81 deletions

View File

@ -1,13 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once #pragma once
#include <sys/types.h>
#include "macro.h"
int asynchronous_job(void* (*func)(void *p), void *arg); int asynchronous_job(void* (*func)(void *p), void *arg);
int asynchronous_sync(pid_t *ret_pid); int asynchronous_sync(pid_t *ret_pid);
int asynchronous_close(int fd); int asynchronous_close(int fd);
DEFINE_TRIVIAL_CLEANUP_FUNC(int, asynchronous_close);

View File

@ -51,7 +51,7 @@ static int journal_fd = -1;
static bool syslog_is_stream = false; static bool syslog_is_stream = false;
static int show_color = -1; /* tristate */ static bool show_color = false;
static bool show_location = false; static bool show_location = false;
static bool show_time = false; static bool show_time = false;
static bool show_tid = false; static bool show_tid = false;
@ -387,10 +387,11 @@ static int write_to_console(
iovec[n++] = IOVEC_MAKE_STRING(prefix); iovec[n++] = IOVEC_MAKE_STRING(prefix);
} }
if (show_time && if (show_time) {
format_timestamp(header_time, sizeof(header_time), now(CLOCK_REALTIME))) { if (format_timestamp(header_time, sizeof(header_time), now(CLOCK_REALTIME))) {
iovec[n++] = IOVEC_MAKE_STRING(header_time); iovec[n++] = IOVEC_MAKE_STRING(header_time);
iovec[n++] = IOVEC_MAKE_STRING(" "); iovec[n++] = IOVEC_MAKE_STRING(" ");
}
} }
if (show_tid) { if (show_tid) {
@ -398,12 +399,12 @@ static int write_to_console(
iovec[n++] = IOVEC_MAKE_STRING(tid_string); iovec[n++] = IOVEC_MAKE_STRING(tid_string);
} }
if (log_get_show_color()) if (show_color)
get_log_colors(LOG_PRI(level), &on, &off, NULL); get_log_colors(LOG_PRI(level), &on, &off, NULL);
if (show_location) { if (show_location) {
const char *lon = "", *loff = ""; const char *lon = "", *loff = "";
if (log_get_show_color()) { if (show_color) {
lon = ANSI_HIGHLIGHT_YELLOW4; lon = ANSI_HIGHLIGHT_YELLOW4;
loff = ANSI_NORMAL; loff = ANSI_NORMAL;
} }
@ -1221,7 +1222,7 @@ void log_show_color(bool b) {
} }
bool log_get_show_color(void) { bool log_get_show_color(void) {
return show_color > 0; /* Defaults to false. */ return show_color;
} }
void log_show_location(bool b) { void log_show_location(bool b) {
@ -1484,9 +1485,7 @@ void log_setup_service(void) {
void log_setup_cli(void) { void log_setup_cli(void) {
/* Sets up logging the way it is most appropriate for running a program as a CLI utility. */ /* Sets up logging the way it is most appropriate for running a program as a CLI utility. */
log_set_target(LOG_TARGET_AUTO); log_show_color(true);
log_parse_environment_cli(); log_parse_environment_cli();
(void) log_open(); (void) log_open();
if (log_on_console() && show_color < 0)
log_show_color(true);
} }

View File

@ -1836,10 +1836,6 @@ int unit_pick_cgroup_path(Unit *u) {
return 0; return 0;
} }
static int cg_v1_errno_to_log_level(int r) {
return r == -EROFS ? LOG_DEBUG : LOG_WARNING;
}
static int unit_update_cgroup( static int unit_update_cgroup(
Unit *u, Unit *u,
CGroupMask target_mask, CGroupMask target_mask,
@ -1897,30 +1893,16 @@ static int unit_update_cgroup(
* We perform migration also with whole slices for cases when users don't care about leave * We perform migration also with whole slices for cases when users don't care about leave
* granularity. Since delegated_mask is subset of target mask, we won't trim slice subtree containing * granularity. Since delegated_mask is subset of target mask, we won't trim slice subtree containing
* delegated units. * delegated units.
*
* If we're in an nspawn container and using legacy cgroups, the controller hierarchies are mounted
* read-only into the container. We skip migration/trim in this scenario since it would fail
* regardless with noisy "Read-only filesystem" warnings.
*/ */
if (cg_all_unified() == 0) { if (cg_all_unified() == 0) {
r = cg_migrate_v1_controllers(u->manager->cgroup_supported, migrate_mask, u->cgroup_path, migrate_callback, u); r = cg_migrate_v1_controllers(u->manager->cgroup_supported, migrate_mask, u->cgroup_path, migrate_callback, u);
if (r < 0) if (r < 0)
log_unit_full_errno( log_unit_warning_errno(u, r, "Failed to migrate controller cgroups from %s, ignoring: %m", u->cgroup_path);
u,
cg_v1_errno_to_log_level(r),
r,
"Failed to migrate controller cgroups from %s, ignoring: %m",
u->cgroup_path);
is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE); is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE);
r = cg_trim_v1_controllers(u->manager->cgroup_supported, ~target_mask, u->cgroup_path, !is_root_slice); r = cg_trim_v1_controllers(u->manager->cgroup_supported, ~target_mask, u->cgroup_path, !is_root_slice);
if (r < 0) if (r < 0)
log_unit_full_errno( log_unit_warning_errno(u, r, "Failed to delete controller cgroups %s, ignoring: %m", u->cgroup_path);
u,
cg_v1_errno_to_log_level(r),
r,
"Failed to delete controller cgroups %s, ignoring: %m",
u->cgroup_path);
} }
/* Set attributes */ /* Set attributes */

View File

@ -2937,10 +2937,8 @@ int manager_loop(Manager *m) {
usec_t wait_usec, watchdog_usec; usec_t wait_usec, watchdog_usec;
watchdog_usec = manager_get_watchdog(m, WATCHDOG_RUNTIME); watchdog_usec = manager_get_watchdog(m, WATCHDOG_RUNTIME);
if (m->runtime_watchdog_running) if (timestamp_is_set(watchdog_usec))
(void) watchdog_ping(); (void) watchdog_ping();
else if (timestamp_is_set(watchdog_usec))
manager_retry_runtime_watchdog(m);
if (!ratelimit_below(&rl)) { if (!ratelimit_below(&rl)) {
/* Yay, something is going seriously wrong, pause a little */ /* Yay, something is going seriously wrong, pause a little */
@ -3410,18 +3408,14 @@ void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout) {
if (t == WATCHDOG_RUNTIME) if (t == WATCHDOG_RUNTIME)
if (!timestamp_is_set(m->watchdog_overridden[WATCHDOG_RUNTIME])) { if (!timestamp_is_set(m->watchdog_overridden[WATCHDOG_RUNTIME])) {
if (timestamp_is_set(timeout)) { if (timestamp_is_set(timeout))
r = watchdog_set_timeout(&timeout); r = watchdog_set_timeout(&timeout);
else
if (r >= 0)
m->runtime_watchdog_running = true;
} else {
watchdog_close(true); watchdog_close(true);
m->runtime_watchdog_running = false;
}
} }
m->watchdog[t] = timeout; if (r >= 0)
m->watchdog[t] = timeout;
} }
int manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout) { int manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout) {
@ -3439,36 +3433,18 @@ int manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout) {
usec_t *p; usec_t *p;
p = timestamp_is_set(timeout) ? &timeout : &m->watchdog[t]; p = timestamp_is_set(timeout) ? &timeout : &m->watchdog[t];
if (timestamp_is_set(*p)) { if (timestamp_is_set(*p))
r = watchdog_set_timeout(p); r = watchdog_set_timeout(p);
else
if (r >= 0)
m->runtime_watchdog_running = true;
} else {
watchdog_close(true); watchdog_close(true);
m->runtime_watchdog_running = false;
}
} }
m->watchdog_overridden[t] = timeout; if (r >= 0)
m->watchdog_overridden[t] = timeout;
return 0; return 0;
} }
void manager_retry_runtime_watchdog(Manager *m) {
int r = 0;
assert(m);
if (timestamp_is_set(m->watchdog_overridden[WATCHDOG_RUNTIME]))
r = watchdog_set_timeout(&m->watchdog_overridden[WATCHDOG_RUNTIME]);
else
r = watchdog_set_timeout(&m->watchdog[WATCHDOG_RUNTIME]);
if (r >= 0)
m->runtime_watchdog_running = true;
}
static void manager_deserialize_uid_refs_one_internal( static void manager_deserialize_uid_refs_one_internal(
Manager *m, Manager *m,
Hashmap** uid_refs, Hashmap** uid_refs,

View File

@ -241,8 +241,6 @@ struct Manager {
usec_t watchdog[_WATCHDOG_TYPE_MAX]; usec_t watchdog[_WATCHDOG_TYPE_MAX];
usec_t watchdog_overridden[_WATCHDOG_TYPE_MAX]; usec_t watchdog_overridden[_WATCHDOG_TYPE_MAX];
bool runtime_watchdog_running; /* Whether the runtime HW watchdog was started, so we know if we still need to get the real timeout from the hardware */
dual_timestamp timestamps[_MANAGER_TIMESTAMP_MAX]; dual_timestamp timestamps[_MANAGER_TIMESTAMP_MAX];
/* Data specific to the device subsystem */ /* Data specific to the device subsystem */
@ -564,7 +562,6 @@ ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s);
usec_t manager_get_watchdog(Manager *m, WatchdogType t); usec_t manager_get_watchdog(Manager *m, WatchdogType t);
void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout); void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout);
int manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout); int manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout);
void manager_retry_runtime_watchdog(Manager *m);
const char* oom_policy_to_string(OOMPolicy i) _const_; const char* oom_policy_to_string(OOMPolicy i) _const_;
OOMPolicy oom_policy_from_string(const char *s) _pure_; OOMPolicy oom_policy_from_string(const char *s) _pure_;

View File

@ -8,12 +8,12 @@
#include "sd-messages.h" #include "sd-messages.h"
#include "alloc-util.h" #include "alloc-util.h"
#include "async.h"
#include "fd-util.h" #include "fd-util.h"
#include "logind-button.h" #include "logind-button.h"
#include "missing_input.h" #include "missing_input.h"
#include "string-util.h" #include "string-util.h"
#include "util.h" #include "util.h"
#include "async.h"
#define CONST_MAX5(a, b, c, d, e) CONST_MAX(CONST_MAX(a, b), CONST_MAX(CONST_MAX(c, d), e)) #define CONST_MAX5(a, b, c, d, e) CONST_MAX(CONST_MAX(a, b), CONST_MAX(CONST_MAX(c, d), e))
@ -60,7 +60,11 @@ void button_free(Button *b) {
sd_event_source_unref(b->io_event_source); sd_event_source_unref(b->io_event_source);
sd_event_source_unref(b->check_event_source); sd_event_source_unref(b->check_event_source);
asynchronous_close(b->fd); if (b->fd >= 0)
/* If the device has been unplugged close() returns
* ENODEV, let's ignore this, hence we don't use
* safe_close() */
(void) asynchronous_close(b->fd);
free(b->name); free(b->name);
free(b->seat); free(b->seat);
@ -68,9 +72,19 @@ void button_free(Button *b) {
} }
int button_set_seat(Button *b, const char *sn) { int button_set_seat(Button *b, const char *sn) {
assert(b); char *s;
return free_and_strdup(&b->seat, sn); assert(b);
assert(sn);
s = strdup(sn);
if (!s)
return -ENOMEM;
free(b->seat);
b->seat = s;
return 0;
} }
static void button_lid_switch_handle_action(Manager *manager, bool is_edge) { static void button_lid_switch_handle_action(Manager *manager, bool is_edge) {
@ -313,14 +327,14 @@ static int button_set_mask(const char *name, int fd) {
} }
int button_open(Button *b) { int button_open(Button *b) {
_cleanup_(asynchronous_closep) int fd = -1; _cleanup_close_ int fd = -1;
const char *p; const char *p;
char name[256]; char name[256];
int r; int r;
assert(b); assert(b);
b->fd = asynchronous_close(b->fd); b->fd = safe_close(b->fd);
p = strjoina("/dev/input/", b->name); p = strjoina("/dev/input/", b->name);
@ -331,10 +345,12 @@ int button_open(Button *b) {
r = button_suitable(fd); r = button_suitable(fd);
if (r < 0) if (r < 0)
return log_warning_errno(r, "Failed to determine whether input device %s is relevant to us: %m", p); return log_warning_errno(r, "Failed to determine whether input device %s is relevant to us: %m", p);
if (r == 0) if (r == 0) {
b->fd = TAKE_FD(fd);
return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL), return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL),
"Device %s does not expose keys or switches relevant to us, ignoring.", p); "Device %s does not expose keys or switches relevant to us, ignoring.", p);
}
if (ioctl(fd, EVIOCGNAME(sizeof name), name) < 0) if (ioctl(fd, EVIOCGNAME(sizeof name), name) < 0)
return log_error_errno(errno, "Failed to get input name for %s: %m", p); return log_error_errno(errno, "Failed to get input name for %s: %m", p);