diff mbox series

Unable to apply a patch for the buildroot makedevs tool

Message ID AM6PR05MB5928D4AD5D2311ACA772CCA5A34C9@AM6PR05MB5928.eurprd05.prod.outlook.com
State Not Applicable
Headers show
Series Unable to apply a patch for the buildroot makedevs tool | expand

Commit Message

Ivan Castell April 16, 2021, 6:58 a.m. UTC
Hello! I did a patch for the makedevs tool that provides a new 'x' option that allows setting permissions for directories recursively without modifiying permissions for regular files. The patch is named 'makedevs-0001-custom-opts-exclude-regular-files.patch' (see below), and is located inside package/makedevs/ directory. When I try to re-build the framework, I get this error:

# make all
>>> host-makedevs  Patching

Applying makedevs-0001-custom-opts-exclude-regular-files.patch using patch:
can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -purN makedevs.orig/makedevs.c makedevs/makedevs.c
|--- makedevs.orig/makedevs.c 2021-04-15 14:40:03.439990661 +0000
|+++ makedevs/makedevs.c 2021-04-15 14:40:46.128006533 +0000
--------------------------
No file to patch.  Skipping patch.
3 out of 3 hunks ignored
package/pkg-generic.mk:187: recipe for target '/usr/local/share/buildroot/output/build/host-makedevs/.stamp_patched' failed
make: *** [/usr/local/share/buildroot/output/build/host-makedevs/.stamp_patched] Error 1

I was able to apply other patches properly that run on the target, but this tool is compiled to run on the host, and makedevs.mk rules compiles the makedevs.c source file without deploying it on output/build, and I think that's the main issue, but I am not completely sure.

Can you explain why is this patch not aplying properly and what should be the proper way to apply a patch for this makedevs tool, located inside the buildroot framework?

Thanks!

Comments

Peter Seiderer April 16, 2021, 10:14 p.m. UTC | #1
Hello Ivan,

On Fri, 16 Apr 2021 06:58:05 +0000, Ivan Castell <icastell@circontrol.com> wrote:

> Hello! I did a patch for the makedevs tool that provides a new 'x' option that allows setting permissions for directories recursively without modifiying permissions for regular files. The patch is named 'makedevs-0001-custom-opts-exclude-regular-files.patch' (see below), and is located inside package/makedevs/ directory. When I try to re-build the framework, I get this error:
>
> # make all
> >>> host-makedevs  Patching
>
> Applying makedevs-0001-custom-opts-exclude-regular-files.patch using patch:
> can't find file to patch at input line 4
> Perhaps you used the wrong -p or --strip option?
> The text leading up to this was:
> --------------------------
> |diff -purN makedevs.orig/makedevs.c makedevs/makedevs.c
> |--- makedevs.orig/makedevs.c 2021-04-15 14:40:03.439990661 +0000
> |+++ makedevs/makedevs.c 2021-04-15 14:40:46.128006533 +0000
> --------------------------
> No file to patch.  Skipping patch.
> 3 out of 3 hunks ignored
> package/pkg-generic.mk:187: recipe for target '/usr/local/share/buildroot/output/build/host-makedevs/.stamp_patched' failed
> make: *** [/usr/local/share/buildroot/output/build/host-makedevs/.stamp_patched] Error 1

The makedevs package is a little bit special, as there is no download source package,
and the build receipt package/makedevs/makedevs.mk is just compiling the
(buildroot internal) file package/makedevs/makedevs.c, so no chance to apply a
patch, you need to patch the file package/makedevs/makedevs.c itself...

Regards,
Peter

>
> I was able to apply other patches properly that run on the target, but this tool is compiled to run on the host, and makedevs.mk rules compiles the makedevs.c source file without deploying it on output/build, and I think that's the main issue, but I am not completely sure.
>
> Can you explain why is this patch not aplying properly and what should be the proper way to apply a patch for this makedevs tool, located inside the buildroot framework?
>
> Thanks!
>
>
>
>
Yann E. MORIN April 17, 2021, 7:13 a.m. UTC | #2
Ivan, All,

On 2021-04-16 06:58 +0000, Ivan Castell spake thusly:
> Hello! I did a patch for the makedevs tool that provides a new 'x' option
> that allows setting permissions for directories recursively without
> modifiying permissions for regular files.

As Peter said, makedev is directly compiled from its single source file
in Buildroot's tree, so no way to patch it with the standard package
infrastructure.

