Search code examples
patchbuildroot

Unable to apply a patch for the buildroot makedevs tool


I am using the buildroot framework. 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!

# cat makedevs-0001-mypath.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;

Solution

  • Asked this question in buildroot mailing list and get a valid anwer:

    http://lists.busybox.net/pipermail/buildroot/2021-April/308390.html

    Hope this helps somebody else in the future!