aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-09-23 18:24:04 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-09-23 21:02:25 +0000
commitaa10b1d2da3ecf9672ae915a49073bd30ee0a785 (patch)
treea1816d96cf875f7208fb518172a5a92a512fe3e4 /terminal.c
parentMerge branch 'nightfly-and-moonfly' (diff)
Add support for creating utmp records
This patch adds support for creating utmp records using the ‘utempter’ helper binary from the ‘libutempter’ package. * New config option ‘main.utempter’ * New meson command line option, -Ddefault-utempter-path. Defaults to auto-detecting the path. The default value of the new ‘main.utempter’ config option depends on the meson command line option ‘-Ddefault-utempter-path’. If ‘main.utempter’ is *not* set to ‘none’, foot will try to execute the utempter helper binary to create utmp records when a new terminal is instantiated. The record is removed when the terminal instance is destroyed.
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/terminal.c b/terminal.c
index 3445b89f..4c9bf3db 100644
--- a/terminal.c
+++ b/terminal.c
@@ -203,6 +203,30 @@ fdm_ptmx_out(struct fdm *fdm, int fd, int events, void *data)
return true;
}
+static bool
+add_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx)
+{
+ if (ptmx < 0)
+ return true;
+ if (conf->utempter_path == NULL)
+ return true;
+
+ char *const argv[] = {conf->utempter_path, "add", NULL};
+ return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL);
+}
+
+static bool
+del_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx)
+{
+ if (ptmx < 0)
+ return true;
+ if (conf->utempter_path == NULL)
+ return true;
+
+ char *const argv[] = {conf->utempter_path, "del", NULL};
+ return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL);
+}
+
#if PTMX_TIMING
static struct timespec last = {0};
#endif
@@ -326,6 +350,7 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
}
if (hup) {
+ del_utmp_record(term->conf, term->reaper, term->ptmx);
fdm_del(fdm, fd);
term->ptmx = -1;
}
@@ -1251,6 +1276,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
}
term->font_line_height = conf->line_height;
+ add_utmp_record(conf, reaper, ptmx);
+
/* Start the slave/client */
if ((term->slave = slave_spawn(
term->ptmx, argc, term->cwd, argv, envp, &conf->env_vars,
@@ -1514,6 +1541,8 @@ term_shutdown(struct terminal *term)
fdm_del(term->fdm, term->blink.fd);
fdm_del(term->fdm, term->flash.fd);
+ del_utmp_record(term->conf, term->reaper, term->ptmx);
+
if (term->window != NULL && term->window->is_configured)
fdm_del(term->fdm, term->ptmx);
else
@@ -1595,6 +1624,8 @@ term_destroy(struct terminal *term)
}
}
+ del_utmp_record(term->conf, term->reaper, term->ptmx);
+
fdm_del(term->fdm, term->selection.auto_scroll.fd);
fdm_del(term->fdm, term->render.app_sync_updates.timer_fd);
fdm_del(term->fdm, term->render.title.timer_fd);