From aa10b1d2da3ecf9672ae915a49073bd30ee0a785 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 23 Sep 2022 20:24:04 +0200 Subject: Add support for creating utmp records MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- terminal.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'terminal.c') 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); -- cgit v1.3