However, your patch looks like it would provide an interesting feature
that we want in Buildroot.

Would you mind officially contributing your patch so we can apply it?

Regards,
Yann E. MORIN.
Ivan Castell April 19, 2021, 5:58 a.m. UTC | #3
Hello all.

Thanks for confirming my suspicions with makedevs patch. Please, proceed applying the patch, of course!

Kind regards,
  -- Ivan
Yann E. MORIN April 19, 2021, 5:04 p.m. UTC | #4
Ivan, All,

On 2021-04-19 05:58 +0000, Ivan Castell spake thusly:
> Please, proceed applying the patch, of course!

Can you please send the patch with:
  - a proper commit title
  - a proper commit log
  - your signed-off-by line

And then use 'git send-email' to actually send the patch.

See the manual for extensive explanations on how to send a patch:
    https://buildroot.org/downloads/manual/manual.html#submitting-patches

See also the actual 'git log' for examples pertaining to makedevs:

    git log package/makedevs/makedevs.c

Commit bdbbc72934bc7 (makedevs: support optional files) is a good
example: it also adds a new feature to makedevs, so you can model your
commit log after that one for example.

Regards,
Yann E. MORIN.
Peter Korsgaard April 26, 2021, 9:48 p.m. UTC | #5
>>>>> "Yann" == Yann E MORIN <yann.morin.1998@free.fr> writes:

 > Ivan, All,
 > On 2021-04-16 06:58 +0000, Ivan Castell spake thusly:
 >> Hello! I did a patch for the makedevs tool that provides a new 'x' option
 >> that allows setting permissions for directories recursively without
 >> modifiying permissions for regular files.

 > As Peter said, makedev is directly compiled from its single source file
 > in Buildroot's tree, so no way to patch it with the standard package
 > infrastructure.

With that said, there is no specific reason why this is done like that -
And E.G. mcookie does copy its .c file to the build directory so the
patch step works - So it IMHO makes sense to fix makedevs to also do it
so the normal infrastructure works as expected.

I've sent a series to do that:

https://patchwork.ozlabs.org/project/buildroot/list/?series=240851
diff mbox series

Patch

diff -purN makedevs.orig/makedevs.c makedevs/makedevs.c
--- makedevs.orig/makedevs.c    2021-04-15 14:40:03.439990661 +0000
+++ makedevs/makedevs.c 2021-04-15 14:40:46.128006533 +0000
@@ -404,7 +404,8 @@  void bb_show_usage(void)
    fprintf(stderr, "Where name is the file name,  type can be one of:\n");
    fprintf(stderr, "      f       A regular file\n");
    fprintf(stderr, "      d       Directory\n");
-   fprintf(stderr, "      r       Directory recursively\n");
+   fprintf(stderr, "      r       Directory recursively including regular files\n");
+   fprintf(stderr, "      x       Directory recursively excluding regular files\n");
    fprintf(stderr, "      c       Character special device file\n");
    fprintf(stderr, "      b       Block special device file\n");
    fprintf(stderr, "      p       Fifo (named pipe)\n");
@@ -437,6 +438,26 @@  void bb_show_usage(void)
    exit(1);
 }
 
+int xx_recursive(const char *fpath, const struct stat *sb,
+       int tflag, struct FTW *ftwbuf){
+
+   if (chown(fpath, recursive_uid, recursive_gid) == -1) {
+       bb_perror_msg("chown failed for %s", fpath);
+       return -1;
+   }
+
+   if (tflag == 1) {
+       if (recursive_mode != -1) {
+           if (chmod(fpath, recursive_mode) < 0) {
+               bb_perror_msg("chmod failed for %s", fpath);
+               return -1;
+           }
+       }
+   }
+
+   return 0;
+}
+
 int bb_recursive(const char *fpath, const struct stat *sb,
        int tflag, struct FTW *ftwbuf){
 
@@ -599,7 +620,17 @@  int main(int argc, char **argv)
                ret = EXIT_FAILURE;
                goto loop;
            }
-       } else
+       } else if (type == 'x') {
+           recursive_uid = uid;
+           recursive_gid = gid;
+           recursive_mode = mode;
+           if (nftw(full_name, xx_recursive, 20, FTW_MOUNT | FTW_PHYS) < 0) {
+               bb_perror_msg("line %d: xx_recursive failed for %s", linenum, full_name);
+               ret = EXIT_FAILURE;
+               goto loop;
+           }
+       }
+       else
        {
            dev_t rdev;
            unsigned i;