From a36be3e57f2a290e4c5216933344086d69d4db01 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 30 Jul 2022 13:44:11 +0900 Subject: [PATCH 1/6] meson: use 0 for default uids, gids, and time epoch 0 UID and GID are special, and should not be acceptable for the settings. Hence, we can handle 0 as unset. Strictly speaking, time epoch with 0 is valid, but I guess no one use 0 as a valid value. --- meson.build | 8 ++++---- meson_options.txt | 50 +++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/meson.build b/meson.build index 87e67c9c32..bdd494cedf 100644 --- a/meson.build +++ b/meson.build @@ -795,7 +795,7 @@ if default_net_naming_scheme != 'latest' endif time_epoch = get_option('time-epoch') -if time_epoch == -1 +if time_epoch <= 0 time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check : true).stdout().strip() if time_epoch == '' and git.found() and fs.exists('.git') # If we're in a git repository, use the creation time of the latest git tag. @@ -828,7 +828,7 @@ foreach tuple : [['system-alloc-uid-min', 'SYS_UID_MIN', 1], # Also see login.d ['system-alloc-gid-min', 'SYS_GID_MIN', 1], ['system-gid-max', 'SYS_GID_MAX', 999]] v = get_option(tuple[0]) - if v == -1 + if v <= 0 v = run_command( awk, '/^\s*@0@\s+/ { uid=$2 } END { print uid }'.format(tuple[1]), @@ -936,8 +936,8 @@ foreach option : ['adm-gid', val = get_option(option) # Ensure provided GID argument is numeric, otherwise fall back to default assignment - conf.set(name, val >= 0 ? val : '-') - if val >= 0 + conf.set(name, val > 0 ? val : '-') + if val > 0 static_ugids += '@0@:@1@'.format(option, val) endif endforeach diff --git a/meson_options.txt b/meson_options.txt index d8c0c581c2..0e9dc168c4 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -220,20 +220,20 @@ option('default-net-naming-scheme', type : 'string', value : 'latest', option('status-unit-format-default', type : 'combo', choices : ['auto', 'description', 'name', 'combined'], description : 'use unit name or description in messages by default') -option('time-epoch', type : 'integer', value : '-1', +option('time-epoch', type : 'integer', value : 0, description : 'time epoch for time clients') option('clock-valid-range-usec-max', type : 'integer', value : '473364000000000', # 15 years description : 'maximum value in microseconds for the difference between RTC and epoch, exceeding which is considered an RTC error') option('default-user-shell', type : 'string', value : '/bin/bash', description : 'default interactive shell') -option('system-alloc-uid-min', type : 'integer', value : '-1', +option('system-alloc-uid-min', type : 'integer', value : 0, description : 'minimum system UID used when allocating') -option('system-alloc-gid-min', type : 'integer', value : '-1', +option('system-alloc-gid-min', type : 'integer', value : 0, description : 'minimum system GID used when allocating') -option('system-uid-max', type : 'integer', value : '-1', +option('system-uid-max', type : 'integer', value : 0, description : 'maximum system UID') -option('system-gid-max', type : 'integer', value : '-1', +option('system-gid-max', type : 'integer', value : 0, description : 'maximum system GID') option('dynamic-uid-min', type : 'integer', value : 0x0000EF00, description : 'minimum dynamic UID') @@ -253,47 +253,47 @@ option('nobody-user', type : 'string', option('nobody-group', type : 'string', description : 'The name of the nobody group (the one with GID 65534)', value : 'nobody') -option('adm-gid', type : 'integer', value : '-1', +option('adm-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "adm" group') -option('audio-gid', type : 'integer', value : '-1', +option('audio-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "audio" group') -option('cdrom-gid', type : 'integer', value : '-1', +option('cdrom-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "cdrom" group') -option('dialout-gid', type : 'integer', value : '-1', +option('dialout-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "dialout" group') -option('disk-gid', type : 'integer', value : '-1', +option('disk-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "disk" group') -option('input-gid', type : 'integer', value : '-1', +option('input-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "input" group') -option('kmem-gid', type : 'integer', value : '-1', +option('kmem-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "kmem" group') -option('kvm-gid', type : 'integer', value : '-1', +option('kvm-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "kvm" group') -option('lp-gid', type : 'integer', value : '-1', +option('lp-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "lp" group') -option('render-gid', type : 'integer', value : '-1', +option('render-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "render" group') -option('sgx-gid', type : 'integer', value : '-1', +option('sgx-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "sgx" group') -option('tape-gid', type : 'integer', value : '-1', +option('tape-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "tape" group') option('tty-gid', type : 'integer', value : 5, description : 'the numeric GID of the "tty" group') -option('users-gid', type : 'integer', value : '-1', +option('users-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "users" group') -option('utmp-gid', type : 'integer', value : '-1', +option('utmp-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "utmp" group') -option('video-gid', type : 'integer', value : '-1', +option('video-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "video" group') -option('wheel-gid', type : 'integer', value : '-1', +option('wheel-gid', type : 'integer', value : 0, description : 'soft-static allocation for the "wheel" group') -option('systemd-journal-gid', type : 'integer', value : '-1', +option('systemd-journal-gid', type : 'integer', value : 0, description : 'soft-static allocation for the systemd-journal group') -option('systemd-network-uid', type : 'integer', value : '-1', +option('systemd-network-uid', type : 'integer', value : 0, description : 'soft-static allocation for the systemd-network user') -option('systemd-resolve-uid', type : 'integer', value : '-1', +option('systemd-resolve-uid', type : 'integer', value : 0, description : 'soft-static allocation for the systemd-resolve user') -option('systemd-timesync-uid', type : 'integer', value : '-1', +option('systemd-timesync-uid', type : 'integer', value : 0, description : 'soft-static allocation for the systemd-timesync user') option('dev-kvm-mode', type : 'string', value : '0666', From 792d5e87b6b3489500244109f3079071d7acb5a7 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 19 May 2022 06:50:35 -0400 Subject: [PATCH 2/6] meson: fix type for many build options Integers and booleans are supposed to be actual integers and booleans, not strings describing their value, but Meson silently accepted either one. It's still wrong to do it though, and other implementations of Meson such as muon choke on it. --- meson_options.txt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index 0e9dc168c4..d5237f02ae 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -38,7 +38,7 @@ option('static-libsystemd', type : 'combo', option('static-libudev', type : 'combo', choices : ['false', 'true', 'pic', 'no-pic'], description : 'install a static library for libudev') -option('standalone-binaries', type : 'boolean', value : 'false', +option('standalone-binaries', type : 'boolean', value : false, description : 'also build standalone versions of supported binaries') option('sysvinit-path', type : 'string', value : '/etc/init.d', @@ -51,7 +51,7 @@ option('rc-local', type : 'string', value : '/etc/rc.local') option('initrd', type : 'boolean', description : 'install services for use when running systemd in initrd') -option('compat-mutable-uid-boundaries', type : 'boolean', value : 'false', +option('compat-mutable-uid-boundaries', type : 'boolean', value : false, description : 'look at uid boundaries in /etc/login.defs for compatibility') option('nscd', type : 'boolean', description : 'build support for flushing of the nscd caches') @@ -222,7 +222,7 @@ option('status-unit-format-default', type : 'combo', description : 'use unit name or description in messages by default') option('time-epoch', type : 'integer', value : 0, description : 'time epoch for time clients') -option('clock-valid-range-usec-max', type : 'integer', value : '473364000000000', # 15 years +option('clock-valid-range-usec-max', type : 'integer', value : 473364000000000, # 15 years description : 'maximum value in microseconds for the difference between RTC and epoch, exceeding which is considered an RTC error') option('default-user-shell', type : 'string', value : '/bin/bash', description : 'default interactive shell') @@ -442,7 +442,7 @@ option('efi-libdir', type : 'string', description : 'path to the EFI lib directory') option('efi-includedir', type : 'string', value : '/usr/include/efi', description : 'path to the EFI header directory') -option('efi-tpm-pcr-compat', type : 'boolean', value : 'false', +option('efi-tpm-pcr-compat', type : 'boolean', value : false, description : 'Measure kernel command line also into TPM PCR 8 (in addition to 12)') option('sbat-distro', type : 'string', value : 'auto', description : 'SBAT distribution ID, e.g. fedora, or auto for autodetection') @@ -472,11 +472,11 @@ option('zshcompletiondir', type : 'string', option('tests', type : 'combo', choices : ['true', 'unsafe', 'false'], description : 'enable extra tests with =unsafe') -option('slow-tests', type : 'boolean', value : 'false', +option('slow-tests', type : 'boolean', value : false, description : 'run the slow tests by default') -option('fuzz-tests', type : 'boolean', value : 'false', +option('fuzz-tests', type : 'boolean', value : false, description : 'run the fuzzer regression tests by default (with sanitizers)') -option('install-tests', type : 'boolean', value : 'false', +option('install-tests', type : 'boolean', value : false, description : 'install test executables') option('log-message-verification', type : 'combo', choices : ['auto', 'true', 'false'], description : 'do fake printf() calls to verify format strings') @@ -488,18 +488,18 @@ option('ok-color', type : 'combo', 'highlight-cyan', 'highlight-white'], value : 'green', description: 'color of the "OK" status message') -option('urlify', type : 'boolean', value : 'true', +option('urlify', type : 'boolean', value : true, description : 'enable pager Hyperlink ANSI sequence support') -option('fexecve', type : 'boolean', value : 'false', +option('fexecve', type : 'boolean', value : false, description : 'use fexecve() to spawn children') -option('oss-fuzz', type : 'boolean', value : 'false', +option('oss-fuzz', type : 'boolean', value : false, description : 'build against oss-fuzz') -option('llvm-fuzz', type : 'boolean', value : 'false', +option('llvm-fuzz', type : 'boolean', value : false, description : 'build against LLVM libFuzzer') -option('kernel-install', type: 'boolean', value: 'true', +option('kernel-install', type: 'boolean', value: true, description : 'install kernel-install and associated files') -option('analyze', type: 'boolean', value: 'true', +option('analyze', type: 'boolean', value: true, description : 'install systemd-analyze') option('bpf-compiler', type : 'combo', choices : ['clang', 'gcc'], @@ -507,5 +507,5 @@ option('bpf-compiler', type : 'combo', choices : ['clang', 'gcc'], option('bpf-framework', type : 'combo', choices : ['auto', 'true', 'false'], description: 'build BPF programs from source code in restricted C') -option('skip-deps', type : 'boolean', value : 'false', +option('skip-deps', type : 'boolean', value : false, description : 'skip optional dependencies') From 64a42770064fac0d05892dfc5b3f105680677afd Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 19 May 2022 06:54:40 -0400 Subject: [PATCH 3/6] meson: move i18n module import to only when it is used When translations are disabled, it's not necessary to `import('i18n')` and do nothing with it. Also, importing it is (slightly) slow as Meson needs to load another implementation file from disk, so why bother with that work? More particularly, muon does not yet implement this module and fails to setup. Since there's already an option to disable using it, it makes sense to let that option completely skip the not-implemented functionality and actually succeed. --- po/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/meson.build b/po/meson.build index 139f393e33..0a140b40b5 100644 --- a/po/meson.build +++ b/po/meson.build @@ -1,9 +1,9 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -i18n = import('i18n') want_translations = get_option('translations') if want_translations + i18n = import('i18n') i18n.gettext(meson.project_name(), preset : 'glib', data_dirs : '.') From 6c8892828c0970bb51639923e5b3483c7707e9ca Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 26 Jul 2022 21:09:07 -0400 Subject: [PATCH 4/6] meson: use files in run_command with relativized path Passing a file as a command argument in string form assumes that run_command has the current subdir as its cwd, but Meson's documentation *explicitly* calls this out as undefined and wrong to use. Indeed, muon has a different implementation that uses a different cwd, and this argument cannot be found. Instead, passing a files() object means that it's the job of meson itself to verify the file exists, then pass it to the run_command in some format that guarantees it is a valid path reference. --- src/basic/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/meson.build b/src/basic/meson.build index 84576efd89..19d3395a49 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -385,7 +385,7 @@ filesystem_includes = ['linux/magic.h', 'linux/gfs2_ondisk.h'] check_filesystems = find_program('check-filesystems.sh') -r = run_command([check_filesystems, cpp, 'filesystems-gperf.gperf'] + filesystem_includes, check: false) +r = run_command([check_filesystems, cpp, files('filesystems-gperf.gperf')] + filesystem_includes, check: false) if r.returncode() != 0 error('found unknown filesystem(s) defined in kernel headers:\n\n' + r.stdout()) r.stdout() From 89cdbe1f08cb2acf28354bc321678cbbe14eb225 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 26 Jul 2022 21:13:55 -0400 Subject: [PATCH 5/6] meson: strip various strings before converting them to integers "9\n" is not intrinsically a number, although some tools might auto-strip strings before checking if they are a number. It's not guaranteed, anyway. --- meson.build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index bdd494cedf..2189abddc7 100644 --- a/meson.build +++ b/meson.build @@ -813,7 +813,7 @@ if time_epoch <= 0 time_epoch = run_command(stat, '-c', '%Y', NEWS, check : true).stdout() endif - time_epoch = time_epoch.to_int() + time_epoch = time_epoch.strip().to_int() endif conf.set('TIME_EPOCH', time_epoch) @@ -874,7 +874,7 @@ if not meson.is_cross_build() endif id_result = run_command('id', '-u', nobody_user, check : false) if id_result.returncode() == 0 - id = id_result.stdout().to_int() + id = id_result.stdout().strip().to_int() if id != 65534 warning('\n' + 'The local user with the configured user name "@0@" of the nobody user does not have UID 65534 (it has @1@).\n'.format(nobody_user, id) + @@ -893,7 +893,7 @@ if not meson.is_cross_build() endif id_result = run_command('id', '-g', nobody_group, check : false) if id_result.returncode() == 0 - id = id_result.stdout().to_int() + id = id_result.stdout().strip().to_int() if id != 65534 warning('\n' + 'The local group with the configured group name "@0@" of the nobody group does not have GID 65534 (it has @1@).\n'.format(nobody_group, id) + From 9e4a50bcdf7a275766e4f5c7af012c32bc22128d Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 26 Jul 2022 21:49:48 -0400 Subject: [PATCH 6/6] meson: fix broken boolean kwarg Everywhere else that `conf.get('ENABLE_*')` is used as a boolean key for something (for example in if statements) it always checks if == 1, but in this one case it neglects to do so. This is important because conf.get yields the same int that was stored, but if statements require booleans. So does executable's "install" kwarg, at least according to the documentation. In actuality, it accepts all types without sanity checking, then uses python "if bool(var)", so you can actually do `install: 'do not'` and that's treated identical to `true`. This is a type-checking bug which Meson will eventually fix. muon fails on the same code, today. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 2189abddc7..6bbb2db55d 100644 --- a/meson.build +++ b/meson.build @@ -2229,7 +2229,7 @@ exe = executable( dependencies : [versiondep, libseccomp], install_rpath : rootpkglibdir, - install : conf.get('ENABLE_ANALYZE')) + install : conf.get('ENABLE_ANALYZE') == 1) public_programs += exe if want_tests != 'false'