Implemented logging into separate file for debugging
[mtetherd] / util.c
diff --git a/util.c b/util.c
index cc3966d..c746bf9 100644 (file)
--- a/util.c
+++ b/util.c
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
+#include <unistd.h>
 #include <glib.h>
+#include "util.h"
+#include "plugin.h"
 
 static const char *MODULE_LIST = "/proc/modules";
 
 gboolean mtetherd_scan_modules(const char *module) {
-       g_message("Scanning %s", MODULE_LIST);
+       g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Scanning %s", MODULE_LIST);
 
        FILE *fp = fopen(MODULE_LIST, "r");
        if (!fp) {
@@ -34,9 +37,9 @@ gboolean mtetherd_scan_modules(const char *module) {
        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);
+               g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Checking if '%s' starts with %s...", line, module);
+               if (g_str_has_prefix(line, module) == 0) {
+                       g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Found %s", module);
                        found = TRUE;
                }
                free(line);
@@ -47,16 +50,6 @@ gboolean mtetherd_scan_modules(const char *module) {
 }
 
 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) {