Use a more detailed list of special/default SSIDs
[connman] / plugins / loopback.c
index 7eac1e8..782853e 100644 (file)
@@ -39,6 +39,7 @@
 #include <connman/plugin.h>
 #include <connman/log.h>
 
+#if 0
 static GIOChannel *inotify_channel = NULL;
 
 static int hostname_descriptor = -1;
@@ -101,9 +102,6 @@ static int create_watch(void)
                return -EIO;
        }
 
-       g_io_add_watch(inotify_channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
-                                                       inotify_event, NULL);
-
        hostname_descriptor = inotify_add_watch(fd, "/etc/hostname",
                                IN_MODIFY | IN_DELETE_SELF | IN_MOVE_SELF);
        if (hostname_descriptor < 0) {
@@ -114,6 +112,9 @@ static int create_watch(void)
                return -EIO;
        }
 
+       g_io_add_watch(inotify_channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
+                                                       inotify_event, NULL);
+
        return 0;
 }
 
@@ -133,6 +134,15 @@ static void remove_watch(void)
 
        close(fd);
 }
+#endif
+
+static void create_hostname(void)
+{
+       const char *name = "localhost";
+
+       if (sethostname(name, strlen(name)) < 0)
+               connman_error("Failed to set hostname to %s", name);
+}
 
 static int setup_hostname(void)
 {
@@ -145,7 +155,20 @@ static int setup_hostname(void)
                return -EIO;
        }
 
-       connman_info("System hostname is %s", name);
+       if (strlen(name) > 0 && strcmp(name, "(none)") != 0)
+               connman_info("System hostname is %s", name);
+       else
+               create_hostname();
+
+       memset(name, 0, sizeof(name));
+
+       if (getdomainname(name, HOST_NAME_MAX) < 0) {
+               connman_error("Failed to get current domainname");
+               return -EIO;
+       }
+
+       if (strlen(name) > 0 && strcmp(name, "(none)") != 0)
+               connman_info("System domainname is %s", name);
 
        return 0;
 }
@@ -222,14 +245,14 @@ static int loopback_init(void)
 
        setup_hostname();
 
-       create_watch();
+       //create_watch();
 
        return 0;
 }
 
 static void loopback_exit(void)
 {
-       remove_watch();
+       //remove_watch();
 }
 
 CONNMAN_PLUGIN_DEFINE(loopback, "Loopback device plugin", VERSION,