insmod_ng_main: -80 bytes. Stopp mmapping, use xmalloc_open_read_close().
This commit is contained in:
parent
a8381948da
commit
9229794ab3
@ -3,19 +3,18 @@
|
|||||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "unarchive.h"
|
#include "unarchive.h"
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count)
|
ssize_t archive_xread_all_eof(archive_handle_t *archive_handle,
|
||||||
|
unsigned char *buf, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
|
|
||||||
size = full_read(archive_handle->src_fd, buf, count);
|
size = full_read(archive_handle->src_fd, buf, count);
|
||||||
if ((size != 0) && (size != count)) {
|
if (size != 0 && size != count) {
|
||||||
bb_perror_msg_and_die("short read, read %ld of %ld", (long)size, (long)count);
|
bb_error_msg_and_die("short read: %u of %u",
|
||||||
|
(unsigned)size, (unsigned)count);
|
||||||
}
|
}
|
||||||
return(size);
|
return size;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
#define PATH_MAX 256
|
#define PATH_MAX 256
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Not (yet) used, but tested to work correctly
|
/* Tested to work correctly (IIRC :]) */
|
||||||
#define MAXINT(T) (T)( \
|
#define MAXINT(T) (T)( \
|
||||||
((T)-1) > 0 \
|
((T)-1) > 0 \
|
||||||
? (T)-1 \
|
? (T)-1 \
|
||||||
@ -72,7 +72,6 @@
|
|||||||
? (T)0 \
|
? (T)0 \
|
||||||
: ((T)1 << (sizeof(T)*8-1)) \
|
: ((T)1 << (sizeof(T)*8-1)) \
|
||||||
)
|
)
|
||||||
*/
|
|
||||||
|
|
||||||
/* Large file support */
|
/* Large file support */
|
||||||
/* Note that CONFIG_LFS forces bbox to be built with all common ops
|
/* Note that CONFIG_LFS forces bbox to be built with all common ops
|
||||||
|
@ -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;
|
long ret;
|
||||||
int fd;
|
size_t len;
|
||||||
long int ret;
|
|
||||||
struct stat st;
|
|
||||||
unsigned long len;
|
|
||||||
void *map;
|
void *map;
|
||||||
char *filename, *options = xstrdup("");
|
char *filename, *options;
|
||||||
|
|
||||||
filename = argv[1];
|
filename = *++argv;
|
||||||
if (!filename) {
|
if (!filename)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Rest is options */
|
/* Rest is options */
|
||||||
for (i = 2; i < argc; i++) {
|
options = xstrdup("");
|
||||||
options = xrealloc(options, strlen(options) + 2 + strlen(argv[i]) + 2);
|
while (*++argv) {
|
||||||
|
int optlen = strlen(options);
|
||||||
|
options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
|
||||||
/* Spaces handled by "" pairs, but no way of escaping quotes */
|
/* Spaces handled by "" pairs, but no way of escaping quotes */
|
||||||
if (strchr(argv[i], ' ')) {
|
sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv);
|
||||||
strcat(options, "\"");
|
|
||||||
strcat(options, argv[i]);
|
|
||||||
strcat(options, "\"");
|
|
||||||
} else {
|
|
||||||
strcat(options, argv[i]);
|
|
||||||
}
|
|
||||||
strcat(options, " ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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);
|
fd = xopen(filename, O_RDONLY);
|
||||||
|
|
||||||
fstat(fd, &st);
|
fstat(fd, &st);
|
||||||
len = st.st_size;
|
len = st.st_size;
|
||||||
map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
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);
|
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);
|
ret = syscall(__NR_init_module, map, len, options);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
bb_perror_msg_and_die("cannot insert '%s': %s (%li)",
|
bb_perror_msg_and_die("cannot insert '%s': %s (%li)",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user