utmp: rewrite utmp logging

This patch generalizes the utmp support, to not only support
libutempter, but also ulog (and in the future, even more interfaces).

* Rename config option main.utempter to main.utmp-helper
* Add meson option -Dutmp-backend=none|libutempter|ulog|auto
* Rename meson option -Ddefault-utempter-path to -Dutmp-default-helper-path
* utmp is no longer detected at compile time, but at runtime instead.

Meson will configure the following pre-processor macros, based on the
selected utmp backend:

* UTMP_ADD - argument to pass to utmp helper when adding a record (starting foot)
* UTMP_DEL - argument to pass to utmp helper when removing a record (exiting foot)
* UTMP_DEL_HAVE_ARGUMENT - if defined, UTMP_DEL expects an extra argument ($WAYLAND_DISPLAY)
* UTMP_DEFAULT_HELPER_PATH - path to the default utmp helper binary

The documentation has been updated to mention which arguments are
passed to the helper binary.

Closes #1314
This commit is contained in:
Daniel Eklöf 2023-05-17 20:51:40 +02:00
parent a2f765b72a
commit e78319fccd
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
11 changed files with 159 additions and 58 deletions

View file

@ -46,6 +46,9 @@
### Added ### Added
* VT: implemented `XTQMODKEYS` query (`CSI ? Pp m`). * VT: implemented `XTQMODKEYS` query (`CSI ? Pp m`).
* Meson option `utmp-backend=none|libutempter|ulog|auto`. The default
is `auto`, which will select `libutempter` on Linux, `ulog` on
FreeBSD, and `none` for all others.
### Changed ### Changed
@ -54,9 +57,17 @@
`CSI R`. The kitty keyboard protocol originally allowed F3 to be `CSI R`. The kitty keyboard protocol originally allowed F3 to be
encoded as `CSI R`, but this was removed from the specification encoded as `CSI R`, but this was removed from the specification
since `CSI R` conflicts with the _”Cursor Position Report”_. since `CSI R` conflicts with the _”Cursor Position Report”_.
* `[main].utempter` renamed to `[main].utmp-helper`. The old option
name is still recognized, but will log a deprecation warning.
* Meson option `default-utempter-path` renamed to
`utmp-default-helper-path`.
### Deprecated ### Deprecated
* `[main].utempter` option.
### Removed ### Removed
### Fixed ### Fixed

View file

