mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2024-11-23 03:39:43 +00:00
dietlibc/dnscruft: try to get dns server via command if __sys_property_get fails
- bionic libc's property_get and __sys_property_get fail for statically compiled binaries - fallback to a default known dns server if all else fails
This commit is contained in:
parent
4b30a324c4
commit
d882a3fe44
@ -61,6 +61,9 @@ void __dns_readstartfiles(void) {
|
||||
#ifdef __BIONIC__
|
||||
char propvalue[PROP_VALUE_MAX];
|
||||
char propname[PROP_NAME_MAX];
|
||||
char propcmd[PROP_NAME_MAX+8];
|
||||
char pbuf[256];
|
||||
FILE *fp;
|
||||
int i;
|
||||
#endif
|
||||
|
||||
@ -73,7 +76,19 @@ void __dns_readstartfiles(void) {
|
||||
for(i = 1; i <= MAX_DNS_PROPERTIES; i++) {
|
||||
snprintf(propname, sizeof(propname), "%s%d", DNS_PROP_NAME_PREFIX, i);
|
||||
if(__system_property_get(propname, propvalue) < 1) {
|
||||
break;
|
||||
/* attempt to get the property via command instead since the call to Bionic libc failed */
|
||||
snprintf(propcmd, sizeof(propcmd), "getprop %s", propname);
|
||||
if((fp = popen(propcmd, "r"))) {
|
||||
if((fgets(pbuf, sizeof(pbuf)-1, fp) != NULL) && (strlen(pbuf) > 0)) {
|
||||
if (pbuf[strlen(pbuf)-1] == '\n')
|
||||
pbuf[strlen(pbuf)-1] = '\0'; /* strip trailing newline */
|
||||
strncpy(propvalue, pbuf, sizeof(propvalue));
|
||||
}
|
||||
}
|
||||
pclose(fp);
|
||||
memset(&propname[0], 0, sizeof(propname)); /* clear propname to avoid unpredictable behavior */
|
||||
if(strlen(propvalue) < 1)
|
||||
strcpy(propvalue, "8.8.8.8"); /* use a fallback nameserver since we still fail to get the property correctly */
|
||||
}
|
||||
|
||||
if (parsesockaddr(propvalue,&_diet_res.nsaddr_list[_diet_res.nscount]))
|
||||
|
Loading…
Reference in New Issue
Block a user