aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-12-26 00:29:40 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-21 10:44:04 +0000
commitce90480011c9d78275a069e0514e9a03813edffc (patch)
tree1cb7f5dd42d7469ffdede953b70e8fb35453cf60
parentreaper: add optional callback (diff)
terminal: shutdown (or --hold) when the client process terminates
Shutdown the terminal when the client process terminates, not when the ptmx file descriptor is closed. This fixes an issue where the terminal remains running after the client process has terminated, if it spawned child processes that inherited the ptmx file descriptor.
-rw-r--r--CHANGELOG.md5
-rw-r--r--pgo/pgo.c4
-rw-r--r--terminal.c25
3 files changed, 28 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ec039ae..5f174cd9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,11 @@
### Deprecated
### Removed
### Fixed
+
+* Exit when the client application terminates, not when the TTY file
+ descriptor is closed.
+
+
### Security
### Contributors
diff --git a/pgo/pgo.c b/pgo/pgo.c
index 7874cc8d..120b8628 100644
--- a/pgo/pgo.c
+++ b/pgo/pgo.c
@@ -13,6 +13,7 @@
#include "async.h"
#include "config.h"
+#include "reaper.h"
#include "sixel.h"
#include "user-notification.h"
#include "vt.h"
@@ -134,6 +135,9 @@ notify_notify(const struct terminal *term, const char *title, const char *body)
{
}
+void reaper_add(struct reaper *reaper, pid_t pid, reaper_cb cb, void *cb_data) {}
+
+
int
main(int argc, const char *const *argv)
{
diff --git a/terminal.c b/terminal.c
index 208c8700..78969e9e 100644
--- a/terminal.c
+++ b/terminal.c
@@ -314,12 +314,8 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
}
if (hup) {
- if (term->conf->hold_at_exit) {
- fdm_del(fdm, fd);
- term->ptmx = -1;
- return true;
- } else
- return term_shutdown(term);
+ fdm_del(fdm, fd);
+ term->ptmx = -1;
}
return true;
@@ -954,6 +950,21 @@ load_fonts_from_conf(struct terminal *term)
return reload_fonts(term);
}
+static bool
+slave_died(struct reaper *reaper, pid_t pid, void *data)
+{
+ struct terminal *term = data;
+ LOG_DBG("slave (PID=%u) died", pid);
+
+ if (term->conf->hold_at_exit) {
+ fdm_del(term->fdm, term->ptmx);
+ term->ptmx = -1;
+ return true;
+ }
+
+ return term_shutdown(term);
+}
+
struct terminal *
term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
struct wayland *wayl, const char *foot_exe, const char *cwd,
@@ -1159,6 +1170,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
goto err;
}
+ reaper_add(term->reaper, term->slave, &slave_died, term);
+
/* Guess scale; we're not mapped yet, so we don't know on which
* output we'll be. Pick highest scale we find for now */
tll_foreach(term->wl->monitors, it) {