@ -45,7 +45,8 @@ subprojects.
* wayland (_client_ and _cursor_ libraries) * wayland (_client_ and _cursor_ libraries)
* xkbcommon * xkbcommon
* utf8proc (_optional_, needed for grapheme clustering) * utf8proc (_optional_, needed for grapheme clustering)
* libutempter (_optional_, needed for utmp logging) * libutempter (_optional_, needed for utmp logging on Linux)
* ulog (_optional_, needed for utmp logging on FreeBSD)
* [fcft](https://codeberg.org/dnkl/fcft) [^1] * [fcft](https://codeberg.org/dnkl/fcft) [^1]
[^1]: can also be built as subprojects, in which case they are [^1]: can also be built as subprojects, in which case they are
@ -142,17 +143,18 @@ mkdir -p bld/release && cd bld/release
Available compile-time options: Available compile-time options:
| Option | Type | Default | Description | Extra dependencies | | Option | Type | Default | Description | Extra dependencies |
|--------------------------------------|---------|-------------------------|-----------------------------------------------------------|--------------------| |--------------------------------------|---------|-------------------------|---------------------------------------------------------------------------------|---------------------|
| `-Ddocs` | feature | `auto` | Builds and install documentation | scdoc | | `-Ddocs` | feature | `auto` | Builds and install documentation | scdoc |
| `-Dtests` | bool | `true` | Build tests (adds a `ninja test` build target) | none | | `-Dtests` | bool | `true` | Build tests (adds a `ninja test` build target) | None |
| `-Dime` | bool | `true` | Enables IME support | None | | `-Dime` | bool | `true` | Enables IME support | None |
| `-Dgrapheme-clustering` | feature | `auto` | Enables grapheme clustering | libutf8proc | | `-Dgrapheme-clustering` | feature | `auto` | Enables grapheme clustering | libutf8proc |
| `-Dterminfo` | feature | `enabled` | Build and install terminfo files | tic (ncurses) | | `-Dterminfo` | feature | `enabled` | Build and install terminfo files | tic (ncurses) |
| `-Ddefault-terminfo` | string | `foot` | Default value of `TERM` | none | | `-Ddefault-terminfo` | string | `foot` | Default value of `TERM` | None |
| `-Dcustom-terminfo-install-location` | string | `${datadir}/terminfo` | Value to set `TERMINFO` to | None | | `-Dcustom-terminfo-install-location` | string | `${datadir}/terminfo` | Value to set `TERMINFO` to | None |
| `-Dsystemd-units-dir` | string | `${systemduserunitdir}` | Where to install the systemd service files (absolute) | None | | `-Dsystemd-units-dir` | string | `${systemduserunitdir}` | Where to install the systemd service files (absolute) | None |
| `-Ddefault-utempter-path` | feature | `auto` | Default path to utempter binary (none disables default) | libutempter | | `-Dutmp-backend` | combo | `auto` | Which utmp backend to use (`none`, `libutempter`, `ulog` or `auto`) | libutempter or ulog |
| `-Dutmp-default-helper-path` | string | `auto` | Default path to utmp helper binary. `auto` selects path based on `utmp-backend` | None |
Documentation includes the man pages, readme, changelog and license Documentation includes the man pages, readme, changelog and license
files. files.

View file

@ -1009,13 +1009,29 @@ parse_section_main(struct context *ctx)
else if (strcmp(key, "box-drawings-uses-font-glyphs") == 0) else if (strcmp(key, "box-drawings-uses-font-glyphs") == 0)
return value_to_bool(ctx, &conf->box_drawings_uses_font_glyphs); return value_to_bool(ctx, &conf->box_drawings_uses_font_glyphs);
else if (strcmp(key, "utempter") == 0) { else if (strcmp(key, "utmp-helper") == 0 || strcmp(key, "utempter") == 0) {
if (!value_to_str(ctx, &conf->utempter_path)) if (strcmp(key, "utempter") == 0) {
struct user_notification deprecation = {
.kind = USER_NOTIFICATION_DEPRECATED,
.text = xasprintf(
"%s:%d: \033[1m[main].utempter\033[22m, "
"use \033[1m[main].utmp-helper\033[22m instead",
ctx->path, ctx->lineno),
};
tll_push_back(conf->notifications, deprecation);
LOG_WARN(
"%s:%d: [main].utempter is deprecated, "
"use [main].utmp-helper instead",
ctx->path, ctx->lineno);
}
if (!value_to_str(ctx, &conf->utmp_helper_path))
return false; return false;
if (strcmp(conf->utempter_path, "none") == 0) { if (strcmp(conf->utmp_helper_path, "none") == 0) {
free(conf->utempter_path); free(conf->utmp_helper_path);
conf->utempter_path = NULL; conf->utmp_helper_path = NULL;
} }
return true; return true;
@ -3019,9 +3035,12 @@ config_load(struct config *conf, const char *conf_path,
}, },
.env_vars = tll_init(), .env_vars = tll_init(),
.utempter_path = (strlen(FOOT_DEFAULT_UTEMPTER_PATH) > 0 #if defined(UTMP_DEFAULT_HELPER_PATH)
? xstrdup(FOOT_DEFAULT_UTEMPTER_PATH) .utmp_helper_path = ((strlen(UTMP_DEFAULT_HELPER_PATH) > 0 &&
: NULL), access(UTMP_DEFAULT_HELPER_PATH, X_OK) == 0)
? xstrdup(UTMP_DEFAULT_HELPER_PATH)
: NULL),
#endif
.notifications = tll_init(), .notifications = tll_init(),
}; };
@ -3310,8 +3329,8 @@ config_clone(const struct config *old)
tll_push_back(conf->env_vars, copy); tll_push_back(conf->env_vars, copy);
} }
conf->utempter_path = conf->utmp_helper_path =
old->utempter_path != NULL ? xstrdup(old->utempter_path) : NULL; old->utmp_helper_path != NULL ? xstrdup(old->utmp_helper_path) : NULL;
conf->notifications.length = 0; conf->notifications.length = 0;
conf->notifications.head = conf->notifications.tail = 0; conf->notifications.head = conf->notifications.tail = 0;
@ -3379,7 +3398,7 @@ config_free(struct config *conf)
tll_remove(conf->env_vars, it); tll_remove(conf->env_vars, it);
} }
free(conf->utempter_path); free(conf->utmp_helper_path);
user_notifications_free(&conf->notifications); user_notifications_free(&conf->notifications);
} }

View file

