ubase/rmmod.c

51 lines
754 B
C
Raw Normal View History

2013-08-09 04:42:34 -04:00
/* See LICENSE file for copyright and license details. */
#include <sys/syscall.h>
2014-06-30 14:03:41 -04:00
2013-08-09 04:42:34 -04:00
#include <fcntl.h>
2014-06-30 14:03:41 -04:00
#include <libgen.h>
2013-08-09 04:42:34 -04:00
#include <stdio.h>
2013-10-07 14:11:40 -04:00
#include <stdlib.h>
2013-08-09 04:42:34 -04:00
#include <string.h>
2014-06-30 14:03:41 -04:00
#include <unistd.h>
2013-08-09 04:42:34 -04:00
#include "util.h"
static void
usage(void)
{
2013-08-14 09:32:22 -04:00
eprintf("usage: %s [-fw] module...\n", argv0);
2013-08-09 04:42:34 -04:00
}
int
main(int argc, char *argv[])
{
char *mod, *p;
int i;
int flags = O_NONBLOCK;
ARGBEGIN {
case 'f':
flags |= O_TRUNC;
break;
case 'w':
flags &= ~O_NONBLOCK;
break;
default:
usage();
} ARGEND;
if (argc < 1)
usage();
for (i = 0; i < argc; i++) {
mod = argv[i];
p = strrchr(mod, '.');
if (p && !strcmp(p, ".ko"))
2013-08-09 04:42:34 -04:00
*p = '\0';
if (syscall(__NR_delete_module, mod, flags) < 0)
eprintf("delete_module:");
}
2014-10-02 18:45:25 -04:00
return 0;
2013-08-09 04:42:34 -04:00
}