All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yann E. MORIN" <yann.morin.1998@free.fr>
To: Joachim Wiberg <troglobit@gmail.com>
Cc: Matt Weber <matthew.weber@collins.com>, buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH v3 1/3] package/makedevs: allow recursive on directory with dangling symlinks
Date: Sat, 1 Jan 2022 14:32:18 +0100	[thread overview]
Message-ID: <20220101133218.GI3390456@scaer> (raw)
In-Reply-To: <20211223090800.1716321-2-troglobit@gmail.com>

Joachim, All,

On 2021-12-23 10:07 +0100, Joachim Wiberg spake thusly:
> 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 dangling symlink:

*makedevs   *its (really "its", and really not "it's")

Applied to master, thanks.

Regards,
Yann E. MORIN.

>   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, dangling or not.
> 
> In case the recursive operation includes a chmod() as well, explicitly
> exclude symlinks that are dangling, because chmod() always operates on
> the link target.
> 
> Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
> ---
>  package/makedevs/makedevs.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/package/makedevs/makedevs.c b/package/makedevs/makedevs.c
> index c57b964f5c..2796cd5e78 100644
> --- a/package/makedevs/makedevs.c
> +++ b/package/makedevs/makedevs.c
> @@ -440,11 +440,13 @@ 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) {
>  		bb_perror_msg("chown failed for %s", fpath);
>  		return -1;
>  	}
> -	if (recursive_mode != -1) {
> +
> +	/* chmod() is optional, also skip if dangling symlink */
> +	if (recursive_mode != -1 && tflag == FTW_SL && access(fpath, F_OK)) {
>  		if (chmod(fpath, recursive_mode) < 0) {
>  			bb_perror_msg("chmod failed for %s", fpath);
>  			return -1;
> @@ -628,7 +630,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) {
> -- 
> 2.25.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2022-01-01 13:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23  9:07 [Buildroot] [PATCH v3 0/3] package/makedevs: allow recursive on directory with symlinks Joachim Wiberg
2021-12-23  9:07 ` [Buildroot] [PATCH v3 1/3] package/makedevs: allow recursive on directory with dangling symlinks Joachim Wiberg
2022-01-01 13:32   ` Yann E. MORIN [this message]
2021-12-23  9:07 ` [Buildroot] [PATCH v3 2/3] .clang-format: initial import from Linux 5.15.6 Joachim Wiberg
2022-01-01 13:58   ` Yann E. MORIN
2021-12-23  9:08 ` [Buildroot] [PATCH v3 3/3] package/makedevs: coding style and whitespace cleanup Joachim Wiberg
2022-01-01 14:13   ` Yann E. MORIN
2022-01-01 14:26     ` Joachim Wiberg
2022-01-01 14:38       ` Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220101133218.GI3390456@scaer \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@buildroot.org \
    --cc=matthew.weber@collins.com \
    --cc=troglobit@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.