X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/agedu/blobdiff_plain/0e005efab7da1a8cbf220ba2bb19c49ab96d9133..HEAD:/agedu.c diff --git a/agedu.c b/agedu.c index 9a354f8..1847e2c 100644 --- 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: @@ -1243,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); @@ -1268,6 +1272,11 @@ int main(int argc, char **argv) perror(PNAME ": mmap"); return 1; } + if (!trie_check_magic(mappedfile)) { + fprintf(stderr, "%s: %s: magic numbers did not match\n" + "%s: check that the index was built by this version of agedu on this platform\n", PNAME, filename, PNAME); + return 1; + } pathsep = trie_pathsep(mappedfile); /* @@ -1351,6 +1360,21 @@ int main(int argc, char **argv) } return 1; } + if (!trie_check_magic(mappedfile)) { + fprintf(stderr, "%s: %s: magic numbers did not match\n" + "%s: check that the index was built by this version of agedu on this platform\n", PNAME, filename, PNAME); + if (!querydir) { + printf("Status: 500\nContent-type: text/html\n\n" + "" + "500 Internal Server Error" + "" + "

500 Internal Server Error

" + "

agedu suffered an internal error." + "\n"); + return 0; + } + return 1; + } pathsep = trie_pathsep(mappedfile); maxpathlen = trie_maxpathlen(mappedfile); @@ -1553,6 +1577,11 @@ int main(int argc, char **argv) perror(PNAME ": mmap"); return 1; } + if (!trie_check_magic(mappedfile)) { + fprintf(stderr, "%s: %s: magic numbers did not match\n" + "%s: check that the index was built by this version of agedu on this platform\n", PNAME, filename, PNAME); + return 1; + } pathsep = trie_pathsep(mappedfile); maxpathlen = trie_maxpathlen(mappedfile); @@ -1585,6 +1614,11 @@ int main(int argc, char **argv) perror(PNAME ": mmap"); return 1; } + if (!trie_check_magic(mappedfile)) { + fprintf(stderr, "%s: %s: magic numbers did not match\n" + "%s: check that the index was built by this version of agedu on this platform\n", PNAME, filename, PNAME); + return 1; + } pathsep = trie_pathsep(mappedfile); dcfg.address = httpserveraddr;