summaryrefslogtreecommitdiffstats
path: root/src/core/execute.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-07-11 16:28:08 +0200
committerLennart Poettering <lennart@poettering.net>2024-07-19 11:44:04 +0200
commit27c067ceeb6a6cfdaf40d4d65a82087d21154b26 (patch)
tree0bb573707eedb991a011bdbedbe0ec45a5a9acc6 /src/core/execute.c
parentexec-invoke: handle errno log message writing in write_confirm_error_fd() lik... (diff)
downloadsystemd-27c067ceeb6a6cfdaf40d4d65a82087d21154b26.tar.xz
systemd-27c067ceeb6a6cfdaf40d4d65a82087d21154b26.zip
execute: reorder "destructive" tty reset operations
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).
Diffstat (limited to '')
-rw-r--r--src/core/execute.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/core/execute.c b/src/core/execute.c
index e821133eea..8982af10aa 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -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);