From f53ccabb753a8a83467e1bc1d85dd2cea561f626 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Mon, 14 Oct 2019 21:13:51 +0900 Subject: Use system hostname first Change-Id: If1a518bda6824919e46eca5d051bb27058fb385c Signed-off-by: Jaehyun Kim --- plugins/loopback.c | 70 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 30 deletions(-) (limited to 'plugins') 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)); -- cgit v1.2.3