]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
execute: reorder "destructive" tty reset operations
authorLennart Poettering <lennart@poettering.net>
Thu, 11 Jul 2024 14:28:08 +0000 (16:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 Jul 2024 09:44:04 +0000 (11:44 +0200)
Let's make sure to first issue the non-destructive operations, then
issue the hangup (for which we need the fd), then try to disallocate the
device (for which we don't need it anymore).

src/core/execute.c

index e821133eea1fdb4a51d86ff44c34a9048dc72e1f..8982af10aa2a19df7d5f6b46d9929f5358c74606 100644 (file)
@@ -145,7 +145,7 @@ int exec_context_apply_tty_size(
 
 void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p) {
         _cleanup_close_ int _fd = -EBADF, lock_fd = -EBADF;
-        int fd;
+        int fd, r;
 
         assert(context);
 
@@ -172,13 +172,19 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p)
         else if (lock_fd < 0)
                 log_warning_errno(lock_fd, "Failed to lock /dev/console, proceeding without lock: %m");
 
-        if (context->tty_vhangup)
-                (void) terminal_vhangup_fd(fd);
-
         if (context->tty_reset)
                 (void) terminal_reset_defensive(fd, /* switch_to_text= */ true);
 
-        (void) exec_context_apply_tty_size(context, fd, fd, path);
+        r = exec_context_apply_tty_size(context, fd, fd, path);
+        if (r < 0)
+                log_debug_errno(r, "Failed to configure TTY dimensions, ignoring: %m");
+
+        if (context->tty_vhangup)
+                (void) terminal_vhangup_fd(fd);
+
+        /* We don't need the fd anymore now, and it potentially points to a hungup TTY anyway, let's close it
+         * hence. */
+        _fd = safe_close(_fd);
 
         if (context->tty_vt_disallocate && path)
                 (void) vt_disallocate(path);