Bug 14661

Summary: Fakeroot script relies on bash-isms, does not work with dash
Product: buildroot Reporter: Graeme Smecher <gsmecher>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: buildroot, yann.morin.1998
Priority: P5    
Version: 2022.02   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Graeme Smecher 2022-03-09 18:18:35 UTC
On a Debian (bookworm) release, I get the following error message when building up the release tarball:

>>>   Generating filesystem image rootfs.tar
mkdir -p /home/gsmecher/winterland/buildroot-mkids/output/images
rm -rf /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar
mkdir -p /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar
rsync -auH --exclude=/THIS_IS_NOT_YOUR_ROOT_FILESYSTEM /home/gsmecher/winterland/buildroot-mkids/output/target/ /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target
echo '#!/bin/sh' > /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
echo "set -e" >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
echo "chown -h -R 0:0 /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target" >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
PATH="/home/gsmecher/winterland/buildroot-mkids/output/host/bin:/home/gsmecher/winterland/buildroot-mkids/output/host/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" /home/gsmecher/winterland/buildroot-mkids/support/scripts/mkusers /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/full_users_table.txt /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
echo "/home/gsmecher/winterland/buildroot-mkids/output/host/bin/makedevs -d /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/full_devices_table.txt /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target" >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
echo "rm -rf /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target/run/* /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target/run/.[^.]* /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target/tmp/* /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target/tmp/.[^.]*" >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
printf '   \n' >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
printf '   \n' >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
printf '   	(cd /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target; find -print0 | LC_ALL=C sort -z | tar  --pax-option=exthdr.name=%%d/PaxHeaders/%%f,atime:=0,ctime:=0 -cf /home/gsmecher/winterland/buildroot-mkids/output/images/rootfs.tar --null --xattrs-include='\''*'\'' --no-recursion -T - --numeric-owner)\n' >> /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
chmod a+x /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
PATH="/home/gsmecher/winterland/buildroot-mkids/output/host/bin:/home/gsmecher/winterland/buildroot-mkids/output/host/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" FAKEROOTDONTTRYCHOWN=1 /home/gsmecher/winterland/buildroot-mkids/output/host/bin/fakeroot -- /home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/fakeroot
rootdir=/home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target
table='/home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/full_devices_table.txt'
rm: refusing to remove '.' or '..' directory: skipping '/home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target/run/..'
rm: refusing to remove '.' or '..' directory: skipping '/home/gsmecher/winterland/buildroot-mkids/output/build/buildroot-fs/tar/target/tmp/..'
make: *** [fs/tar/tar.mk:37: /home/gsmecher/winterland/buildroot-mkids/output/images/rootfs.tar] Error 1

My /bin/sh is symlinked to /bin/dash:

$ ls -ls /bin/sh
0 lrwxrwxrwx 1 root root 4 Mar  7 16:32 /bin/sh -> dash

When I change fs/common.mk to produce a shebang line using /bin/bash instead, the build completes as expected.

This is most likely a bash-ism in the fakeroot script - it is conceivably also possibly a dash limitation. In any case, the most plausible fixes are either

- for me to insist on /bin/bash for /bin/sh, which fixes the problem here and does not require buildroot alterations, or
- for buildroot to use /bin/bash instead of /bin/sh, which fixes the problem for anyone else who bumps into it.

I am happy with either but thought a bug report was polite.

thanks,
Graeme
Comment 1 Fabrice Fontaine 2022-03-12 17:18:48 UTC
Thanks for your bug report, this should be fixed by https://git.buildroot.net/buildroot/commit/?id=38c4f6b807e9b519922172089915559fb8642046