[Buildroot] [PATCH v2 1/2] package/makedevs: allow recursive on directory with symlinks

Arnout Vandecappelle arnout at mind.be
Wed Dec 22 14:06:49 UTC 2021



On 22/12/2021 09:35, Joachim Wiberg wrote:
> When using BR2_ROOTFS_DEVICE_TABLE to change ownership of /etc, like so:
> 
>    /etc        r  -1 root     wheel     - - - - -
> 
> makdevs fails due to it trying to chown() a symlink:

  The problem is actually a *dangling* symlink, not a symlink per se.


> 
>    makedevs: chown failed for /src/myLinux/output/build/buildroot-fs/ext2/target/etc/mtab: No such file or directory
>    makedevs: line 25: recursive failed for /src/myLinux/output/build/buildroot-fs/ext2/target/etc: No such file or directory
>    make[2]: *** [fs/ext2/ext2.mk:63: /src/myLinux/output/images/rootfs.ext2] Error 1
>    make[1]: *** [Makefile:84: _all] Error 2
>    make[1]: Leaving directory '/src/myLinux/buildroot'
> 
> This patch changes chown() to lchown() in two cases in makedevs.c when
> the argument can be a symlink.
> 
> Signed-off-by: Joachim Wiberg <troglobit at gmail.com>
> ---
>   package/makedevs/makedevs.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/package/makedevs/makedevs.c b/package/makedevs/makedevs.c
> index c57b964f5c..634ae7c3d8 100644
> --- a/package/makedevs/makedevs.c
> +++ b/package/makedevs/makedevs.c
> @@ -440,7 +440,7 @@ void bb_show_usage(void)
>   int bb_recursive(const char *fpath, const struct stat *sb,
>   		int tflag, struct FTW *ftwbuf){
>   
> -	if (chown(fpath, recursive_uid, recursive_gid) == -1) {
> +	if (lchown(fpath, recursive_uid, recursive_gid) == -1) {

  In this v2 you change the chown, but the chmod below still remains. Doesn't it 
have the same problem with a dangling symlink?

  Regards,
  Arnout

>   		bb_perror_msg("chown failed for %s", fpath);
>   		return -1;
>   	}
> @@ -628,7 +628,7 @@ int main(int argc, char **argv)
>   				if (mknod(full_name_inc, mode, rdev) < 0) {
>   					bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc);
>   					ret = EXIT_FAILURE;
> -				} else if (chown(full_name_inc, uid, gid) < 0) {
> +				} else if (lchown(full_name_inc, uid, gid) < 0) {
>   					bb_perror_msg("line %d: can't chown %s", linenum, full_name_inc);
>   					ret = EXIT_FAILURE;
>   				} else if (chmod(full_name_inc, mode) < 0) {
> 



More information about the buildroot mailing list