Mercurial > hg > toybox
annotate toys/other/insmod.c @ 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.
The actual code should be the same afterward, this is just cosmetic refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 6df4ccc0acbe |
children | 4bfbd8b96f66 |
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; |
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
|
25 int fd = xopen(toys.optargs[0], 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] && |
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
|
33 strlen(toybuf) + strlen(toys.optargs[i]) + 2 < sizeof(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
|
34 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
|
35 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
|
36 } |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
37 |
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
|
38 res = init_module(buf, len, 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
|
39 if (CFG_TOYBOX_FREE && buf != toybuf) free(buf); |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
40 |
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
|
41 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
|
42 } |