summaryrefslogtreecommitdiffstats
path: root/src/core/execute.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-07-11 11:29:37 +0200
committerLennart Poettering <lennart@poettering.net>2024-07-19 11:44:04 +0200
commit628c214656fada4228b62b1546220ac781002897 (patch)
tree9eacbac233fca033fc4f1857727ae9bba247d6d7 /src/core/execute.c
parentexecute: reorder "destructive" tty reset operations (diff)
downloadsystemd-628c214656fada4228b62b1546220ac781002897.tar.xz
systemd-628c214656fada4228b62b1546220ac781002897.zip
exec-invoke: move terminal initialization a bit
It's a bit confusing, but we actually initialize the terminal twice for each service, potentially. One earlier time, where we might end up firing vhangup() and vt_disallocate(), which is a pretty brutal way to reset things, by disconnecting and possibly invalidating the tty completely. When we do this we do not keep any fd open afterwards, since it quite likely points to a dead connection of a tty. The 2nd time we initialize things when we actually want to use it. The first initialization is hence "destructive" (killing any left-overs from previous uses) the 2nd one "constructive" (preparing things for our new use), if you so will. Let's document this distinction in comments, and let's also move both initializations to exec_invoke(), so that they are easier to see in their symmetric behaviour. Moreover, let's run the tty initialization after we opened both input and output, since we need both for doing the fancy dimension auto init stuff now. Oh, and of course, one thing to mention: we nowadays initialize terminals both with ioctl() and with ansi sequences. But the latter means we need an fd that is open for *write* (since we are *writing* those ansi sequences to the tty). Hence, resetting via the input fd is conceptually wrong, it worked only so far if we had O_RDWR open mode selected)
Diffstat (limited to '')
-rw-r--r--src/core/execute.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/core/execute.c b/src/core/execute.c
index 8982af10aa..dc418fd14c 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -149,6 +149,11 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p)
assert(context);
+ /* Note that this is potentially a "destructive" reset of a TTY device. It's about getting rid of the
+ * remains of previous uses of the TTY. It's *not* about getting things set up for coming uses. We'll
+ * potentially invalidate the TTY here through hangups or VT disallocations, and hence do not keep a
+ * continous fd open. */
+
const char *path = exec_context_tty_path(context);
if (p && p->stdout_fd >= 0 && isatty_safe(p->stdout_fd))