]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
execute: handle gracefully if we cannot lock /dev/console when resetting tty due...
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Dec 2023 15:37:18 +0000 (16:37 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 Dec 2023 13:02:12 +0000 (22:02 +0900)
This is the common case in --user instances, hence handle this
gracefully.

This should be safe since user instances won't get access to
/dev/console-related ttys anyway, but only their own ptys.

src/core/execute.c

index 1e48e88ee8c01a5463f1e002d54898b80a1073cf..455d7e80132802b28d28d7468bedc8c071fa2a03 100644 (file)
@@ -161,9 +161,10 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p)
          * systemd-vconsole-setup.service also takes the lock to avoid being interrupted. We open a new fd
          * that will be closed automatically, and operate on it for convenience. */
         lock_fd = lock_dev_console();
-        if (lock_fd < 0)
-                return (void) log_debug_errno(lock_fd,
-                                              "Failed to lock /dev/console: %m");
+        if (ERRNO_IS_NEG_PRIVILEGE(lock_fd))
+                log_debug_errno(lock_fd, "No privileges to lock /dev/console, proceeding without: %m");
+        else if (lock_fd < 0)
+                return (void) log_debug_errno(lock_fd, "Failed to lock /dev/console: %m");
 
         if (context->tty_vhangup)
                 (void) terminal_vhangup_fd(fd);
@@ -1453,7 +1454,7 @@ void exec_context_revert_tty(ExecContext *c) {
         assert(c);
 
         /* First, reset the TTY (possibly kicking everybody else from the TTY) */
-        exec_context_tty_reset(c, NULL);
+        exec_context_tty_reset(c, /* parameters= */ NULL);
 
         /* And then undo what chown_terminal() did earlier. Note that we only do this if we have a path
          * configured. If the TTY was passed to us as file descriptor we assume the TTY is opened and managed