File: rmmod.c

package info (click to toggle)
android-platform-system-core 21-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,624 kB
  • ctags: 11,983
  • sloc: ansic: 70,139; cpp: 14,766; asm: 1,774; sh: 875; yacc: 137; python: 131; makefile: 120; lex: 103; java: 79
file content (53 lines) | stat: -rw-r--r-- 1,059 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <malloc.h>
#include <errno.h>
#include <asm/unistd.h>

extern int delete_module(const char *, unsigned int);

int rmmod_main(int argc, char **argv)
{
	int ret, i;
	char *modname, *dot;

	/* make sure we've got an argument */
	if (argc < 2) {
		fprintf(stderr, "usage: rmmod <module>\n");
		return -1;
	}

	/* if given /foo/bar/blah.ko, make a weak attempt
	 * to convert to "blah", just for convenience
	 */
	modname = strrchr(argv[1], '/');
	if (!modname)
		modname = argv[1];
	else modname++;

	dot = strchr(argv[1], '.');
	if (dot)
		*dot = '\0';

	/* Replace "-" with "_". This would keep rmmod
	 * compatible with module-init-tools version of
	 * rmmod
	 */
	for (i = 0; modname[i] != '\0'; i++) {
		if (modname[i] == '-')
			modname[i] = '_';
	}

	/* pass it to the kernel */
	ret = delete_module(modname, O_NONBLOCK | O_EXCL);
	if (ret != 0) {
		fprintf(stderr, "rmmod: delete_module '%s' failed (errno %d)\n",
						modname, errno);
		return -1;
	}

	return 0;
}