busybox-1.13.2-depmod.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. --- busybox-1.13.2/modutils/depmod.c Sun Nov 9 18:28:03 2008
  2. +++ busybox-1.13.2-depmod/modutils/depmod.c Mon Jan 12 23:12:59 2009
  3. @@ -33,7 +33,7 @@
  4. enum {
  5. ARG_a = (1<<0), /* All modules, ignore mods in argv */
  6. ARG_A = (1<<1), /* Only emit .ko that are newer than modules.dep file */
  7. - ARG_b = (1<<2), /* not /lib/modules/$(uname -r)/ but this base-dir */
  8. + ARG_b = (1<<2), /* base directory when modules are in staging area */
  9. ARG_e = (1<<3), /* with -F, print unresolved symbols */
  10. ARG_F = (1<<4), /* System.map that contains the symbols */
  11. ARG_n = (1<<5) /* dry-run, print to stdout only */
  12. @@ -57,7 +57,7 @@
  13. *first = info;
  14. info->dnext = info->dprev = info;
  15. - info->name = xstrdup(fname);
  16. + info->name = xasprintf("/%s", fname);
  17. info->modname = filename2modname(fname, NULL);
  18. for (ptr = image; ptr < image + len - 10; ptr++) {
  19. if (strncmp(ptr, "depends=", 8) == 0) {
  20. @@ -123,44 +123,61 @@
  21. }
  22. }
  23. +static void xfreopen_write(const char *file, FILE *f)
  24. +{
  25. + if (freopen(file, "w", f) == NULL)
  26. + bb_perror_msg_and_die("can't open '%s'", file);
  27. +}
  28. +
  29. int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  30. int depmod_main(int argc UNUSED_PARAM, char **argv)
  31. {
  32. module_info *modules = NULL, *m, *dep;
  33. - char *moddir_base = (char *)CONFIG_DEFAULT_MODULES_DIR;
  34. + const char *moddir_base = "/";
  35. + char *moddir, *version;
  36. + struct utsname uts;
  37. int tmp;
  38. getopt32(argv, "aAb:eF:n", &moddir_base, NULL);
  39. argv += optind;
  40. /* goto modules location */
  41. + xchdir(moddir_base);
  42. /* If a version is provided, then that kernel version's module directory
  43. * is used, rather than the current kernel version (as returned by
  44. * "uname -r"). */
  45. - xchdir(moddir_base);
  46. - if (*argv && (sscanf(*argv, "%d.%d.%d", &tmp, &tmp, &tmp) == 3)) {
  47. - xchdir(*argv++);
  48. + if (*argv && sscanf(*argv, "%d.%d.%d", &tmp, &tmp, &tmp) == 3) {
  49. + version = *argv++;
  50. } else {
  51. - struct utsname uts;
  52. uname(&uts);
  53. - xchdir(uts.release);
  54. + version = uts.release;
  55. }
  56. - /* If no modules are given on the command-line, -a is on per default. */
  57. - option_mask32 |= *argv == NULL;
  58. + moddir = concat_path_file(&CONFIG_DEFAULT_MODULES_DIR[1], version);
  59. /* Scan modules */
  60. - moddir_base = xrealloc_getcwd_or_warn(NULL);
  61. - do {
  62. - recursive_action((option_mask32 & ARG_a) ? moddir_base : *argv,
  63. - ACTION_RECURSE, parse_module, NULL, &modules, 0);
  64. - } while (!(option_mask32 & ARG_a) && *(++argv));
  65. + if (*argv) {
  66. + char *modfile;
  67. + struct stat sb;
  68. + do {
  69. + modfile = concat_path_file(moddir, *argv);
  70. + xstat(modfile, &sb);
  71. + parse_module(modfile, &sb, &modules, 0);
  72. + free(modfile);
  73. + } while (*(++argv));
  74. + } else {
  75. + recursive_action(moddir, ACTION_RECURSE,
  76. + parse_module, NULL, &modules, 0);
  77. + }
  78. +
  79. + /* Prepare for writing out the dep files */
  80. + xchdir(moddir);
  81. if (ENABLE_FEATURE_CLEAN_UP)
  82. - free(moddir_base);
  83. + free(moddir);
  84. /* Generate dependency and alias files */
  85. if (!(option_mask32 & ARG_n))
  86. - freopen(CONFIG_DEFAULT_DEPMOD_FILE, "w", stdout);
  87. + xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout);
  88. for (m = modules; m != NULL; m = m->next) {
  89. printf("%s:", m->name);
  90. @@ -174,12 +191,12 @@
  91. dep->dprev->dnext = dep->dnext;
  92. dep->dnext = dep->dprev = dep;
  93. }
  94. - puts("");
  95. + bb_putchar('\n');
  96. }
  97. #if ENABLE_FEATURE_MODUTILS_ALIAS
  98. if (!(option_mask32 & ARG_n))
  99. - freopen("modules.alias", "w", stdout);
  100. + xfreopen_write("modules.alias", stdout);
  101. for (m = modules; m != NULL; m = m->next) {
  102. while (m->aliases) {
  103. printf("alias %s %s\n",
  104. @@ -190,7 +207,7 @@
  105. #endif
  106. #if ENABLE_FEATURE_MODUTILS_SYMBOLS
  107. if (!(option_mask32 & ARG_n))
  108. - freopen("modules.symbols", "w", stdout);
  109. + xfreopen_write("modules.symbols", stdout);
  110. for (m = modules; m != NULL; m = m->next) {
  111. while (m->symbols) {
  112. printf("alias symbol:%s %s\n",