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.
This commit is contained in:
Daniel Eklöf 2022-09-23 20:24:04 +02:00
parent 77b74734a4
commit aa10b1d2da
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
11 changed files with 105 additions and 11 deletions

View file

@ -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);