build: avoid overwriting binaries on merged-/usr

Recent distributions, such as Fedora Rawhide, have fully merged /sbin
and /usr/sbin into /usr/bin.  In this configuration, /usr/sbin is a
symbolic link to bin.

In this environment, if nilfs-utils is configured to install binaries
into /usr/bin, the current logic to create compatibility symlinks in
/usr/sbin causes a critical issue: it overwrites the actual installed
binaries with symbolic links to themselves (e.g., /usr/sbin/nilfs-clean
points to ../bin/nilfs-clean, which are the same file).

Fix this by detecting if /usr/sbin and /usr/bin identify the same
directory.  If they are the same, disable the creation of compatibility
symlinks to avoid this overwrite.

Also, update the README file to clarify that compatibility symbolic
links are created only if /usr/sbin is distinct from /usr/bin.

Fixes: 160ab60d4959 ("build: support UsrMerge and Bin-Sbin merge with automatic detection")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
This commit is contained in:
Ryusuke Konishi 2026-01-24 08:18:09 +09:00
parent cd6a4ab74c
commit 00adeaa0e9
2 changed files with 8 additions and 3 deletions

4
README
View File

@ -93,8 +93,8 @@ hierarchy and adjusts the installation paths for core binaries
- Bin-Sbin merge (e.g., Fedora Rawhide): Installs to /usr/bin
When installing to /usr/bin, the build system also attempts to create
compatibility symbolic links in /usr/sbin if that directory exists on
the target system.
compatibility symbolic links in /usr/sbin if that directory exists and
is different from /usr/bin.
You can manually override this detection using the following options:

View File

@ -291,7 +291,12 @@ AS_CASE(["x$enable_usrmerge"],
core_sbindir='${exec_prefix}/bin'
sbindir='${exec_prefix}/bin'
badblocksdir='/usr/bin'
create_compat_sbin_link=yes
# If /usr/sbin is effectively /usr/bin,
# we must not create compat symlinks because they would overwrite
# the actual binaries installed in /usr/bin.
AS_IF([test "/usr/sbin" -ef "/usr/bin"],
[create_compat_sbin_link=no],
[create_compat_sbin_link=yes])
],
[xsbin|xyes], [
core_sbindir='${exec_prefix}/sbin'