Stop passing "http" to getaddrinfo in the case when we only need an IP
[sgt/agedu] / agedu.c
diff --git a/agedu.c b/agedu.c
index 00eda2b..411ae6a 100644 (file)
--- a/agedu.c
+++ b/agedu.c
@@ -502,8 +502,8 @@ int main(int argc, char **argv)
     time_t now = time(NULL);
     time_t textcutoff = now, htmlnewest = now, htmloldest = now;
     int htmlautoagerange = 1;
-    const char *httpserveraddr = NULL;
-    int httpserverport = 0;
+    const char *httpserveraddr = "localhost";
+    const char *httpserverport = NULL;
     const char *httpauthdata = NULL;
     const char *outfile = NULL;
     const char *html_title = PNAME;
@@ -821,10 +821,13 @@ int main(int argc, char **argv)
                        else
                            port = optval;
                        port += strcspn(port, ":");
-                       if (port)
+                       if (port && *port)
                            *port++ = '\0';
-                       httpserveraddr = optval;
-                       httpserverport = atoi(port);
+                        if (!strcmp(optval, "ANY"))
+                            httpserveraddr = NULL;
+                        else
+                            httpserveraddr = optval;
+                       httpserverport = port;
                    }
                    break;
                  case OPT_AUTH:
@@ -1143,7 +1146,6 @@ int main(int argc, char **argv)
                prevbuf[0] = '\0';
                tf = triewalk_next(tw, buf);
                assert(tf);
-               prevtf = NULL;         /* placate lint */
                while (1) {
                    int i;
 
@@ -1178,9 +1180,6 @@ int main(int argc, char **argv)
                        triewalk_rebase(tw, mappedfile);
                        diff = (const unsigned char *)mappedfile -
                            (const unsigned char *)oldfile;
-                       if (prevtf)
-                           prevtf = (const struct trie_file *)
-                               (((const unsigned char *)prevtf) + diff);
                        if (tf)
                            tf = (const struct trie_file *)
                                (((const unsigned char *)tf) + diff);
@@ -1247,7 +1246,8 @@ int main(int argc, char **argv)
                indexbuild_free(ib);
 
                munmap(mappedfile, totalsize);
-               ftruncate(fd, realsize);
+               if (ftruncate(fd, realsize) < 0)
+                    fatal("%s: truncate: %s\n", filename, strerror(errno));
                close(fd);
                printf("Final index file size = %llu bytes\n",
                       (unsigned long long)realsize);