1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "toys.h"
17
18void insmod_main(void)
19{
20 int fd = xopenro(*toys.optargs);
21 int i, rc;
22
23 i = 1;
24 while (toys.optargs[i] &&
25 strlen(toybuf) + strlen(toys.optargs[i]) + 2 < sizeof(toybuf))
26 {
27 strcat(toybuf, toys.optargs[i++]);
28 strcat(toybuf, " ");
29 }
30
31
32 rc = syscall(SYS_finit_module, fd, toybuf, 0);
33 if (rc && (fd == 0 || errno == ENOSYS)) {
34 off_t len = 0;
35 char *path = !strcmp(*toys.optargs, "-") ? "/dev/stdin" : *toys.optargs;
36 char *buf = readfileat(AT_FDCWD, path, NULL, &len);
37
38 if (!buf) perror_exit("couldn't read %s", path);
39 rc = syscall(SYS_init_module, buf, len, toybuf);
40 if (CFG_TOYBOX_FREE) free(buf);
41 }
42
43 if (rc) perror_exit("failed to load %s", toys.optargs[0]);
44
45 if (CFG_TOYBOX_FREE) close(fd);
46}
47