@ -320,7 +320,7 @@ struct config {
env_var_list_t env_vars; env_var_list_t env_vars;
char *utempter_path; char *utmp_helper_path;
struct { struct {
enum fcft_scaling_filter fcft_filter; enum fcft_scaling_filter fcft_filter;

View file

@ -343,9 +343,24 @@ empty string to be set, but it must be quoted: *KEY=""*)
(including SMT). Note that this is not always the best value. In (including SMT). Note that this is not always the best value. In
some cases, the number of physical _cores_ is better. some cases, the number of physical _cores_ is better.
*utempter* *utmp-helper*
Path to utempter helper binary. Set to *none* to disable utmp Path to utmp logging helper binary.
records. Default: _@utempter@_.
When starting foot, an utmp record is created by launching the
helper binary with the following arguments:
```
@utmp_add_args@
```
When foot is closed, the utmp record is removed by launching the
helper binary with the following arguments:
```
@utmp_del_args@
```
Set to *none* to disable utmp records. Default: _@utmp_helper_path@_.
# SECTION: environment # SECTION: environment

View file

@ -2,16 +2,26 @@ sh = find_program('sh', native: true)
scdoc_prog = find_program(scdoc.get_variable('scdoc'), native: true) scdoc_prog = find_program(scdoc.get_variable('scdoc'), native: true)
if utempter_path == '' if utmp_backend != 'none'
default_utempter_value = 'not set' utmp_add_args = '@0@ $WAYLAND_DISPLAY'.format(utmp_add)
utmp_del_args = (utmp_del_have_argument
? '@0@ $WAYLAND_DISPLAY'.format(utmp_del)
: '@0@'.format(utmp_del))
utmp_path = utmp_default_helper_path
else else
default_utempter_value = utempter_path utmp_add_args = '<no utmp support in foot>'
utmp_del_args = '<no utmp support in foot>'
utmp_path = 'none'
endif endif
conf_data = configuration_data( conf_data = configuration_data(
{ {
'default_terminfo': get_option('default-terminfo'), 'default_terminfo': get_option('default-terminfo'),
'utempter': default_utempter_value, 'utmp_backend': utmp_backend,
'utmp_add_args': utmp_add_args,
'utmp_del_args': utmp_del_args,
'utmp_helper_path': utmp_path,
} }
) )

View file

@ -34,7 +34,8 @@
# word-delimiters=,│`|:"'()[]{}<> # word-delimiters=,│`|:"'()[]{}<>
# selection-target=primary # selection-target=primary
# workers=<number of logical CPUs> # workers=<number of logical CPUs>
# utempter=/usr/lib/utempter/utempter # utmp-helper=/usr/lib/utempter/utempter # When utmp backend is libutempter (Linux)
# utmp-helper=/usr/libexec/ulog-helper # When utmp backend is ulog (FreeBSD)
[environment] [environment]
# name=value # name=value

View file

@ -16,30 +16,54 @@ if cc.has_function('memfd_create')
add_project_arguments('-DMEMFD_CREATE', language: 'c') add_project_arguments('-DMEMFD_CREATE', language: 'c')
endif endif
utempter_path = get_option('default-utempter-path') utmp_backend = get_option('utmp-backend')
if utempter_path == '' if utmp_backend == 'auto'
utempter = find_program( host_os = host_machine.system()
'utempter', if host_os == 'linux'
required: false, utmp_backend = 'libutempter'
dirs: [join_paths(get_option('prefix'), get_option('libdir'), 'utempter'), elif host_os == 'freebsd'
join_paths(get_option('prefix'), get_option('libexecdir'), 'utempter'), utmp_backend = 'ulog'
'/usr/lib/utempter',
'/usr/libexec/utempter',
'/lib/utempter']
)
if utempter.found()
utempter_path = utempter.full_path()
else else
utempter_path = '' utmp_backend = 'none'
endif endif
elif utempter_path == 'none' endif
utempter_path = ''
utmp_default_helper_path = get_option('utmp-default-helper-path')
if utmp_backend == 'none'
utmp_add = ''
utmp_del = ''
utmp_del_have_argument = false
utmp_default_helper_path = ''
elif utmp_backend == 'libutempter'
utmp_add = 'add'
utmp_del = 'del'
utmp_del_have_argument = true
if utmp_default_helper_path == 'auto'
utmp_default_helper_path = join_paths('/usr', get_option('libdir'), 'utempter', 'utempter')
endif
elif utmp_backend == 'ulog'
utmp_add = 'login'
utmp_del = 'logout'
utmp_del_have_argument = false
if utmp_default_helper_path == 'auto'
utmp_default_helper_path = join_paths('/usr', get_option('libexecdir'), 'ulog-helper')
endif
else
error('invalid utmp backend')
endif endif
add_project_arguments( add_project_arguments(
['-D_GNU_SOURCE=200809L', ['-D_GNU_SOURCE=200809L',
'-DFOOT_DEFAULT_TERM="@0@"'.format(get_option('default-terminfo')), '-DFOOT_DEFAULT_TERM="@0@"'.format(get_option('default-terminfo'))] +
'-DFOOT_DEFAULT_UTEMPTER_PATH="@0@"'.format(utempter_path)] + (utmp_backend != 'none'
? ['-DUTMP_ADD="@0@"'.format(utmp_add),
'-DUTMP_DEL="@0@"'.format(utmp_del),
'-DUTMP_DEFAULT_HELPER_PATH="@0@"'.format(utmp_default_helper_path)]
: []) +
(utmp_del_have_argument
? ['-DUTMP_DEL_HAVE_ARGUMENT=1']
: []) +
(is_debug_build (is_debug_build
? ['-D_DEBUG'] ? ['-D_DEBUG']
: [cc.get_supported_arguments('-fno-asynchronous-unwind-tables')]) + : [cc.get_supported_arguments('-fno-asynchronous-unwind-tables')]) +
@ -343,7 +367,8 @@ summary(
'Themes': get_option('themes'), 'Themes': get_option('themes'),
'IME': get_option('ime'), 'IME': get_option('ime'),
'Grapheme clustering': utf8proc.found(), 'Grapheme clustering': utf8proc.found(),
'Utempter path': utempter_path, 'utmp backend': utmp_backend,
'utmp helper default path': utmp_default_helper_path,
'Build terminfo': tic.found(), 'Build terminfo': tic.found(),
'Terminfo install location': terminfo_install_location, 'Terminfo install location': terminfo_install_location,
'Default TERM': get_option('default-terminfo'), 'Default TERM': get_option('default-terminfo'),

View file

@ -22,5 +22,7 @@ option('custom-terminfo-install-location', type: 'string', value: '',
option('systemd-units-dir', type: 'string', value: '', option('systemd-units-dir', type: 'string', value: '',
description: 'Where to install the systemd service files (absolute path). Default: ${systemduserunitdir}') description: 'Where to install the systemd service files (absolute path). Default: ${systemduserunitdir}')
option('default-utempter-path', type: 'string', value: '', option('utmp-backend', type: 'combo', value: 'auto', choices: ['none', 'libutempter', 'ulog', 'auto'],
description: 'Default path to utempter helper binary. Default: auto-detect') description: 'Which utmp logging backend to use. This affects how (with what arguments) the utmp helper binary (see \utmp-default-helper-path\')is called. Default: auto (linux=libutempter, freebsd=ulog, others=none)')
option('utmp-default-helper-path', type: 'string', value: 'auto',
description: 'Default path to the utmp helper binary. Default: auto-detect')

View file

@ -207,25 +207,41 @@ fdm_ptmx_out(struct fdm *fdm, int fd, int events, void *data)
static bool static bool
add_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx) add_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx)
{ {
#if defined(UTMP_ADD)
if (ptmx < 0) if (ptmx < 0)
return true; return true;
if (conf->utempter_path == NULL) if (conf->utmp_helper_path == NULL)
return true; return true;
char *const argv[] = {conf->utempter_path, "add", getenv("WAYLAND_DISPLAY"), NULL}; char *const argv[] = {conf->utmp_helper_path, UTMP_ADD, getenv("WAYLAND_DISPLAY"), NULL};
return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL); return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL);
#else
return true;
#endif
} }
static bool static bool
del_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx) del_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx)
{ {
#if defined(UTMP_DEL)
if (ptmx < 0) if (ptmx < 0)
return true; return true;
if (conf->utempter_path == NULL) if (conf->utmp_helper_path == NULL)
return true; return true;
char *const argv[] = {conf->utempter_path, "del", getenv("WAYLAND_DISPLAY"), NULL}; char *del_argument =
#if defined(UTMP_DEL_HAVE_ARGUMENT)
getenv("WAYLAND_DISPLAY")
#else
NULL
#endif
;
char *const argv[] = {conf->utmp_helper_path, UTMP_DEL, del_argument, NULL};
return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL); return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL);
#else
return true;
#endif
} }
#if PTMX_TIMING #if PTMX_TIMING

View file

@ -458,7 +458,7 @@ test_section_main(void)
test_string(&ctx, &parse_section_main, "shell", &conf.shell); test_string(&ctx, &parse_section_main, "shell", &conf.shell);
test_string(&ctx, &parse_section_main, "term", &conf.term); test_string(&ctx, &parse_section_main, "term", &conf.term);
test_string(&ctx, &parse_section_main, "app-id", &conf.app_id); test_string(&ctx, &parse_section_main, "app-id", &conf.app_id);
test_string(&ctx, &parse_section_main, "utempter", &conf.utempter_path); test_string(&ctx, &parse_section_main, "utempter", &conf.utmp_helper_path);
test_c32string(&ctx, &parse_section_main, "word-delimiters", &conf.word_delimiters); test_c32string(&ctx, &parse_section_main, "word-delimiters", &conf.word_delimiters);