]> andersk Git - moira.git/blobdiff - gen/hosts.dc
Diane Delgado's changes for a fixed table-locking order
[moira.git] / gen / hosts.dc
index a4f27a1675824f75b85c6c47a50a99d46f8595a1..46a76745d4bd4c302e23ebe3894574a4660c3f05 100644 (file)
@@ -68,8 +68,19 @@ char **argv;
 
     EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
 
+    /* Acquire the required locks in the appropriate order */
+
+    EXEC SQL SELECT modtime INTO :name FROM machine WHERE mach_id = 0;
+    EXEC SQL SELECT modtime INTO :name FROM hostalias WHERE mach_id = 0;
+
     gettimeofday(&now, NULL);
-    fprintf(out, "; Host table generated %s;\n", ctime(&now.tv_sec));
+    
+    fprintf(out, "; MIT Network Host Table\n;\n");
+    fprintf(out, "; \t%cAuthor: $\n", '$');
+    fprintf(out, "; \t%cDate: $\n", '$');
+    fprintf(out, "; \t%cRevision: $\n;\n", '$');
+    fprintf(out, "; Host table generated by Moira at %s;\n",
+           ctime(&now.tv_sec));
 
     EXEC SQL DECLARE y CURSOR FOR SELECT
       mach_id, name FROM hostalias;
@@ -104,7 +115,6 @@ char **argv;
        if (id == 0) continue;
        if (*strtrim(name) == 0) continue;
        if ((i = strlen(name)) < 9 || strcmp(&name[i-8], ".MIT.EDU")) {
-           fprintf(stderr, "Name %s not in MIT domain\n", name);
            continue;
        } else {
            name[i-8] = 0;
@@ -113,17 +123,20 @@ char **argv;
        strtrim(model);
        strtrim(os);
        strtrim(addr);
-       if (*addr == 0)
+       if (*addr == 0 || inet_addr(addr) == -1)
          continue;
        if (p = hash_lookup(aliases, id))
          sprintf(buf, "%s,%s", name, p);
        else
          strcpy(buf, name);
        fprintf(out, "HOST : %s : %s : ", addr, buf);
-       if (*vendor && *model)
-         fprintf(out, "%s/%s : %s :\n", vendor, model, os);
-       else
-         fprintf(out, "%s%s : %s :\n", vendor, model, os);
+       if ((*vendor || *model) && *os) {
+           if (*vendor && *model)
+             fprintf(out, "%s/%s : %s :\n", vendor, model, os);
+           else
+             fprintf(out, "%s%s : %s :\n", vendor, model, os);
+       } else
+         fputs("\n", out);
     }
 
     EXEC SQL CLOSE x;
@@ -145,6 +158,10 @@ char **argv;
 
  sqlerr:
     com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
+#ifsql INGRES
+    if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000)
+      exit(MR_DEADLOCK);
+#endsql
     critical_alert("DCM", "Hosts build encountered INGRES ERROR %d",
                   sqlca.sqlcode);
     exit(MR_INGRES_ERR);
This page took 0.082649 seconds and 4 git commands to generate.