X-Git-Url: http://git.maemo.org/git/?p=mtetherd;a=blobdiff_plain;f=util.c;fp=util.c;h=cc3966d84d2e73db87ed2b2fdd49c22658320d72;hp=0000000000000000000000000000000000000000;hb=a063cda5cff1e3ec56dabddd8ddcd42060a57fd4;hpb=1416438da8af731b20b15a20e41fd45c9fdfe632 diff --git a/util.c b/util.c new file mode 100644 index 0000000..cc3966d --- /dev/null +++ b/util.c @@ -0,0 +1,72 @@ +/* + mtetherd + (c) 2010 Gregor Riepl + + Tethering utility for Maemo + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include + +static const char *MODULE_LIST = "/proc/modules"; + +gboolean mtetherd_scan_modules(const char *module) { + g_message("Scanning %s", MODULE_LIST); + + FILE *fp = fopen(MODULE_LIST, "r"); + if (!fp) { + return FALSE; + } + gboolean found = FALSE; + char *line = NULL; + while (!found && getline(&line, NULL, fp) != -1) { + g_debug("Checking if '%s' starts with %s...", line, module); + if (strcmp(line, module, strlen(module)) == 0) { + g_message("Found %s", module); + found = TRUE; + } + free(line); + line = NULL; + } + fclose(fp); + return found; +} + +gboolean mtetherd_launch_script(const char *command[]) { +/* + const char *arg; + if (enable) { + arg = SBIN_DIR "mtetherd-usbnet-enable.sh"; + } else { + arg = SBIN_DIR "mtetherd-usbnet-disable.sh"; + } + g_debug("Launching %s", arg); + const char *command[] = { "/usr/bin/sudo", arg, NULL }; +*/ + pid_t pid = fork(); + if (pid == 0) { + if (execv(command[0], (char **const) command) == -1) { + exit(1); + } + } else if (pid == -1) { + // error forking + return FALSE; + } + // launch ok + return TRUE; +} +