Beispiel #1
0
static int insmod_do_insert_module(struct kmod_module *mod, const char *opts)
{
	int flags = 0, err;

	SHOW("insmod %s %s\n", kmod_module_get_path(mod), opts ? opts : "");

	if (dry_run)
		return 0;

	if (strip_modversion || force)
		flags |= KMOD_INSERT_FORCE_MODVERSION;
	if (strip_vermagic || force)
		flags |= KMOD_INSERT_FORCE_VERMAGIC;

	err = kmod_module_insert_module(mod, flags, opts);
	switch (err) {
	case -EEXIST:
		/*
		 * We checked for EEXIST with an earlier call to
		 * retrieve the initstate, but to avoid a race
		 * condition, we don't make any assumptions and handle
		 * the error again here
		 */
		if (!first_time)
			err = 0;
		else
			ERR("Module %s already in kernel.\n",
					kmod_module_get_name(mod));
		break;
	case -EPERM:
		ERR("could not insert '%s': %s\n", kmod_module_get_name(mod),
				strerror(-err));
		break;
	}

	return err;

}
Beispiel #2
0
/** load module 
 *
 * @param module Name of the module to load
 * @return 0 on success, non-zero on failure
 *
 */
int usb_moded_load_module(const char *module)
{
	int ret = 0;

#ifdef NO_KMOD
	gchar *command; 
	
	if(!strcmp(module, MODULE_NONE))
		return 0;
	
	command = g_strconcat("modprobe ", module, NULL);
	ret = system(command);
	if(!strcmp(module, MODULE_MASS_STORAGE) && (ret != 0))
	{
	  command = g_strconcat("modprobe ", MODULE_FILE_STORAGE, NULL);
	  ret = system(command);
	}
	if(!strcmp(module, MODULE_CHARGING) && (ret != 0))
	{
	  command = g_strconcat("modprobe ", MODULE_CHARGE_FALLBACK, NULL);
	  ret = system(command);
	}
	g_free(command);
#else
	const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
	struct kmod_module *mod;
	char *charging_args = NULL;
	char *load = NULL;

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

	/* copy module to load as it might be modified if we're trying charging mode */
	load = strdup(module);
	if(!strcmp(module, MODULE_CHARGING) || !strcmp(module, MODULE_CHARGE_FALLBACK))
	{
	  /* split the string in module name and argument, they are the same for MODULE_CHARGE_FALLBACK 
	     so no need to handle them separately  */
	  gchar **strings;

	  /* since the mass_storage module is the newer one and we check against it to avoid 
	     loading failures we use it here, as we fall back to g_file_storage if g_mass_storage 
	     fails to load */
	  strings = g_strsplit(MODULE_CHARGE_FALLBACK, " ", 2);
	  //log_debug("module args = %s, module = %s\n", strings[1], strings[0]);
          charging_args = strdup(strings[1]);
	  /* load was already assigned. Free it to re-assign */
	  free(load);
	  load = strdup(strings[0]);
	  g_strfreev(strings);
	  
	}
	ret = kmod_module_new_from_name(ctx, load, &mod);
	/* since kmod_module_new_from_name does not check if the module
           exists we test it's path in case we deal with the mass-storage one */
	if(!strcmp(module, MODULE_MASS_STORAGE) && 
	    (kmod_module_get_path(mod) == NULL))
	{
	  log_debug("Fallback on older g_file_storage\n");  
	  ret = kmod_module_new_from_name(ctx, MODULE_FILE_STORAGE, &mod);
	}

	if(!charging_args)
		ret = kmod_module_probe_insert_module(mod, probe_flags, NULL, NULL, NULL, NULL);
	else
	{
		ret = kmod_module_probe_insert_module(mod, probe_flags, charging_args, NULL, NULL, NULL);
		free(charging_args);
	}
	kmod_module_unref(mod);
	free(load);
#endif /* NO_KMOD */

	if( ret == 0)
		log_info("Module %s loaded successfully\n", module);
	else
		log_info("Module %s failed to load\n", module);
	return(ret);
}
Beispiel #3
0
static int modinfo_do(struct kmod_module *mod)
{
	struct kmod_list *l, *list = NULL;
	struct param *params = NULL;
	int err;

	if (field != NULL && strcmp(field, "filename") == 0) {
		printf("%s%c", kmod_module_get_path(mod), separator);
		return 0;
	} else if (field == NULL) {
		printf("%-16s%s%c", "filename:",
		       kmod_module_get_path(mod), separator);
	}

	err = kmod_module_get_info(mod, &list);
	if (err < 0) {
		LOG("could not get modinfo from '%s': %s\n",
			kmod_module_get_name(mod), strerror(-err));
		return err;
	}

	if (field != NULL && strcmp(field, "parm") == 0) {
		err = modinfo_params_do(list);
		goto end;
	}

	kmod_list_foreach(l, list) {
		const char *key = kmod_module_info_get_key(l);
		const char *value = kmod_module_info_get_value(l);
		int keylen;

		if (field != NULL) {
			if (strcmp(field, key) != 0)
				continue;
			/* filtered output contains no key, just value */
			printf("%s%c", value, separator);
			continue;
		}

		if (strcmp(key, "parm") == 0 || strcmp(key, "parmtype") == 0) {
			err = process_parm(key, value, &params);
			if (err < 0)
				goto end;
			continue;
		}

		if (separator == '\0') {
			printf("%s=%s%c", key, value, separator);
			continue;
		}

		keylen = strlen(key);
		printf("%s:%-*s%s%c", key, 15 - keylen, "", value, separator);
	}

	if (field != NULL)
		goto end;

	while (params != NULL) {
		struct param *p = params;
		params = p->next;

		if (p->param == NULL)
			printf("%-16s%.*s:%.*s%c", "parm:",
			       p->namelen, p->name, p->typelen, p->type,
			       separator);
		else if (p->type != NULL)
			printf("%-16s%.*s:%.*s (%.*s)%c", "parm:",
			       p->namelen, p->name,
			       p->paramlen, p->param,
			       p->typelen, p->type,
			       separator);
		else
			printf("%-16s%.*s:%.*s%c",
			       "parm:",
			       p->namelen, p->name,
			       p->paramlen, p->param,
			       separator);

		free(p);
	}

end:
	while (params != NULL) {
		void *tmp = params;
		params = params->next;
		free(tmp);
	}
	kmod_module_info_free_list(list);

	return err;
}