无法为 buildroot makedevs 工具应用补丁

问题描述

我正在使用 buildroot 框架。我为 makedevs 工具做了一个补丁,它提供了一个新的“x”选项,允许递归地设置目录的权限,而无需修改常规文件的权限。该补丁名为“makedevs-0001-custom-opts-exclude-regular-files.patch”(见下文),位于 package/makedevs/ 目录中。当我尝试重新构建框架时,出现此错误

# 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

我能够正确应用在目标上运行的其他补丁,但是这个工具被编译为在主机上运行,​​并且 makedevs.mk 规则编译 makedevs.c 源文件而不在输出/构建上部署它,我认为这是主要问题,但我不完全确定。

你能解释为什么这个补丁没有正确应用吗?为这个位于 buildroot 框架内的 makedevs 工具应用补丁的正确方法是什么?

谢谢!

# 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,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;

解决方法

在 buildroot 邮件列表中提出这个问题并得到一个有效的回答:

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

希望这对未来的其他人有所帮助!