]> andersk Git - moira.git/blobdiff - regtape/students.dc
Added missing definition of $(SRCDIR)
[moira.git] / regtape / students.dc
index 098a01946d8c17e9bd6d61dde2f65744da2e318d..80462c781370628ca552c4ddd08fbcea566aad11 100644 (file)
@@ -77,8 +77,9 @@ struct entry {
 char *whoami;
 int newfinger = 0;
 
-#define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 100)
 #define SQL_DUPLICATE -40100
+#define SQL_DEADLOCK -49900
+#define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 100)
 
 main(argc, argv)
 int argc;
@@ -124,11 +125,17 @@ char **argv;
     }
 
     while (e = get_next_entry(in)) {
+    again:
        process_entry(e);
        EXEC SQL COMMIT WORK;
        if (sqlca.sqlcode != 0) {
-           com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
-           exit(1);
+           if (sqlca.sqlcode == SQL_DEADLOCK) {
+               com_err(whoami, MR_DEADLOCK, "commiting work");
+               goto again;
+           } else {
+               com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+               exit(1);
+           }
        }
        if (wait) {
            printf("Next");
@@ -247,7 +254,7 @@ struct entry *e;
     int changed, nochange, encrypted;
     char buf[BUFSIZ], *from, *to;
     EXEC SQL BEGIN DECLARE SECTION;
-    char *first, *last, *eid, *title, *sid, *name, *rname, *rdept, *rtitle;
+    char *first, *last, *middle, *eid, *title, *sid, *name, *rname, *rdept, *rtitle;
     char *rophone, *rhphone, *prog;
     char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128];
     char dfirst[17], dlast[17], dmiddle[17];
@@ -262,12 +269,13 @@ struct entry *e;
     last = e->last;
     if (strlen(last) > 16)
       last[16] = 0;
+    middle = e->middle;
     eid = e->eid;
     sid = e->id;
     id = 0;
     encrypted = 0;
 
-/* Get user info */
+    /* Get user info */
     EXEC SQL REPEATED SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
       INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
       FROM users
@@ -276,6 +284,10 @@ struct entry *e;
        if (sqlca.sqlcode == SQL_DUPLICATE) {
            com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last);
            return;
+       } else if (sqlca.sqlcode == SQL_DEADLOCK) {
+           com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
+           EXEC SQL ROLLBACK;
+           return process_entry(e);
        } else
          sqlexit();
     }
@@ -284,7 +296,14 @@ struct entry *e;
          INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
          FROM users
          WHERE last = :last and first = :first and clearid = :eid;
-       if (sqlfail() && sqlca.sqlcode != SQL_DUPLICATE) sqlexit();
+       if (sqlfail()) {
+           if (sqlca.sqlcode == SQL_DEADLOCK) {
+               com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
+               EXEC SQL ROLLBACK;
+               return process_entry(e);
+           } else if (sqlca.sqlcode != SQL_DUPLICATE)
+             sqlexit();
+       }
        encrypted++;
        if (id == 0) {
            newuser(e);
@@ -292,10 +311,10 @@ struct entry *e;
        }
     }
 
-/* See if class changed: if it's different, and the value in the database
- * is not STAFF or SIPB, then update the database.  Since they were on the
- * students tape, make the account usable.
- */
+    /* See if class changed: if it's different, and the value in the database
    * is not STAFF or SIPB, then update the database.  Since they were on the
    * students tape, make the account usable.
    */
     if (strcmp(e->class, strtrim(class)) &&
        strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
        com_err(whoami, 0, "updating class for user %s %s from %s to %s",
@@ -313,8 +332,22 @@ struct entry *e;
        }
     }
 
-    /* Deal with updating the finger info if necessary */
+    /* Update name if necessary */
+    if (strcmp(first, strtrim(dfirst)) ||
+       strcmp(last, strtrim(dlast)) ||
+       strcmp(middle, strtrim(dmiddle))) {
+       com_err(whoami, 0, "updating real name for %s %s", first, last);
+       EXEC SQL UPDATE users
+         SET first = :first, last = :last, middle = :middle,
+               modby = :who, modwith = :prog, modtime = 'now'
+         WHERE users_id = :id;
+       if (sqlca.sqlcode != 0) {
+           com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+           exit(1);
+       }
+    }
 
+    /* Deal with updating the finger info if necessary */
     changed = nochange = 0;
     if (encrypted) changed++;
     strcpy(buf, e->address);
@@ -443,8 +476,14 @@ struct entry *e;
            xmodtime = date('now'), clearid = :sid
          WHERE users_id = :id;
        if (sqlca.sqlcode != 0) {
-           com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
-           exit(1);
+           if (sqlca.sqlcode == SQL_DEADLOCK) {
+               com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
+               EXEC SQL ROLLBACK;
+               return process_entry(e);
+           } else {
+               com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+               exit(1);
+           }
        }
     }  else {
        EXEC SQL REPEATED UPDATE users
@@ -453,8 +492,14 @@ struct entry *e;
            xmodtime = date('now'), clearid = :sid
          WHERE users_id = :id;
        if (sqlca.sqlcode != 0) {
-           com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
-           exit(1);
+           if (sqlca.sqlcode == SQL_DEADLOCK) {
+               com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
+               EXEC SQL ROLLBACK;
+               return process_entry(e);
+           } else {
+               com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+               exit(1);
+           }
        }
     }
 }
@@ -555,8 +600,14 @@ struct entry *e;
              :ophone, :dept, 'now', :who, :prog, 'NONE', :name, :dept,
              :title, :raddr, :hphone, :ophone, date('now'));
     if (sqlca.sqlcode != 0) {
-       com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
-       exit(1);
+       if (sqlca.sqlcode == SQL_DEADLOCK) {
+           com_err(whoami, MR_DEADLOCK, "adding user %s", sid);
+           EXEC SQL ROLLBACK;
+           return newuser(e);
+       } else {
+           com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+           exit(1);
+       }
     } else
       com_err(whoami, 0, "adding user %s %s", e->first, e->last);
 }
@@ -655,7 +706,11 @@ set_next_uid(limit)
 
 sqlexit()
 {
-    com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+    if (sqlca.sqlcode == SQL_DEADLOCK)
+      com_err(whoami, MR_DEADLOCK, "unrecoverable ingres error %d",
+             sqlca.sqlcode);
+    else
+      com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
     EXEC SQL ROLLBACK WORK;
     exit(1);
 }
This page took 0.038142 seconds and 4 git commands to generate.