summaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
authorDenis Vlasenko2006-11-21 11:58:14 +0000
committerDenis Vlasenko2006-11-21 11:58:14 +0000
commit9229794ab33fa510a5896784958b90f87bef6876 (patch)
treecbf063d72178aac42b71fe233dc20e5bc226463e /modutils
parenta8381948da79b06071c17853a9a2a59947742c8d (diff)
downloadbusybox-9229794ab33fa510a5896784958b90f87bef6876.zip
busybox-9229794ab33fa510a5896784958b90f87bef6876.tar.gz
insmod_ng_main: -80 bytes. Stopp mmapping, use xmalloc_open_read_close().
Diffstat (limited to 'modutils')
-rw-r--r--modutils/insmod.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c
index ff96736..11ba263 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -4263,38 +4263,32 @@ static const char *moderror(int err)
}
}
-int insmod_ng_main( int argc, char **argv)
+int insmod_ng_main(int argc, char **argv)
{
- int i;
- int fd;
- long int ret;
- struct stat st;
- unsigned long len;
+ long ret;
+ size_t len;
void *map;
- char *filename, *options = xstrdup("");
+ char *filename, *options;
- filename = argv[1];
- if (!filename) {
+ filename = *++argv;
+ if (!filename)
bb_show_usage();
- return -1;
- }
/* Rest is options */
- for (i = 2; i < argc; i++) {
- options = xrealloc(options, strlen(options) + 2 + strlen(argv[i]) + 2);
+ options = xstrdup("");
+ while (*++argv) {
+ int optlen = strlen(options);
+ options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
/* Spaces handled by "" pairs, but no way of escaping quotes */
- if (strchr(argv[i], ' ')) {
- strcat(options, "\"");
- strcat(options, argv[i]);
- strcat(options, "\"");
- } else {
- strcat(options, argv[i]);
- }
- strcat(options, " ");
+ sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv);
}
+#if 0
+ /* Any special reason why mmap? It isn't performace critical... */
+ int fd;
+ struct stat st;
+ unsigned long len;
fd = xopen(filename, O_RDONLY);
-
fstat(fd, &st);
len = st.st_size;
map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -4302,6 +4296,16 @@ int insmod_ng_main( int argc, char **argv)
bb_perror_msg_and_die("cannot mmap '%s'", filename);
}
+ /* map == NULL on Blackfin, probably on other MMU-less systems too. Workaround. */
+ if (map == NULL) {
+ map = xmalloc(len);
+ xread(fd, map, len);
+ }
+#else
+ len = MAXINT(ssize_t);
+ map = xmalloc_open_read_close(filename, &len);
+#endif
+
ret = syscall(__NR_init_module, map, len, options);
if (ret != 0) {
bb_perror_msg_and_die("cannot insert '%s': %s (%li)",