Mercurial > hg > toybox
annotate toys/other/insmod.c @ 1736:5892daac85ab draft
Switch nsenter to default y.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 12 Mar 2015 15:34:03 -0500 |
parents | 4bfbd8b96f66 |
children | 57f2a26fa92c |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
1 /* insmod.c - Load a module into the Linux kernel. |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
2 * |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
3 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com> |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
4 |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
5 USE_INSMOD(NEWTOY(insmod, "<1", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
6 |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
7 config INSMOD |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
8 bool "insmod" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
9 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
10 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
11 usage: insmod MODULE [MODULE_OPTIONS] |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
12 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
13 Load the module named MODULE passing options if given. |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
14 */ |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
15 |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
16 #include "toys.h" |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
17 |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
18 #include <sys/syscall.h> |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
19 #define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts) |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
20 |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
21 void insmod_main(void) |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
22 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
23 char * buf = NULL; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
24 int len, res, i; |
1518
4bfbd8b96f66
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
25 int fd = xopen(*toys.optargs, O_RDONLY); |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
26 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
27 len = fdlength(fd); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
28 buf = xmalloc(len); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
29 xreadall(fd, buf, len); |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
30 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
31 i = 1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
32 while(toys.optargs[i] && |
1518
4bfbd8b96f66
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
33 strlen(toybuf) + strlen(toys.optargs[i]) + 2 < sizeof(toybuf)) |
4bfbd8b96f66
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
34 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
35 strcat(toybuf, toys.optargs[i++]); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
36 strcat(toybuf, " "); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
37 } |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
38 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
39 res = init_module(buf, len, toybuf); |
1518
4bfbd8b96f66
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
40 if (CFG_TOYBOX_FREE) { |
4bfbd8b96f66
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
41 if (buf != toybuf) free(buf); |
4bfbd8b96f66
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
42 close(fd); |
4bfbd8b96f66
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
43 } |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
44 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
45 if (res) perror_exit("failed to load %s", toys.optargs[0]); |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
46 } |