Mercurial > hg > toybox
annotate toys/other/rmmod.c @ 782:3d7526f6115b
Use basename() where appropriate.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 05 Jan 2013 00:44:24 -0600 |
parents | 786841fdb1e0 |
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:
674
diff
changeset
|
1 /* rmmod.c - Remove a module from 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_RMMOD(NEWTOY(rmmod, "<1wf", 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 RMMOD |
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:
674
diff
changeset
|
8 bool "rmmod" |
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:
674
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:
674
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:
674
diff
changeset
|
11 usage: rmmod [-wf] [MODULE] |
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:
674
diff
changeset
|
13 Unload the module named MODULE from the Linux kernel. |
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:
674
diff
changeset
|
14 -f Force unload of a module |
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:
674
diff
changeset
|
15 -w Wait until the module is no longer used. |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
16 |
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 |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
19 #define FOR_rmmod |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
20 #include "toys.h" |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
21 |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
22 #include <sys/syscall.h> |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
23 #define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
24 |
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
25 void rmmod_main(void) |
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:
674
diff
changeset
|
27 unsigned int flags = O_NONBLOCK|O_EXCL; |
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:
674
diff
changeset
|
28 char * mod_name; |
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:
674
diff
changeset
|
29 int 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:
674
diff
changeset
|
31 // Basename |
782
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
32 mod_name = basename(*toys.optargs); |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
33 |
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:
674
diff
changeset
|
34 // Remove .ko if present |
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:
674
diff
changeset
|
35 len = strlen(mod_name); |
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:
674
diff
changeset
|
36 if (len > 3 && !strcmp(&mod_name[len-3], ".ko" )) mod_name[len-3] = 0; |
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:
674
diff
changeset
|
38 if (toys.optflags & FLAG_f) flags |= O_TRUNC; |
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:
674
diff
changeset
|
39 if (toys.optflags & FLAG_w) flags &= ~O_NONBLOCK; |
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:
674
diff
changeset
|
41 if (delete_module(mod_name, flags)) |
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:
674
diff
changeset
|
42 perror_exit("failed to unload %s", mod_name); |
489
d473dff476e2
Adding insmod and rmmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
43 } |