From aa2b29b1bdc4c50ecbe820c56b76c3207228a9bf Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Thu, 6 Apr 2023 09:04:05 +0200 Subject: [PATCH] utmp: add suppport for FreeBSD FreeBSD does not have utempter helper but instead have a ulog-helper which provides the same set of functionnality, but the call and arguments are slightly different. --- doc/foot.ini.5.scd | 4 +++- doc/meson.build | 4 ++++ meson.build | 34 +++++++++++++++++++++++----------- terminal.c | 9 +++++++-- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 5ef62045..545a7a06 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -344,8 +344,10 @@ empty string to be set, but it must be quoted: *KEY=""*) some cases, the number of physical _cores_ is better. *utempter* - Path to utempter helper binary. Set to *none* to disable utmp + Path to _@utempter_name@_ helper binary. Set to *none* to disable utmp records. Default: _@utempter@_. + Foot will execute the binary with _@utempter_add@_ when starting + and with _@utempter_del@_ when exiting. # SECTION: environment diff --git a/doc/meson.build b/doc/meson.build index 86e75952..f267e793 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -4,6 +4,7 @@ scdoc_prog = find_program(scdoc.get_variable('scdoc'), native: true) if utempter_path == '' default_utempter_value = 'not set' + utempter_name = 'none' else default_utempter_value = utempter_path endif @@ -12,6 +13,9 @@ conf_data = configuration_data( { 'default_terminfo': get_option('default-terminfo'), 'utempter': default_utempter_value, + 'utempter_name': utempter_name, + 'utempter_add': utempter_add, + 'utempter_del': utempter_del, } ) diff --git a/meson.build b/meson.build index a6892cc4..aaf53f3c 100644 --- a/meson.build +++ b/meson.build @@ -18,28 +18,40 @@ endif utempter_path = get_option('default-utempter-path') if utempter_path == '' - utempter = find_program( - 'utempter', - required: false, - dirs: [join_paths(get_option('prefix'), get_option('libdir'), 'utempter'), - join_paths(get_option('prefix'), get_option('libexecdir'), 'utempter'), - '/usr/lib/utempter', - '/usr/libexec/utempter', - '/lib/utempter'] - ) - if utempter.found() - utempter_path = utempter.full_path() + host_system = host_machine.system() + if host_system == 'linux' + utempter_path = join_paths(get_option('libdir'),'/utempter/utempter') + utempter_add = 'add' + utempter_name = 'utempter' + utempter_del_arguments = true + utempter_del = 'del' + elif host_system == 'freebsd' + utempter_path = '/usr/libexec/ulog-helper' + utempter_name = 'ulog-helper' + utempter_add = 'login' + utempter_del_arguments = false + utempter_del = 'logout' else utempter_path = '' + utempter_add = '' + utempter_del = '' + utempter_del_arguments = false endif elif utempter_path == 'none' utempter_path = '' + utempter_add = '' + utempter_del = '' + utempter_del_arguments = false endif add_project_arguments( ['-D_GNU_SOURCE=200809L', '-DFOOT_DEFAULT_TERM="@0@"'.format(get_option('default-terminfo')), + '-DFOOT_UTEMPTER_ADD="@0@"'.format(utempter_add), + '-DFOOT_UTEMPTER_DEL="@0@"'.format(utempter_del), '-DFOOT_DEFAULT_UTEMPTER_PATH="@0@"'.format(utempter_path)] + + (utempter_del_arguments + ? [ '-DFOOT_UTEMPTER_DEL_ARGUMENTS' ] : []) + (is_debug_build ? ['-D_DEBUG'] : [cc.get_supported_arguments('-fno-asynchronous-unwind-tables')]) + diff --git a/terminal.c b/terminal.c index 2e62fbb7..9eefde84 100644 --- a/terminal.c +++ b/terminal.c @@ -212,19 +212,24 @@ add_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx) if (conf->utempter_path == NULL) return true; - char *const argv[] = {conf->utempter_path, "add", getenv("WAYLAND_DISPLAY"), NULL}; + char *const argv[] = {conf->utempter_path, FOOT_UTEMPTER_ADD, getenv("WAYLAND_DISPLAY"), NULL}; return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL); + } static bool del_utmp_record(const struct config *conf, struct reaper *reaper, int ptmx) { + char *arg1 = NULL; if (ptmx < 0) return true; if (conf->utempter_path == NULL) return true; +#ifdef FOOT_UTEMPTER_DEL_ARGUMENTS + arg1 = getenv("WAYLAD_DISPLAY"); +#endif - char *const argv[] = {conf->utempter_path, "del", getenv("WAYLAND_DISPLAY"), NULL}; + char *const argv[] = {conf->utempter_path, FOOT_UTEMPTER_DEL, arg1, NULL}; return spawn(reaper, NULL, argv, ptmx, ptmx, -1, NULL); }