diff options
author | Jaehyun Kim <jeik01.kim@samsung.com> | 2019-10-14 12:54:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.ap-northeast-2.compute.internal> | 2019-10-14 12:54:50 +0000 |
commit | 5f3b1826bfeda1ca9e5e9817b0fc77390d7e49b0 (patch) | |
tree | 1c87f7c6399b82d2bc988ee05591013ac159511a | |
parent | fcfb1714c531184c6e32b32fcd1a47714d054053 (diff) | |
parent | f53ccabb753a8a83467e1bc1d85dd2cea561f626 (diff) | |
download | connman-5f3b1826bfeda1ca9e5e9817b0fc77390d7e49b0.tar.gz connman-5f3b1826bfeda1ca9e5e9817b0fc77390d7e49b0.tar.bz2 connman-5f3b1826bfeda1ca9e5e9817b0fc77390d7e49b0.zip |
Merge "Use system hostname first" into tizensubmit/tizen/20191022.003657submit/tizen/20191021.013541submit/tizen/20191017.072410submit/tizen/20191016.060650submit/tizen/20191014.125724accepted/tizen/unified/20191022.150300
-rwxr-xr-x | plugins/loopback.c | 70 |
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)); |