diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
commit | e49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch) | |
tree | c90bda10731ad9333ce3b404f993354c9fc104b8 /modutils | |
parent | c0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff) | |
download | busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2 busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip |
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'modutils')
-rw-r--r-- | modutils/insmod.c | 240 | ||||
-rw-r--r-- | modutils/lsmod.c | 6 | ||||
-rw-r--r-- | modutils/rmmod.c | 55 |
3 files changed, 154 insertions, 147 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c index 31cb11261..7cbbed441 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Mini insmod implementation for busybox | 3 | * Mini insmod implementation for busybox |
3 | * | 4 | * |
@@ -41,8 +42,7 @@ | |||
41 | 42 | ||
42 | /* Some firendly syscalls to cheer everyone's day... */ | 43 | /* Some firendly syscalls to cheer everyone's day... */ |
43 | _syscall2(int, init_module, const char *, name, | 44 | _syscall2(int, init_module, const char *, name, |
44 | const struct module *, info) | 45 | const struct module *, info) |
45 | |||
46 | #ifndef BB_RMMOD | 46 | #ifndef BB_RMMOD |
47 | _syscall1(int, delete_module, const char *, name) | 47 | _syscall1(int, delete_module, const char *, name) |
48 | #else | 48 | #else |
@@ -52,155 +52,159 @@ extern int delete_module(const char *); | |||
52 | #if defined(__i386__) || defined(__m68k__) || defined(__arm__) | 52 | #if defined(__i386__) || defined(__m68k__) || defined(__arm__) |
53 | /* Jump through hoops to fixup error return codes */ | 53 | /* Jump through hoops to fixup error return codes */ |
54 | #define __NR__create_module __NR_create_module | 54 | #define __NR__create_module __NR_create_module |
55 | static inline _syscall2(long, _create_module, const char *, name, size_t, size) | 55 | static inline _syscall2(long, _create_module, const char *, name, size_t, |
56 | size) | ||
56 | unsigned long create_module(const char *name, size_t size) | 57 | unsigned long create_module(const char *name, size_t size) |
57 | { | 58 | { |
58 | long ret = _create_module(name, size); | 59 | long ret = _create_module(name, size); |
59 | if (ret == -1 && errno > 125) { | 60 | |
60 | ret = -errno; | 61 | if (ret == -1 && errno > 125) { |
61 | errno = 0; | 62 | ret = -errno; |
62 | } | 63 | errno = 0; |
63 | return ret; | 64 | } |
65 | return ret; | ||
64 | } | 66 | } |
65 | #else | 67 | #else |
66 | _syscall2(unsigned long, create_module, const char *, name, size_t, size) | 68 | _syscall2(unsigned long, create_module, const char *, name, size_t, size) |
67 | #endif | 69 | #endif |
68 | |||
69 | |||
70 | static char m_filename[PATH_MAX + 1] = "\0"; | 70 | static char m_filename[PATH_MAX + 1] = "\0"; |
71 | static char m_fullName[PATH_MAX + 1] = "\0"; | 71 | static char m_fullName[PATH_MAX + 1] = "\0"; |
72 | static const char insmod_usage[] = | 72 | static const char insmod_usage[] = |
73 | "insmod [OPTION]... MODULE [symbol=value]...\n\n" | 73 | "insmod [OPTION]... MODULE [symbol=value]...\n\n" |
74 | "Loads the specified kernel modules into the kernel.\n\n" | 74 | "Loads the specified kernel modules into the kernel.\n\n" |
75 | "Options:\n" | 75 | "Options:\n" |
76 | "\t-f\tForce module to load into the wrong kernel version.\n" | 76 | |
77 | "\t-k\tMake module autoclean-able.\n"; | 77 | "\t-f\tForce module to load into the wrong kernel version.\n" |
78 | "\t-k\tMake module autoclean-able.\n"; | ||
78 | 79 | ||
79 | 80 | ||
80 | static int findNamedModule(const char *fileName, struct stat* statbuf) | 81 | static int findNamedModule(const char *fileName, struct stat *statbuf) |
81 | { | 82 | { |
82 | if (m_fullName[0]=='\0') | 83 | if (m_fullName[0] == '\0') |
83 | return( FALSE); | 84 | return (FALSE); |
84 | else { | 85 | else { |
85 | char* tmp = strrchr( fileName, '/'); | 86 | char *tmp = strrchr(fileName, '/'); |
86 | if (tmp == NULL) | 87 | |
87 | tmp = (char*)fileName; | 88 | if (tmp == NULL) |
88 | else | 89 | tmp = (char *) fileName; |
89 | tmp++; | 90 | else |
90 | if (check_wildcard_match(tmp, m_fullName) == TRUE) { | 91 | tmp++; |
91 | /* Stop searching if we find a match */ | 92 | if (check_wildcard_match(tmp, m_fullName) == TRUE) { |
92 | memcpy(m_filename, fileName, strlen(fileName)); | 93 | /* Stop searching if we find a match */ |
93 | return( FALSE); | 94 | memcpy(m_filename, fileName, strlen(fileName)); |
95 | return (FALSE); | ||
96 | } | ||
94 | } | 97 | } |
95 | } | 98 | return (TRUE); |
96 | return( TRUE); | ||
97 | } | 99 | } |
98 | 100 | ||
99 | 101 | ||
100 | extern int insmod_main(int argc, char **argv) | 102 | extern int insmod_main(int argc, char **argv) |
101 | { | 103 | { |
102 | int len; | 104 | int len; |
103 | char *tmp; | 105 | char *tmp; |
104 | char m_name[PATH_MAX + 1] ="\0"; | 106 | char m_name[PATH_MAX + 1] = "\0"; |
105 | FILE *fp; | 107 | FILE *fp; |
106 | 108 | ||
107 | if (argc<=1) { | 109 | if (argc <= 1) { |
108 | usage( insmod_usage); | ||
109 | } | ||
110 | |||
111 | /* Parse any options */ | ||
112 | while (--argc > 0 && **(++argv) == '-') { | ||
113 | while (*(++(*argv))) { | ||
114 | switch (**argv) { | ||
115 | case 'f': | ||
116 | break; | ||
117 | case 'k': | ||
118 | break; | ||
119 | default: | ||
120 | usage(insmod_usage); | 110 | usage(insmod_usage); |
121 | } | ||
122 | } | 111 | } |
123 | } | 112 | |
124 | 113 | /* Parse any options */ | |
125 | if (argc <= 0 ) | 114 | while (--argc > 0 && **(++argv) == '-') { |
126 | usage(insmod_usage); | 115 | while (*(++(*argv))) { |
127 | 116 | switch (**argv) { | |
128 | /* Grab the module name */ | 117 | case 'f': |
129 | if ((tmp = strrchr(*argv, '/')) != NULL) | 118 | break; |
130 | tmp++; | 119 | case 'k': |
131 | else | 120 | break; |
132 | tmp = *argv; | 121 | default: |
133 | len = strlen(tmp); | 122 | usage(insmod_usage); |
134 | 123 | } | |
135 | if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') | 124 | } |
136 | len -= 2; | ||
137 | memcpy(m_name, tmp, len); | ||
138 | strcpy(m_fullName, m_name); | ||
139 | strcat(m_fullName, ".o"); | ||
140 | |||
141 | /* Get a filedesc for the module */ | ||
142 | if ((fp = fopen(*argv, "r")) == NULL) { | ||
143 | /* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */ | ||
144 | if (recursiveAction(_PATH_MODULES, TRUE, FALSE, FALSE, | ||
145 | findNamedModule, findNamedModule) == FALSE) { | ||
146 | if ( m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) { | ||
147 | perror("No module by that name found in " _PATH_MODULES "\n"); | ||
148 | exit( FALSE); | ||
149 | } | ||
150 | } | 125 | } |
151 | } else | ||
152 | memcpy(m_filename, *argv, strlen(*argv)); | ||
153 | 126 | ||
127 | if (argc <= 0) | ||
128 | usage(insmod_usage); | ||
154 | 129 | ||
155 | fprintf(stderr, "m_filename='%s'\n", m_filename); | 130 | /* Grab the module name */ |
156 | fprintf(stderr, "m_name='%s'\n", m_name); | 131 | if ((tmp = strrchr(*argv, '/')) != NULL) |
132 | tmp++; | ||
133 | else | ||
134 | tmp = *argv; | ||
135 | len = strlen(tmp); | ||
136 | |||
137 | if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') | ||
138 | len -= 2; | ||
139 | memcpy(m_name, tmp, len); | ||
140 | strcpy(m_fullName, m_name); | ||
141 | strcat(m_fullName, ".o"); | ||
142 | |||
143 | /* Get a filedesc for the module */ | ||
144 | if ((fp = fopen(*argv, "r")) == NULL) { | ||
145 | /* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */ | ||
146 | if (recursiveAction(_PATH_MODULES, TRUE, FALSE, FALSE, | ||
147 | findNamedModule, findNamedModule) == FALSE) { | ||
148 | if (m_filename[0] == '\0' | ||
149 | || ((fp = fopen(m_filename, "r")) == NULL)) { | ||
150 | perror("No module by that name found in " _PATH_MODULES | ||
151 | "\n"); | ||
152 | exit(FALSE); | ||
153 | } | ||
154 | } | ||
155 | } else | ||
156 | memcpy(m_filename, *argv, strlen(*argv)); | ||
157 | |||
158 | |||
159 | fprintf(stderr, "m_filename='%s'\n", m_filename); | ||
160 | fprintf(stderr, "m_name='%s'\n", m_name); | ||
161 | |||
162 | |||
163 | /* TODO: do something roughtly like this... */ | ||
164 | #if 0 | ||
157 | 165 | ||
166 | if ((f = obj_load(fp)) == NULL) { | ||
167 | perror("Could not load the module\n"); | ||
168 | exit(FALSE); | ||
169 | } | ||
158 | 170 | ||
159 | /* TODO: do something roughtly like this... */ | 171 | /* Let the module know about the kernel symbols. */ |
160 | #if 0 | 172 | add_kernel_symbols(f); |
161 | 173 | ||
162 | if ((f = obj_load(fp)) == NULL) { | 174 | if (!create_this_module(f, m_name)) { |
163 | perror("Could not load the module\n"); | 175 | perror("Could not create the module\n"); |
164 | exit( FALSE); | 176 | exit(FALSE); |
165 | } | ||
166 | |||
167 | /* Let the module know about the kernel symbols. */ | ||
168 | add_kernel_symbols(f); | ||
169 | |||
170 | if (!create_this_module(f, m_name)) { | ||
171 | perror("Could not create the module\n"); | ||
172 | exit( FALSE); | ||
173 | } | ||
174 | |||
175 | if (!obj_check_undefineds(f, quiet)) { | ||
176 | perror("Undefined symbols in the module\n"); | ||
177 | exit( FALSE); | ||
178 | } | ||
179 | obj_allocate_commons(f); | ||
180 | |||
181 | /* Perse the module's arguments */ | ||
182 | while (argc-- >0 && *(argv++) != '\0') { | ||
183 | if (!process_module_arguments(f, argc - optind, argv + optind)) { | ||
184 | perror("Undefined symbols in the module\n"); | ||
185 | exit( FALSE); | ||
186 | } | 177 | } |
187 | } | ||
188 | 178 | ||
189 | /* Find current size of the module */ | 179 | if (!obj_check_undefineds(f, quiet)) { |
190 | m_size = obj_load_size(f); | 180 | perror("Undefined symbols in the module\n"); |
181 | exit(FALSE); | ||
182 | } | ||
183 | obj_allocate_commons(f); | ||
184 | |||
185 | /* Perse the module's arguments */ | ||
186 | while (argc-- > 0 && *(argv++) != '\0') { | ||
187 | if (!process_module_arguments(f, argc - optind, argv + optind)) { | ||
188 | perror("Undefined symbols in the module\n"); | ||
189 | exit(FALSE); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /* Find current size of the module */ | ||
194 | m_size = obj_load_size(f); | ||
191 | 195 | ||
192 | 196 | ||
193 | errno = 0; | 197 | errno = 0; |
194 | m_addr = create_module(m_name, m_size); | 198 | m_addr = create_module(m_name, m_size); |
195 | switch (errno) { | 199 | switch (errno) { |
196 | /* yada yada */ | 200 | /* yada yada */ |
197 | default: | 201 | default: |
198 | perror("create_module: %m"); | 202 | perror("create_module: %m"); |
199 | 203 | ||
200 | } | 204 | } |
201 | 205 | ||
202 | #endif | 206 | #endif |
203 | 207 | ||
204 | fclose( fp); | 208 | fclose(fp); |
205 | exit( TRUE); | 209 | exit(TRUE); |
206 | } | 210 | } |
diff --git a/modutils/lsmod.c b/modutils/lsmod.c index 1696f756e..d9c40eaaf 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Mini lsmod implementation for busybox | 3 | * Mini lsmod implementation for busybox |
3 | * | 4 | * |
@@ -30,6 +31,7 @@ | |||
30 | 31 | ||
31 | extern int lsmod_main(int argc, char **argv) | 32 | extern int lsmod_main(int argc, char **argv) |
32 | { | 33 | { |
33 | char* cmd[] = { "cat", "/proc/modules", "\0" }; | 34 | char *cmd[] = { "cat", "/proc/modules", "\0" }; |
34 | exit(cat_main( 3, cmd)); | 35 | |
36 | exit(cat_main(3, cmd)); | ||
35 | } | 37 | } |
diff --git a/modutils/rmmod.c b/modutils/rmmod.c index 6b15b48bb..a0db4ae5c 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Mini rmmod implementation for busybox | 3 | * Mini rmmod implementation for busybox |
3 | * | 4 | * |
@@ -33,41 +34,41 @@ _syscall1(int, delete_module, const char *, name) | |||
33 | 34 | ||
34 | 35 | ||
35 | static const char rmmod_usage[] = | 36 | static const char rmmod_usage[] = |
36 | "rmmod [OPTION]... [MODULE]...\n\n" | 37 | "rmmod [OPTION]... [MODULE]...\n\n" |
37 | "Unloads the specified kernel modules from the kernel.\n\n" | 38 | "Unloads the specified kernel modules from the kernel.\n\n" |
38 | "Options:\n" | 39 | |
39 | "\t-a\tTry to remove all unused kernel modules.\n"; | 40 | "Options:\n" "\t-a\tTry to remove all unused kernel modules.\n"; |
40 | 41 | ||
41 | 42 | ||
42 | 43 | ||
43 | extern int rmmod_main(int argc, char **argv) | 44 | extern int rmmod_main(int argc, char **argv) |
44 | { | 45 | { |
45 | if (argc<=1) { | 46 | if (argc <= 1) { |
46 | usage(rmmod_usage); | 47 | usage(rmmod_usage); |
47 | } | 48 | } |
48 | 49 | ||
49 | /* Parse any options */ | 50 | /* Parse any options */ |
50 | while (--argc > 0 && **(++argv) == '-') { | 51 | while (--argc > 0 && **(++argv) == '-') { |
51 | while (*(++(*argv))) { | 52 | while (*(++(*argv))) { |
52 | switch (**argv) { | 53 | switch (**argv) { |
53 | case 'a': | 54 | case 'a': |
54 | /* Unload _all_ unused modules via NULL delete_module() call */ | 55 | /* Unload _all_ unused modules via NULL delete_module() call */ |
55 | if (delete_module(NULL)) { | 56 | if (delete_module(NULL)) { |
56 | perror("rmmod"); | 57 | perror("rmmod"); |
57 | exit( FALSE); | 58 | exit(FALSE); |
59 | } | ||
60 | exit(TRUE); | ||
61 | default: | ||
62 | usage(rmmod_usage); | ||
63 | } | ||
58 | } | 64 | } |
59 | exit( TRUE); | ||
60 | default: | ||
61 | usage(rmmod_usage); | ||
62 | } | ||
63 | } | 65 | } |
64 | } | ||
65 | 66 | ||
66 | while (argc-- > 0 ) { | 67 | while (argc-- > 0) { |
67 | if (delete_module(*argv) < 0) { | 68 | if (delete_module(*argv) < 0) { |
68 | perror(*argv); | 69 | perror(*argv); |
70 | } | ||
71 | argv++; | ||
69 | } | 72 | } |
70 | argv++; | 73 | exit(TRUE); |
71 | } | ||
72 | exit( TRUE); | ||
73 | } | 74 | } |