summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaehyun Kim <jeik01.kim@samsung.com>2019-10-14 21:13:51 +0900
committerJaehyun Kim <jeik01.kim@samsung.com>2019-10-14 21:37:31 +0900
commitf53ccabb753a8a83467e1bc1d85dd2cea561f626 (patch)
tree0ca30cb9de55c2573d9072c296be3c2fa55e682f
parent85aa71a6d25c806e2ef43cbb3caddb1fcfb67f77 (diff)
downloadconnman-f53ccabb753a8a83467e1bc1d85dd2cea561f626.tar.gz
connman-f53ccabb753a8a83467e1bc1d85dd2cea561f626.tar.bz2
connman-f53ccabb753a8a83467e1bc1d85dd2cea561f626.zip
Use system hostname first
Change-Id: If1a518bda6824919e46eca5d051bb27058fb385c Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
-rwxr-xr-xplugins/loopback.c70
1 files changed, 40 insertions, 30 deletions
diff --git a/plugins/loopback.c b/plugins/loopback.c
index 55c8a218..28a59c9c 100755
--- a/plugins/loopback.c
+++ b/plugins/loopback.c
@@ -58,54 +58,64 @@ static void create_hostname(void)
strncpy(system_hostname, name, HOST_NAME_MAX);
}
-static int setup_hostname(void)
+#if defined TIZEN_EXT
+static void _create_hostname(void)
{
- char name[HOST_NAME_MAX + 1];
+ FILE *fp = NULL;
+#define WIFI_MAC "/opt/etc/.mac.info"
memset(system_hostname, 0, sizeof(system_hostname));
-#if defined TIZEN_EXT
- FILE *fp = NULL;
-#define WIFI_MAC "/opt/etc/.mac.info"
- {
- char* rv = 0;
- gchar* dev_id = "TIZEN";
- char wifi_mac[HOST_NAME_MAX + 1];
-
- fp = fopen(WIFI_MAC, "r");
- if(!fp){
- connman_error("Failed to get current hostname");
- strncpy(system_hostname, dev_id, strlen(dev_id));
- goto host_name_end;
- }
+ char* rv = 0;
+ gchar* dev_id = "TIZEN";
+ char wifi_mac[HOST_NAME_MAX + 1];
- rv = fgets(wifi_mac, HOST_NAME_MAX, fp);
- if(!rv){
- connman_error("Failed to get current hostname");
- strncpy(system_hostname, dev_id, strlen(dev_id));
- fclose(fp);
- goto host_name_end;
- }
+ fp = fopen(WIFI_MAC, "r");
+ if(!fp){
+ connman_error("Failed to get current hostname");
+ strncpy(system_hostname, dev_id, strlen(dev_id));
+ return;
+ }
- dev_id = g_base64_encode((const guchar *)wifi_mac, strlen(wifi_mac));
- g_sprintf(system_hostname, "TIZEN-%s", dev_id);
- g_free(dev_id);
+ rv = fgets(wifi_mac, HOST_NAME_MAX, fp);
+ if(!rv){
+ connman_error("Failed to get current hostname");
+ strncpy(system_hostname, dev_id, strlen(dev_id));
fclose(fp);
+ return;
}
-host_name_end:
-#else
+ dev_id = g_base64_encode((const guchar *)wifi_mac, strlen(wifi_mac));
+ g_sprintf(system_hostname, "TIZEN-%s", dev_id);
+ g_free(dev_id);
+ fclose(fp);
+}
+#endif
+
+static int setup_hostname(void)
+{
+ char name[HOST_NAME_MAX + 1];
+
+ memset(system_hostname, 0, sizeof(system_hostname));
+
if (gethostname(system_hostname, HOST_NAME_MAX) < 0) {
connman_error("Failed to get current hostname");
return -EIO;
}
-#endif
-
+#if defined TIZEN_EXT
+ if (strlen(system_hostname) > 0 &&
+ strcmp(system_hostname, "(none)") != 0 &&
+ strcmp(system_hostname, "localhost") != 0)
+ connman_info("System hostname is %s", system_hostname);
+ else
+ _create_hostname();
+#else
if (strlen(system_hostname) > 0 &&
strcmp(system_hostname, "(none)") != 0)
connman_info("System hostname is %s", system_hostname);
else
create_hostname();
+#endif
memset(name, 0, sizeof(name));