dhclient: fallback to /var/resolv.conf if /etc is read-only

This commit is contained in:
K. Lange 2021-09-02 15:26:11 +09:00
parent 783e6d69d6
commit 64bfcce029
2 changed files with 2 additions and 0 deletions

View File

@ -389,6 +389,7 @@ static int configure_interface(const char * if_name) {
ip_ntoa(ntohl(ip_data), addr);
printf("%s: %s: nameserver %s\n", _argv_0, if_name, addr);
FILE * resolve = fopen("/etc/resolv.conf","w");
if (!resolve) resolve = fopen("/var/resolv.conf","w");
if (resolve) {
fprintf(resolve, "nameserver %s\n", addr);
fclose(resolve);

View File

@ -237,6 +237,7 @@ struct hostent * gethostbyname(const char * name) {
/* Try to open /etc/resolv.conf */
FILE * resolv = fopen("/etc/resolv.conf","r");
if (!resolv) resolv = fopen("/var/resolv.conf","r");
if (!resolv) {
fprintf(stderr, "gethostbyname: no resolver\n");
return NULL;