wok rev 1637
busybox: fix modinfo
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Oct 24 21:24:55 2008 +0000 (2008-10-24) |
parents | c7968a159ca2 |
children | 7d89161a7786 |
files | busybox/stuff/busybox-1.12.0-modinfo.u busybox/stuff/busybox-1.12.0-modprobe.u |
line diff
1.1 --- a/busybox/stuff/busybox-1.12.0-modinfo.u Thu Oct 23 20:39:58 2008 +0000 1.2 +++ b/busybox/stuff/busybox-1.12.0-modinfo.u Fri Oct 24 21:24:55 2008 +0000 1.3 @@ -59,7 +59,7 @@ 1.4 1.5 --- busybox-1.12.0/modutils/modinfo.c 1.6 +++ busybox-1.12.0/modutils/modinfo.c 1.7 -@@ -0,0 +1,91 @@ 1.8 +@@ -0,0 +1,82 @@ 1.9 +/* vi: set sw=4 ts=4: */ 1.10 +/* 1.11 + * modinfo - retrieve module info 1.12 @@ -71,7 +71,48 @@ 1.13 +#undef _GNU_SOURCE 1.14 +#define _GNU_SOURCE 1.15 +#include <libbb.h> 1.16 -+#include <sys/utsname.h> /* uname() */ 1.17 ++#include <fnmatch.h> 1.18 ++ 1.19 ++enum { 1.20 ++ ARG_F = (1<<4), /* field name */ 1.21 ++ ARG_0 = (1<<5) /* \0 as separator */ 1.22 ++}; 1.23 ++ 1.24 ++struct modinfo_env { 1.25 ++ char **argv; 1.26 ++ char *field; 1.27 ++}; 1.28 ++ 1.29 ++static void modinfo(char *name, char *path, void *env) 1.30 ++{ 1.31 ++ size_t len; 1.32 ++ int i, length; 1.33 ++ char *ptr, *the_module; 1.34 ++ char **argv = ((struct modinfo_env *) env)->argv; 1.35 ++ char *field = ((struct modinfo_env *) env)->field; 1.36 ++ extern void *xalloc_load_module(const char filename[], size_t *len); 1.37 ++ 1.38 ++ for (i = 0; argv[i]; i++) { 1.39 ++ if (fnmatch(argv[i],name,0) == 0) { 1.40 ++ len = MAXINT(ssize_t); 1.41 ++ ptr = the_module = xalloc_load_module(path, &len); 1.42 ++ length = strlen(field); 1.43 ++ do { 1.44 ++ ptr = memchr(ptr, *field, len - (ptr - (char*)the_module)); 1.45 ++ if (ptr == NULL) /* no occurance left, done */ 1.46 ++ break; 1.47 ++ if (!strncmp(ptr, field, length) && ptr[length] == '=') { 1.48 ++ ptr += length + 1; 1.49 ++ ptr += printf("%s%c",ptr, 1.50 ++ (option_mask32 & ARG_0) ? '\0' : '\n'); 1.51 ++ } 1.52 ++ ++ptr; 1.53 ++ } while (1); 1.54 ++ free(the_module); 1.55 ++ break; 1.56 ++ } 1.57 ++ } 1.58 ++} 1.59 + 1.60 +int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1.61 +int modinfo_main(int argc UNUSED_PARAM, char **argv) 1.62 @@ -82,72 +123,22 @@ 1.63 + "license", 1.64 + "parm" 1.65 + }; 1.66 -+ size_t len; 1.67 -+ int i, length; 1.68 -+ char *field = NULL; 1.69 -+ char *ptr, *the_module, *depends, *filename; 1.70 -+ struct utsname un; 1.71 -+ enum { 1.72 -+ ARG_F = (1<<4), /* field name */ 1.73 -+ ARG_0 = (1<<5) /* \0 as separator */ 1.74 -+ }; 1.75 -+ extern void *xalloc_load_module(const char filename[], size_t *len); 1.76 ++ int i; 1.77 ++ struct modinfo_env env; 1.78 ++ extern void mod_walk(void (*action)(char *name, char *path, void *env), 1.79 ++ void *data); 1.80 + 1.81 -+ getopt32(argv, "adlpF:0", &field); 1.82 -+ argv += optind; 1.83 ++ env.field = NULL; 1.84 ++ getopt32(argv, "adlpF:0", &env.field); 1.85 ++ env.argv = argv += optind; 1.86 + 1.87 + for (i = 0; i < sizeof(shortcuts)/sizeof(shortcuts[0]); i++) 1.88 + if (option_mask32 & (1 << i)) 1.89 -+ field = (char *) shortcuts[i]; 1.90 ++ env.field = (char *) shortcuts[i]; 1.91 + 1.92 -+ if (!field || !*argv) 1.93 ++ if (!env.field || !*env.argv) 1.94 + bb_show_usage(); 1.95 + 1.96 -+ /* get module path from modules.dep */ 1.97 -+ uname(&un); /* never fails */ 1.98 -+ filename = xasprintf(CONFIG_DEFAULT_MODULES_DIR"/%s/"CONFIG_DEFAULT_DEPMOD_FILE, un.release); 1.99 -+ len = MAXINT(ssize_t); 1.100 -+ the_module = xalloc_load_module(*argv, &len); 1.101 -+ if (the_module == NULL) { 1.102 -+ len = MAXINT(ssize_t); 1.103 -+ ptr = depends = xmalloc_open_read_close(filename, &len); 1.104 -+ depends[len-1] = 0; 1.105 -+ if (ENABLE_FEATURE_CLEAN_UP) 1.106 -+ free(filename); 1.107 -+ do { 1.108 -+ ptr = strstr(ptr,*argv); 1.109 -+ length = strlen(*argv); 1.110 -+ if (!ptr) 1.111 -+ bb_show_usage(); 1.112 -+ if (ptr[length] == '.' && ptr[-1] == '/') { 1.113 -+ while (ptr[++length] != ':') 1.114 -+ if (ptr[length] == ' ') goto next; 1.115 -+ ptr[length] = 0; 1.116 -+ while (ptr > depends && ptr[-1] != '\n') ptr--; 1.117 -+ break; 1.118 -+ } 1.119 -+ next: 1.120 -+ ptr++; 1.121 -+ } while (1); 1.122 -+ if (ENABLE_FEATURE_CLEAN_UP) 1.123 -+ free(depends); 1.124 -+ 1.125 -+ len = MAXINT(ssize_t); 1.126 -+ the_module = xalloc_load_module(ptr, &len); 1.127 -+ } 1.128 -+ ptr = the_module; 1.129 -+ length = strlen(field); 1.130 -+ do { 1.131 -+ ptr = memchr(ptr, *field, len - (ptr - (char*)the_module)); 1.132 -+ if (ptr == NULL) /* no occurance left, done */ 1.133 -+ break; 1.134 -+ if (!strncmp(ptr, field, length) && ptr[length] == '=') { 1.135 -+ ptr += length + 1; 1.136 -+ ptr += printf("%s%c",ptr,(option_mask32 & ARG_0) ? '\0' : '\n'); 1.137 -+ } 1.138 -+ ++ptr; 1.139 -+ } while (1); 1.140 -+ if (ENABLE_FEATURE_CLEAN_UP) 1.141 -+ free(the_module); 1.142 ++ mod_walk(modinfo, &env); 1.143 + return 0; 1.144 +}
2.1 --- a/busybox/stuff/busybox-1.12.0-modprobe.u Thu Oct 23 20:39:58 2008 +0000 2.2 +++ b/busybox/stuff/busybox-1.12.0-modprobe.u Fri Oct 24 21:24:55 2008 +0000 2.3 @@ -27,3 +27,27 @@ 2.4 if (remove_opt) { 2.5 do { 2.6 /* (*argv) can be NULL here */ 2.7 + 2.8 +--- busybox-1.12.0/modutils/modprobe.c 2.9 ++++ busybox-1.12.0/modutils/modprobe.c 2.10 +@@ -921,6 +921,20 @@ 2.11 + return rc; 2.12 + } 2.13 + 2.14 ++void mod_walk(void (*action)(char *name, char *path, void *env), void *data); 2.15 ++void mod_walk(void (*action)(char *name, char *path, void *env), void *data) 2.16 ++{ 2.17 ++ struct dep_t *dt; 2.18 ++ 2.19 ++ depend = build_dep(); 2.20 ++ if (!depend) 2.21 ++ bb_error_msg_and_die("cannot parse "CONFIG_DEFAULT_DEPMOD_FILE); 2.22 ++ 2.23 ++ for (dt = depend; dt && dt->m_path; dt = dt->m_next) { 2.24 ++ action(dt->m_name, dt->m_path, data); 2.25 ++ } 2.26 ++} 2.27 ++ 2.28 + int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 2.29 + int modprobe_main(int argc UNUSED_PARAM, char **argv) 2.30 + {