X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/5eaef52092da48d922a6b37cf48bb7c5104d0841..41ecb0f6e2cc3e9b4d29aad9672b8b39c70c4b95:/gen/hosts.pc diff --git a/gen/hosts.pc b/gen/hosts.pc index ecd35adc..62174d17 100644 --- a/gen/hosts.pc +++ b/gen/hosts.pc @@ -1,53 +1,52 @@ -/* $Header$ +/* $Id$ * * This generates the hstath.txt hosttable. * - * (c) Copyright 1993 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . + * (c) Copyright 1993-1998 by the Massachusetts Institute of Technology. + * For copying and distribution information, please see the file + * . */ #include -#include #include -#include + #include -#include + +#include +#include + +#include +#include +#include +#include + +#include "util.h" + EXEC SQL INCLUDE sqlca; -extern int errno; +RCSID("$Header$"); + char *whoami = "hosts.gen"; char *db = "moira/moira"; int main(int argc, char **argv) { FILE *out = stdout; - char *outf = NULL, outft[64], *p, buf[256]; - struct stat sb; + char *outf = NULL, outft[MAXPATHLEN], *p; struct timeval now; - int flag1, flag2, i; + int i; struct hash *aliases; EXEC SQL BEGIN DECLARE SECTION; int id; - char name[65], vendor[33], model[33], os[33], addr[17]; + char name[MACHINE_NAME_SIZE], vendor[MACHINE_VENDOR_SIZE]; + char model[MACHINE_MODEL_SIZE], os[MACHINE_OS_SIZE]; + char addr[MACHINE_ADDRESS_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL CONNECT :db; if (argc == 2) { - if (stat(argv[1], &sb) == 0) - { - if (ModDiff(&flag1, "machine", sb.st_mtime) || - ModDiff(&flag2, "subnet", sb.st_mtime)) - exit(MR_DATE); - if (flag1 < 0 && flag2 < 0) - { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } outf = argv[1]; sprintf(outft, "%s~", outf); if (!(out = fopen(outft, "w"))) @@ -87,38 +86,42 @@ int main(int argc, char **argv) continue; if (!*strtrim(name)) continue; - if ((i = strlen(name)) < 9 || strcmp(&name[i - 8], ".MIT.EDU")) + if ((i = strlen(name)) < 9 || !strchr(name, '.') || + strcmp(strchr(name, '.'), ".MIT.EDU")) { - fprintf(stderr, "Name %s not in MIT domain\n", name); + fprintf(stderr, "Ignoring alias %s\n", name); continue; } else name[i - 8] = 0; - if (p = hash_lookup(aliases, id)) + if ((p = hash_lookup(aliases, id))) { - sprintf(buf, "%s,%s", p, name); - hash_update(aliases, id, strsave(buf)); - free(p); + p = realloc(p, strlen(p) + strlen(name) + 2); + sprintf(strchr(p, '\0'), ",%s", name); + hash_update(aliases, id, p); } else - hash_store(aliases, id, strsave(name)); + hash_store(aliases, id, strdup(name)); } EXEC SQL DECLARE x CURSOR FOR SELECT name, mach_id, vendor, model, os, address - FROM machine WHERE status = 1 ORDER BY address; + FROM machine WHERE status = 1 AND mach_id > 0 + ORDER BY address; EXEC SQL OPEN x; while (1) { EXEC SQL FETCH x INTO :name, :id, :vendor, :model, :os, :addr; if (sqlca.sqlcode) break; - if (id == 0) - continue; if (!*strtrim(name)) continue; - if ((i = strlen(name)) < 9 || strcmp(&name[i - 8], ".MIT.EDU")) - continue; + if ((i = strlen(name)) < 9 || !strchr(name, '.') || + strcmp(strchr(name, '.'), ".MIT.EDU")) + { + fprintf(stderr, "Ignoring machine %s\n", name); + continue; + } else name[i - 8] = 0; strtrim(vendor); @@ -127,20 +130,18 @@ int main(int argc, char **argv) strtrim(addr); if (*addr == 0 || inet_addr(addr) == -1) continue; + fprintf(out, "HOST : %s : %s", addr, name); if ((p = hash_lookup(aliases, id))) - sprintf(buf, "%s,%s", name, p); - else - strcpy(buf, name); - fprintf(out, "HOST : %s : %s : ", addr, buf); + fprintf(out, ",%s", p); if ((*vendor || *model) && *os) { if (*vendor && *model) - fprintf(out, "%s/%s : %s :\n", vendor, model, os); + fprintf(out, " : %s/%s : %s :\n", vendor, model, os); else - fprintf(out, "%s%s : %s :\n", vendor, model, os); + fprintf(out, " : %s%s : %s :\n", vendor, model, os); } else - fputs("\n", out); + fputs(" : \n", out); } EXEC SQL CLOSE x;