comparison toys/other/insmod.c @ 653:2986aa63a021

Move commands into "posix", "lsb", and "other" menus/directories.
author Rob Landley <rob@landley.net>
date Sat, 25 Aug 2012 14:25:22 -0500
parents toys/insmod.c@d473dff476e2
children 6df4ccc0acbe
comparison
equal deleted inserted replaced
652:2d7c56913fda 653:2986aa63a021
1 /* vi: set sw=4 ts=4:
2 *
3 * insmod.c - Load a module into the Linux kernel.
4 *
5 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
6 *
7 * Not in SUSv4.
8
9 USE_INSMOD(NEWTOY(insmod, "<1", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
10
11 config INSMOD
12 bool "insmod"
13 default y
14 help
15 usage: insmod MODULE [MODULE_OPTIONS]
16
17 Load the module named MODULE passing options if given.
18 */
19
20 #include "toys.h"
21
22 #include <sys/syscall.h>
23 #define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts)
24
25 void insmod_main(void)
26 {
27 char * buf = NULL;
28 int len, res, i;
29 int fd = xopen(toys.optargs[0], O_RDONLY);
30
31 len = fdlength(fd);
32 buf = xmalloc(len);
33 xreadall(fd, buf, len);
34
35 i = 1;
36 while(toys.optargs[i] &&
37 strlen(toybuf) + strlen(toys.optargs[i]) + 2 < sizeof(toybuf)) {
38 strcat(toybuf, toys.optargs[i++]);
39 strcat(toybuf, " ");
40 }
41
42 res = init_module(buf, len, toybuf);
43 if (CFG_TOYBOX_FREE && buf != toybuf) free(buf);
44
45 if (res)
46 perror_exit("failed to load %s", toys.optargs[0]);
47 }