From a0f6b6813554e5c72302d5337570787f9b85692b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Feb 2024 12:54:03 +0100 Subject: [PATCH 1/2] dev-setup: normalize logging around lock_dev_console() Previously this function would log loudly in some cases but not in others. Clean this up, and dont log at all, matching our coding style which says we should either log in all error cases or in none. Both callers of this function do logging already, hence no need to duplicate it here. --- src/shared/dev-setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index 08fdd605704..3592b0a6505 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -28,7 +28,7 @@ int lock_dev_console(void) { r = lock_generic(fd, LOCK_BSD, LOCK_EX); if (r < 0) - return log_error_errno(r, "Failed to lock /dev/console: %m"); + return r; return TAKE_FD(fd); } From f244e7a7ead3194807a367a986f2d8427b3b0888 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Feb 2024 12:55:27 +0100 Subject: [PATCH 2/2] pid1,vconsole-setup: gracefully handle if /dev/vconsole is not accessible due to ENODEV I think this is generally the right thing to do and is just an extension of the existing ENOENT check. Prompted by: #31257 --- src/core/execute.c | 2 ++ src/vconsole/vconsole-setup.c | 12 ++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index b91513c5da8..fb3e9b79cbe 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -163,6 +163,8 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p) lock_fd = lock_dev_console(); if (ERRNO_IS_NEG_PRIVILEGE(lock_fd)) log_debug_errno(lock_fd, "No privileges to lock /dev/console, proceeding without: %m"); + else if (ERRNO_IS_NEG_DEVICE_ABSENT(lock_fd)) + log_debug_errno(lock_fd, "Device /dev/console does not exist, proceeding without locking it: %m"); else if (lock_fd < 0) return (void) log_debug_errno(lock_fd, "Failed to lock /dev/console: %m"); diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 83e43b16ff9..554d00e5b75 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -624,14 +624,10 @@ static int run(int argc, char **argv) { /* Take lock around the remaining operation to avoid being interrupted by a tty reset operation * performed for services with TTYVHangup=yes. */ lock_fd = lock_dev_console(); - if (lock_fd < 0) { - log_full_errno(lock_fd == -ENOENT ? LOG_DEBUG : LOG_ERR, - lock_fd, - "Failed to lock /dev/console%s: %m", - lock_fd == -ENOENT ? ", ignoring" : ""); - if (lock_fd != -ENOENT) - return lock_fd; - } + if (ERRNO_IS_NEG_DEVICE_ABSENT(lock_fd)) + log_debug_errno(lock_fd, "Device /dev/console does not exist, proceeding without locking it: %m"); + else if (lock_fd < 0) + return log_error_errno(lock_fd, "Failed to lock /dev/console: %m"); (void) toggle_utf8_sysfs(utf8); (void) toggle_utf8_vc(vc, fd, utf8);