From: Michael Tremer Date: Wed, 3 Jun 2015 16:00:13 +0000 (+0200) Subject: rebuildhosts: Don't break when RED not online X-Git-Tag: v2.17-core91~24 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=e528fb2c7352bf8f2b5c2bc3e298bfa4c34b9d31;hp=bd33c332275ccb041a908c6e53ba78a1fa82f900 rebuildhosts: Don't break when RED not online The hosts file was not regenerated when RED was not connected which should not be happening. This patch checks if the file exists. If not, the gateway line will not be written to /etc/hosts. --- diff --git a/src/misc-progs/rebuildhosts.c b/src/misc-progs/rebuildhosts.c index fdaeed618e..f77c2dfb53 100644 --- a/src/misc-progs/rebuildhosts.c +++ b/src/misc-progs/rebuildhosts.c @@ -79,16 +79,13 @@ int main(int argc, char *argv[]) freekeyvalues(kv); kv = NULL; - if (!(gw = fopen(CONFIG_ROOT "/red/remote-ipaddress", "r"))) - { + if ((gw = fopen(CONFIG_ROOT "/red/remote-ipaddress", "r"))) { + if (fgets(gateway, STRING_SIZE, gw) == NULL) { + fprintf(stderr, "Couldn't read remote-ipaddress\n"); + exit(1); + } + } else { fprintf(stderr, "Couldn't open remote-ipaddress file\n"); - exit(1); - } - - if (fgets(gateway, STRING_SIZE, gw) == NULL) - { - fprintf(stderr, "Couldn't read remote-ipaddress\n"); - exit(1); } if (!(fd = fopen(CONFIG_ROOT "/main/hosts", "r"))) @@ -110,7 +107,8 @@ int main(int argc, char *argv[]) else fprintf(hosts, "%s\t%s\n",address,hostname); - fprintf(hosts, "%s\tgateway\n",gateway); + if (strlen(gateway) > 0) + fprintf(hosts, "%s\tgateway\n", gateway); while (fgets(buffer, STRING_SIZE, fd)) {