]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/misc-progs/rebuildhosts.c
rebuildhosts: Don't break when RED not online
[ipfire-2.x.git] / src / misc-progs / rebuildhosts.c
index e831858819e18d98c5e11404953bad65580cf4b6..f77c2dfb53da72f7cf4371110d219f34591fb308 100644 (file)
@@ -19,7 +19,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <signal.h>
+
 #include "setuid.h"
+#include "netutil.h"
 
 FILE *fd = NULL;
 FILE *hosts = NULL;
@@ -77,18 +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");
-               fclose(gw);
-               gw = NULL;
-               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))
        {