aboutsummaryrefslogtreecommitdiff
path: root/modutils/insmod.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 11:58:14 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 11:58:14 +0000
commit9229794ab33fa510a5896784958b90f87bef6876 (patch)
treecbf063d72178aac42b71fe233dc20e5bc226463e /modutils/insmod.c
parenta8381948da79b06071c17853a9a2a59947742c8d (diff)
downloadbusybox-w32-9229794ab33fa510a5896784958b90f87bef6876.tar.gz
busybox-w32-9229794ab33fa510a5896784958b90f87bef6876.tar.bz2
busybox-w32-9229794ab33fa510a5896784958b90f87bef6876.zip
insmod_ng_main: -80 bytes. Stopp mmapping, use xmalloc_open_read_close().
Diffstat (limited to 'modutils/insmod.c')
-rw-r--r--modutils/insmod.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c
index ff96736af..11ba26344 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -4263,38 +4263,32 @@ static const char *moderror(int err)
4263 } 4263 }
4264} 4264}
4265 4265
4266int insmod_ng_main( int argc, char **argv) 4266int insmod_ng_main(int argc, char **argv)
4267{ 4267{
4268 int i; 4268 long ret;
4269 int fd; 4269 size_t len;
4270 long int ret;
4271 struct stat st;
4272 unsigned long len;
4273 void *map; 4270 void *map;
4274 char *filename, *options = xstrdup(""); 4271 char *filename, *options;
4275 4272
4276 filename = argv[1]; 4273 filename = *++argv;
4277 if (!filename) { 4274 if (!filename)
4278 bb_show_usage(); 4275 bb_show_usage();
4279 return -1;
4280 }
4281 4276
4282 /* Rest is options */ 4277 /* Rest is options */
4283 for (i = 2; i < argc; i++) { 4278 options = xstrdup("");
4284 options = xrealloc(options, strlen(options) + 2 + strlen(argv[i]) + 2); 4279 while (*++argv) {
4280 int optlen = strlen(options);
4281 options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
4285 /* Spaces handled by "" pairs, but no way of escaping quotes */ 4282 /* Spaces handled by "" pairs, but no way of escaping quotes */
4286 if (strchr(argv[i], ' ')) { 4283 sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv);
4287 strcat(options, "\"");
4288 strcat(options, argv[i]);
4289 strcat(options, "\"");
4290 } else {
4291 strcat(options, argv[i]);
4292 }
4293 strcat(options, " ");
4294 } 4284 }
4295 4285
4286#if 0
4287 /* Any special reason why mmap? It isn't performace critical... */
4288 int fd;
4289 struct stat st;
4290 unsigned long len;
4296 fd = xopen(filename, O_RDONLY); 4291 fd = xopen(filename, O_RDONLY);
4297
4298 fstat(fd, &st); 4292 fstat(fd, &st);
4299 len = st.st_size; 4293 len = st.st_size;
4300 map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); 4294 map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -4302,6 +4296,16 @@ int insmod_ng_main( int argc, char **argv)
4302 bb_perror_msg_and_die("cannot mmap '%s'", filename); 4296 bb_perror_msg_and_die("cannot mmap '%s'", filename);
4303 } 4297 }
4304 4298
4299 /* map == NULL on Blackfin, probably on other MMU-less systems too. Workaround. */
4300 if (map == NULL) {
4301 map = xmalloc(len);
4302 xread(fd, map, len);
4303 }
4304#else
4305 len = MAXINT(ssize_t);
4306 map = xmalloc_open_read_close(filename, &len);
4307#endif
4308
4305 ret = syscall(__NR_init_module, map, len, options); 4309 ret = syscall(__NR_init_module, map, len, options);
4306 if (ret != 0) { 4310 if (ret != 0) {
4307 bb_perror_msg_and_die("cannot insert '%s': %s (%li)", 4311 bb_perror_msg_and_die("cannot insert '%s': %s (%li)",