]> andersk Git - moira.git/blobdiff - gen/nfs.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / gen / nfs.qc
index 5949a299cd949eca6fedf4869fcb77f298dcc04a..65e8e16232b30114a75ff97a72d718685a7109db 100644 (file)
@@ -9,8 +9,8 @@
 
 #include <mit-copyright.h>
 #include <stdio.h>
-#include <sms.h>
-#include <sms_app.h>
+#include <moira.h>
+#include <moira_site.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -34,7 +34,7 @@ char **argv;
 
     if (argc > 2) {
        fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
-       exit(SMS_ARGS);
+       exit(MR_ARGS);
     }
 
     IIseterr(ingerr);
@@ -51,17 +51,17 @@ char **argv;
     if (!changed) {
        fprintf(stderr, "No files updated.\n");
        if (argc == 2 && stat(argv[1], &sb) == 0)
-         exit(SMS_NO_CHANGE);
+         exit(MR_NO_CHANGE);
     }
 
     if (argc == 2) {
        sprintf(cmd, "cd %s; cp %s/nfs/* .; tar cf %s .",
                nfs_dir, SMS_DIR, argv[1]);
        if (system(cmd))
-         exit(SMS_TAR_FAIL);
+         exit(MR_TAR_FAIL);
     }
 
-    exit(SMS_SUCCESS);
+    exit(MR_SUCCESS);
 }
 
 
@@ -80,12 +80,12 @@ static int ingerr(num)
 
     switch (*num) {
     case INGRES_DEADLOCK:
-       ingres_errno = SMS_DEADLOCK;
+       ingres_errno = MR_DEADLOCK;
        break;
     default:
-       ingres_errno = SMS_INGRES_ERR;
+       ingres_errno = MR_INGRES_ERR;
     }
-    com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
+    com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
     critical_alert("DCM", "NFS build encountered INGRES ERROR %d", *num);
     exit(ingres_errno);
 }
@@ -168,7 +168,7 @@ struct save_queue *lists;
        fd = fopen(file, "w");
        if (!fd) {
            fprintf(stderr, "cannot open %s for output\n", file);
-           exit(SMS_OCONFIG);
+           exit(MR_OCONFIG);
        }
 ##     repeat retrieve (id = m.member_id)
 ##         where m.list_id = l1.list_id and l1.name = @listname and
@@ -178,7 +178,7 @@ struct save_queue *lists;
 ##     }
        if (fclose(fd)) {
            fprintf(stderr, "error closing %s\n", file);
-           exit(SMS_CCONFIG);
+           exit(MR_CCONFIG);
        }
     }
 /* don't free here either
@@ -218,7 +218,7 @@ struct hash *do_everyone()
     fd = fopen(buf, "w");
     if (!fd) {
        fprintf(stderr, "cannot open %s for output\n", buf);
-       exit(SMS_OCONFIG);
+       exit(MR_OCONFIG);
     }
 
     /* make space for group list */
@@ -291,7 +291,7 @@ struct save_queue *machs;
 ##  range of s is serverhosts
 ##  range of m is machine
 ##  range of n is nfsphys
-##  range of q is nfsquota
+##  range of q is #quota
 ##  range of f is filesys
 ##  range of u is users
 ##  range of l is list
@@ -312,7 +312,7 @@ struct save_queue *machs;
        unlink(f2); /* ignore errors on this unlink */
        if (link(f1, f2)) {
            fprintf(stderr, "Cannot link %s to %s\n", f1, f2);
-           exit(SMS_OCONFIG);
+           exit(MR_OCONFIG);
        }
        hash_store(machines, id, machname);
     }
@@ -321,8 +321,8 @@ struct save_queue *machs;
     fd = stdin;
 ##  retrieve (quota = q.#quota, uid = u.#uid, flag1 = q.phys_id,
 ##           dev = n.device, flag2 = n.mach_id)
-##     where u.users_id = q.users_id and n.nfsphys_id = q.phys_id and
-##           q.phys_id != 0
+##     where u.users_id = q.entity_id and n.nfsphys_id = q.phys_id and
+##           q.phys_id != 0 and n.status < 16 and q.type = "USER"
 ##     sort by #flag2, #flag1, #uid {
       if (flag1 != olddev || flag2 != oldmach) {
          fclose(fd);
@@ -334,7 +334,7 @@ struct save_queue *machs;
          fd = fopen(file, "w");
          if (!fd) {
              fprintf(stderr, "cannot open %s for output\n", file);
-             exit(SMS_OCONFIG);
+             exit(MR_OCONFIG);
          }
          prevuid = -1;
          quotasum = 0;
@@ -350,9 +350,47 @@ struct save_queue *machs;
 ##  }
     if (quotasum)
       fprintf(fd, "%d %d\n", prevuid, quotasum);
-    if (fclose(fd)) {
+    if (fd != stdin && fclose(fd)) {
+       fprintf(stderr, "error closing %s", file);
+       exit(MR_CCONFIG);
+    }
+
+    olddev = oldmach = -1;
+    fd = stdin;
+##  retrieve (quota = q.#quota, gid = l.#gid, flag1 = q.phys_id,
+##           dev = n.device, flag2 = n.mach_id, flag3 = n.status)
+##     where l.list_id = q.entity_id and n.nfsphys_id = q.phys_id and
+##           q.phys_id != 0 and n.status > 15 and q.type = "GROUP"
+##     sort by #flag2, #flag1, #gid {
+      if (flag1 != olddev || flag2 != oldmach) {
+         fclose(fd);
+         olddev = flag1;
+         oldmach = flag2;
+         while (cp = index(dev, '/')) *cp = '@';
+         sprintf(file, "%s/%s.%s.quotas", nfs_dir,
+                 hash_lookup(machines, flag2), strtrim(dev));
+         fd = fopen(file, "w");
+         if (!fd) {
+             fprintf(stderr, "cannot open %s for output\n", file);
+             exit(MR_OCONFIG);
+         }
+         prevuid = -1;
+         quotasum = 0;
+      }
+      if (gid != prevuid) {
+         if (quotasum)
+           fprintf(fd, "%d %d\n", prevuid, quotasum);
+         prevuid = gid;
+         quotasum = quota;
+      } else {
+         quotasum += quota;
+      }
+##  }
+    if (quotasum)
+      fprintf(fd, "%d %d\n", prevuid, quotasum);
+    if (fd != stdin && fclose(fd)) {
        fprintf(stderr, "error closing %s", file);
-       exit(SMS_CCONFIG);
+       exit(MR_CCONFIG);
     }
 
     olddev = oldmach = -1;
@@ -373,14 +411,14 @@ struct save_queue *machs;
          fd = fopen(file, "w");
          if (!fd) {
              fprintf(stderr, "cannot open %s for output\n", file);
-             exit(SMS_OCONFIG);
+             exit(MR_OCONFIG);
          }
       }
       fprintf(fd, "%s %d %d %s\n", strtrim(dir), uid, gid, strtrim(fstype));
 ##  }
     if (fclose(fd)) {
        fprintf(stderr, "error closing %s", file);
-       exit(SMS_CCONFIG);
+       exit(MR_CCONFIG);
     }
 ##  end transaction
     return(1);
This page took 0.055733 seconds and 4 git commands to generate.