Ejemplo n.º 1
0
// test_remove.cmt
static __noreturn int test_remove(const struct test *t)
{
	struct kmod_ctx *ctx;
	struct kmod_module *mod;
	const char *null_config = NULL;
	int err;

	ctx = kmod_new(NULL, &null_config);
	if (ctx == NULL)
		exit(EXIT_FAILURE);

	err = kmod_module_new_from_name(ctx, "ext4", &mod);
	if (err != 0) {
		ERR("could not create module from name: %m\n");
		exit(EXIT_FAILURE);
	}

	err = kmod_module_remove_module(mod, 0);
	if (err != 0) {
		ERR("could not remove module: %m\n");
		exit(EXIT_FAILURE);
	}
	kmod_unref(ctx);

	exit(EXIT_SUCCESS);
}
Ejemplo n.º 2
0
static int do_remove(int argc, char *argv[])
{
	struct kmod_ctx *ctx;
	struct kmod_module *mod;
	const char *name;
	int err, r = EXIT_SUCCESS;

	for (;;) {
		int c, idx =0;
		c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
		if (c == -1)
			break;
		switch (c) {
		case 'h':
			help();
			return EXIT_SUCCESS;

		default:
			ERR("Unexpected getopt_long() value '%c'.\n", c);
			return EXIT_FAILURE;
		}
	}

	if (optind >= argc) {
		ERR("Missing module name\n");
		return EXIT_FAILURE;
	}

	ctx = kmod_new(NULL, NULL);
	if (!ctx) {
		ERR("kmod_new() failed!\n");
		return EXIT_FAILURE;
	}

	name = argv[optind];
	err = kmod_module_new_from_name(ctx, name, &mod);
	if (err < 0) {
		ERR("Could not remove module %s: %s\n", name, strerror(-err));
		goto end;
	}

	err = check_module_inuse(mod);
	if (err < 0)
		goto unref;

	err = kmod_module_remove_module(mod, 0);
	if (err < 0)
		goto unref;

unref:
	kmod_module_unref(mod);

end:
	kmod_unref(ctx);
	if (err < 0) {
		r = EXIT_FAILURE;
		ERR("Could not remove module %s: %s\n", name, strerror(-err));
	}
	return r;
}
Ejemplo n.º 3
0
/** unload module
 *  
 * @param module Name of the module to unload
 * @return 0 on success, non-zero on failure
 *
 */
int usb_moded_unload_module(const char *module)
{
	int ret = 0;


#ifdef NO_KMOD
	gchar *command;

	if(!strcmp(module, MODULE_NONE))
		return 0;

	command = g_strconcat("rmmod ", module, NULL);
	ret = system(command);
	g_free(command);
#else
	struct kmod_module *mod;

	if(!strcmp(module, MODULE_NONE))
		return 0;

	kmod_module_new_from_name(ctx, module, &mod);
	ret = kmod_module_remove_module(mod, KMOD_REMOVE_NOWAIT);
	kmod_module_unref(mod);

#endif /* NO_KMOD */

	return(ret);
}
Ejemplo n.º 4
0
int test_parent_uuid(int loglevel, struct ndctl_test *test)
{
	struct ndctl_ctx *ctx;
	struct kmod_module *mod;
	struct kmod_ctx *kmod_ctx;
	int err, result = EXIT_FAILURE;

	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 3, 0)))
		return 77;

	err = ndctl_new(&ctx);
	if (err < 0)
		exit(EXIT_FAILURE);

	ndctl_set_log_priority(ctx, loglevel);

	kmod_ctx = kmod_new(NULL, NULL);
	if (!kmod_ctx)
		goto err_kmod;

	err = kmod_module_new_from_name(kmod_ctx, NFIT_TEST_MODULE, &mod);
	if (err < 0)
		goto err_module;

	err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST,
			NULL, NULL, NULL, NULL);
	if (err < 0) {
		result = 77;
		ndctl_test_skip(test);
		fprintf(stderr, "%s unavailable skipping tests\n",
				NFIT_TEST_MODULE);
		goto err_module;
	}

	err = do_test(ctx);
	if (err == 0)
		result = EXIT_SUCCESS;
	kmod_module_remove_module(mod, 0);

 err_module:
	kmod_unref(kmod_ctx);
 err_kmod:
	ndctl_unref(ctx);
	return result;
}
Ejemplo n.º 5
0
static int rmmod_do_remove_module(struct kmod_module *mod)
{
	const char *modname = kmod_module_get_name(mod);
	int flags = 0, err;

	SHOW("rmmod %s\n", kmod_module_get_name(mod));

	if (dry_run)
		return 0;

	if (force)
		flags |= KMOD_REMOVE_FORCE;

	err = kmod_module_remove_module(mod, flags);
	if (err == -EEXIST) {
		if (!first_time)
			err = 0;
		else
			LOG("Module %s is not in kernel.\n", modname);
	}

	return err;
}
Ejemplo n.º 6
0
static int do_rmmod(int argc, char**argv)
{
	struct kmod_ctx *ctx;
	const char *null_config = NULL;
	int flags = 0;
	int i, err, r = 0;

	for (;;) {
		int c, idx = 0;
		c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
		if (c == -1)
			break;
		switch (c) {
		case 'f':
			flags |= KMOD_REMOVE_FORCE;
			break;
		case 's':
			use_syslog = 1;
			break;
		case 'v':
			verbose++;
			break;
		case 'h':
			help(argc,argv);
			return EXIT_SUCCESS;
		case 'V':
			puts(PACKAGE " version " VERSION);
			return EXIT_SUCCESS;
		case '?':
			return EXIT_FAILURE;
		default:
			ERR("unexpected getopt_long() value '%c'.\n", c);
			return EXIT_FAILURE;
		}
	}

	log_open(use_syslog);

	if (optind >= argc) {
		ERR("missing module name.\n");
		r = EXIT_FAILURE;
		goto done;
	}

	ctx = kmod_new(NULL, &null_config);
	if (!ctx) {
		ERR("kmod_new() failed!\n");
		r = EXIT_FAILURE;
		goto done;
	}

	log_setup_kmod_log(ctx, verbose);

	for (i = optind; i < argc; i++) {
		struct kmod_module *mod;
		const char *arg = argv[i];
		struct stat st;
		if (stat(arg, &st) == 0)
			err = kmod_module_new_from_path(ctx, arg, &mod);
		else
			err = kmod_module_new_from_name(ctx, arg, &mod);

		if (err < 0) {
			ERR("could not use module %s: %s\n", arg,
			    strerror(-err));
			break;
		}

		if (!(flags & KMOD_REMOVE_FORCE) && check_module_inuse(mod) < 0) {
			r++;
			goto next;
		}

		err = kmod_module_remove_module(mod, flags);
		if (err < 0) {
			ERR("could not remove module %s: %s\n", arg,
			    strerror(-err));
			r++;
		}
next:
		kmod_module_unref(mod);
	}

	kmod_unref(ctx);

done:
	log_close();

	return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}