diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-05-26 17:04:01 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-05-26 17:04:01 +0000 |
commit | 6bb55cfb99090565d565588c281c08ca21993e78 (patch) | |
tree | fb8b75be9b53ad897ecdee08b321fa211aa1345c | |
parent | cf18010ca966aa2be06e0466aeb78b54d15957e2 (diff) | |
download | busybox-w32-6bb55cfb99090565d565588c281c08ca21993e78.tar.gz busybox-w32-6bb55cfb99090565d565588c281c08ca21993e78.tar.bz2 busybox-w32-6bb55cfb99090565d565588c281c08ca21993e78.zip |
- add basic option-handling (+220b). Untested
-rw-r--r-- | modutils/depmod.c | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/modutils/depmod.c b/modutils/depmod.c index 5d51ba450..710c3e540 100644 --- a/modutils/depmod.c +++ b/modutils/depmod.c | |||
@@ -27,7 +27,7 @@ struct globals { | |||
27 | static int fill_lst(const char *modulename, struct stat ATTRIBUTE_UNUSED *sb, | 27 | static int fill_lst(const char *modulename, struct stat ATTRIBUTE_UNUSED *sb, |
28 | void ATTRIBUTE_UNUSED *data, int ATTRIBUTE_UNUSED depth) | 28 | void ATTRIBUTE_UNUSED *data, int ATTRIBUTE_UNUSED depth) |
29 | { | 29 | { |
30 | llist_add_to(&G.lst, strdup(modulename)); | 30 | llist_add_to(&G.lst, xstrdup(modulename)); |
31 | return TRUE; | 31 | return TRUE; |
32 | } | 32 | } |
33 | 33 | ||
@@ -69,7 +69,7 @@ static int fileAction(const char *fname, struct stat *sb, | |||
69 | break; | 69 | break; |
70 | len -= ++ptr - the_module; | 70 | len -= ++ptr - the_module; |
71 | } while (1); | 71 | } while (1); |
72 | deps = depends = strdup (ptr + sizeof("depends=")-1); | 72 | deps = depends = xstrdup (ptr + sizeof("depends=")-1); |
73 | //bb_info_msg(" depends='%s'", depends); | 73 | //bb_info_msg(" depends='%s'", depends); |
74 | while (*deps) { | 74 | while (*deps) { |
75 | llist_t * _lst = G.lst; | 75 | llist_t * _lst = G.lst; |
@@ -106,18 +106,49 @@ int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
106 | int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv) | 106 | int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv) |
107 | { | 107 | { |
108 | int retval = EXIT_SUCCESS; | 108 | int retval = EXIT_SUCCESS; |
109 | // static const char moddir_base[] ALIGN1 = "/lib/modules/%s"; | 109 | char *moddir_base, *system_map, *chp; |
110 | FILE *filedes = xfopen("/tmp/modules.dep", "w"); | 110 | FILE *filedes = stdout; |
111 | enum { | ||
112 | ARG_a = (1<<0), /* All modules, ignore mods in argv */ | ||
113 | ARG_A = (1<<1), /* Only emit .ko that are newer than modules.dep file */ | ||
114 | ARG_b = (1<<2), /* not /lib/modules/$(uname -r)/ but this base-dir */ | ||
115 | ARG_e = (1<<3), /* with -F, print unresolved symbols */ | ||
116 | ARG_F = (1<<4), /* System.map that contains the symbols */ | ||
117 | ARG_n = (1<<5) /* dry-run, print to stdout only */ | ||
118 | }; | ||
111 | 119 | ||
112 | argv++; | 120 | getopt32(argv, "aAb:eF:n", &moddir_base, &system_map); |
121 | argv += optind; | ||
122 | if (*argv) /* got a version to use? */ | ||
123 | chp = *argv++; | ||
124 | else { | ||
125 | struct utsname uts; | ||
126 | if (uname(&uts) < 0) | ||
127 | bb_simple_perror_msg_and_die("uname"); | ||
128 | chp = xstrdup(uts.release); | ||
129 | } | ||
130 | moddir_base | ||
131 | = concat_path_file(option_mask32 & ARG_b ? moddir_base : "/lib/modules", | ||
132 | chp); | ||
133 | if (ENABLE_FEATURE_CLEAN_UP) | ||
134 | free(chp); | ||
135 | if (!(option_mask32 & ARG_n)) { | ||
136 | char *modules_dep = concat_path_file(moddir_base, "modules.dep"); | ||
137 | filedes = xfopen(modules_dep, "w"); | ||
138 | if (ENABLE_FEATURE_CLEAN_UP) | ||
139 | free(modules_dep); | ||
140 | } | ||
113 | do { | 141 | do { |
114 | if (!recursive_action(*argv, | 142 | chp = concat_path_file(moddir_base, |
143 | option_mask32 & ARG_a ? "/" : *argv++); | ||
144 | |||
145 | if (!recursive_action(chp, | ||
115 | ACTION_RECURSE, /* flags */ | 146 | ACTION_RECURSE, /* flags */ |
116 | fill_lst, /* file action */ | 147 | fill_lst, /* file action */ |
117 | NULL, /* dir action */ | 148 | NULL, /* dir action */ |
118 | NULL, /* user data */ | 149 | NULL, /* user data */ |
119 | 0) || /* depth */ | 150 | 0) || /* depth */ |
120 | !recursive_action(*argv, | 151 | !recursive_action(chp, |
121 | ACTION_RECURSE, /* flags */ | 152 | ACTION_RECURSE, /* flags */ |
122 | fileAction, /* file action */ | 153 | fileAction, /* file action */ |
123 | NULL, /* dir action */ | 154 | NULL, /* dir action */ |
@@ -125,11 +156,14 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv) | |||
125 | 0)) { /* depth */ | 156 | 0)) { /* depth */ |
126 | retval = EXIT_FAILURE; | 157 | retval = EXIT_FAILURE; |
127 | } | 158 | } |
128 | } while (*++argv); | 159 | if (ENABLE_FEATURE_CLEAN_UP) |
160 | free(chp); | ||
161 | } while (!(option_mask32 & ARG_a) || *argv); | ||
129 | 162 | ||
130 | if (ENABLE_FEATURE_CLEAN_UP) { | 163 | if (ENABLE_FEATURE_CLEAN_UP) { |
131 | fclose(filedes); | 164 | fclose(filedes); |
132 | llist_free(G.lst, free); | 165 | llist_free(G.lst, free); |
166 | free(moddir_base); | ||
133 | } | 167 | } |
134 | return retval; | 168 | return retval; |
135 | } | 169 | } |