static gboolean _doLoadModule(const gchar *module, gchar **args) { gint child; gint status; if (!(child = fork())) { gint i, rc; gchar **argv = NULL; gint fd = -1; if ((argv = g_malloc0(3 * sizeof(*argv))) == NULL) { if (loggingReady()) { logMessage(ERROR, "%s (%d): %m", __func__, __LINE__); } abort(); } if ((fd = open("/dev/tty3", O_RDWR)) == -1) { if (loggingReady()) { logMessage(ERROR, "%s (%d): %m", __func__, __LINE__); } } else { dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); close(fd); } argv[0] = "/sbin/modprobe"; argv[1] = g_strdup(module); argv[2] = NULL; if (args) { for (i = 0; args[i] ; i++) { _addOption(module, args[i]); } _writeModulesConf(MODULES_CONF); } rc = execv("/sbin/modprobe", argv); g_strfreev(argv); _exit(rc); } waitpid(child, &status, 0); if (!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) { return TRUE; } else { return FALSE; } }
int Config::addOption(const std::string &longArg, const std::string &name, double defaultValue) { int error; // add the option to the config system error = _addOption(longArg, name, DOUBLE); if(error) { return error; } // set the option to the default value error = setOption(name, defaultValue); if(error) { return error; } return 0; }
int Config::addOption(char shortArg, const std::string &longArg, const std::string &name, void (*defaultFn)(const std::string &)) { int error; // add the option to the config system error = _addOption(shortArg, longArg, name, FUNCTION); if(error) { return error; } // set the option to the default value error = setOption(name, defaultFn); if(error) { return error; } return 0; }
/** * Add a given option and sets its default value. The option is * specified as a short command line (-f), long command line (--foo), * option name (Foo), its type (integer or string), and its default * value. */ int Config::addOption(char shortArg, const std::string &longArg, const std::string &name, const std::string &defaultValue) { int error; // add the option to the config system error = _addOption(shortArg, longArg, name, STRING); if(error) { return error; } // set the option to the default value error = setOption(name, defaultValue); if(error) { return error; } return 0; }
gboolean mlInitModuleConfig(void) { GHashTableIter iter; gpointer key = NULL, value = NULL; GHashTable *cmdline = readvars_parse_file("/proc/cmdline"); if (cmdline == NULL) { return _writeModulesConf(MODULES_CONF); } g_hash_table_iter_init(&iter, cmdline); while (g_hash_table_iter_next(&iter, &key, &value)) { gchar *k = (gchar *) key; gchar *v = (gchar *) value; if (v == NULL) { continue; } else if (!strcasecmp(k, "blacklist")) { gchar *tmpmod = g_strdup(v); blacklist = g_slist_append(blacklist, tmpmod); } else if (!strstr(k, ".")) { gchar **fields = g_strsplit(k, ".", 0); if (g_strv_length(fields) == 2 && _isValidModule(fields[0])) { GString *tmp = g_string_new(fields[1]); g_string_append_printf(tmp, "=%s", v); _addOption(fields[0], tmp->str); g_string_free(tmp, TRUE); } g_strfreev(fields); } } g_hash_table_destroy(cmdline); return _writeModulesConf(MODULES_CONF); }
gboolean mlInitModuleConfig(void) { gint i = 0, j = 0; gchar *cmdline = NULL; gchar **options = NULL; GError *readErr = NULL; /* read module options out of /proc/cmdline and into a structure */ if (!g_file_get_contents("/proc/cmdline", &cmdline, NULL, &readErr)) { logMessage(ERROR, "unable to read /proc/cmdline: %s", readErr->message); g_error_free(readErr); return _writeModulesConf(MODULES_CONF); } cmdline = g_strchomp(cmdline); options = g_strsplit(cmdline, " ", 0); g_free(cmdline); if (options == NULL) { return _writeModulesConf(MODULES_CONF); } while (options[i] != NULL) { gchar *tmpmod = NULL; gchar **fields = NULL; gchar **blmods = NULL; if (g_strstr_len(options[i], -1, "=") == NULL) { i++; continue; } if (!strncmp(options[i], "blacklist=", 10) || !strncmp(options[i], "rdblacklist=", 12)) { if ((fields = g_strsplit(options[i], "=", 0)) != NULL) { if (g_strv_length(fields) <= 1) { g_strfreev(fields); continue; } if ((blmods = g_strsplit(fields[1], ",", 0)) != NULL) { for (j=0; j < g_strv_length(blmods); j++) { if (blmods[j] != NULL && g_strcmp0(blmods[j], "")) { tmpmod = g_strdup(blmods[j]); blacklist = g_slist_append(blacklist, tmpmod); } } g_strfreev(blmods); } } } else if ((fields = g_strsplit(options[i], ".", 0)) != NULL) { if (g_strv_length(fields) == 2) { if (_isValidModule(fields[0])) { _addOption(fields[0], fields[1]); } } } if (fields != NULL) { g_strfreev(fields); } i++; } if (options != NULL) { g_strfreev(options); } return _writeModulesConf(MODULES_CONF); }