]> andersk Git - moira.git/blobdiff - server/qrtn.qc
added motd checking
[moira.git] / server / qrtn.qc
index 56be528b2639a59820cb2d72a8d2a44313db8aad..ec9cbe316a5f8a48a22f35b079d5d757741f8d8e 100644 (file)
@@ -4,6 +4,8 @@
  *     $Header$
  *
  *     Copyright (C) 1987, 1988 by the Massachusetts Institute of Technology
+ *     For copying and distribution information, please see the file
+ *     <mit-copyright.h>.
  * 
  */
 
 static char *rcsid_qrtn_qc = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include "query.h"
 #include "sms_server.h"
 
 char *Argv[16];
 
 int ingres_errno = 0;
+int sms_errcode = 0;
+## int query_timeout = 30;
 extern char *whoami;
 extern FILE *journal;
 
 #define INGRES_BAD_INT 4111
 #define INGRES_BAD_DATE 4302
 #define INGRES_DEADLOCK 4700
+#define INGRES_TIMEOUT 4702
 
 /*
  * ingerr: (supposedly) called when Ingres indicates an error.
@@ -33,20 +39,25 @@ extern FILE *journal;
 static int ingerr(num)
     int *num;
 {
-    char buf[256];
+    ingres_errno = *num;
 
     switch (*num) {
     case INGRES_BAD_INT:
-       ingres_errno = SMS_INTEGER;
+       sms_errcode = SMS_INTEGER;
        break;
     case INGRES_BAD_DATE:
-       ingres_errno = SMS_DATE;
+       sms_errcode = SMS_DATE;
        break;
     case INGRES_DEADLOCK:
-       ingres_errno = SMS_DEADLOCK;
+       sms_errcode = SMS_DEADLOCK;
+       com_err(whoami, 0, "INGRES deadlock detected");
+       break;
+    case INGRES_TIMEOUT:
+       sms_errcode = SMS_BUSY;
+       com_err(whoami, 0, "timed out getting lock");
        break;
     default:
-       ingres_errno = SMS_INGRES_ERR;
+       sms_errcode = SMS_INGRES_ERR;
        com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
        critical_alert("SMS", "SMS server encountered INGRES ERROR %d", *num);
        return (*num);
@@ -69,6 +80,7 @@ int sms_open_database()
        
     /* open the database */
 ##  ingres sms
+##  set lockmode session where level = table, timeout = query_timeout
     return ingres_errno;
 }
 
@@ -86,6 +98,8 @@ sms_check_access(cl, name, argc, argv_ro)
     struct query *q;
     struct query *get_query_by_name();
 
+    ingres_errno = 0;
+
     q = get_query_by_name(name, cl->args->sms_version_no);
     if (q == (struct query *)0)
        return(SMS_NO_HANDLE);
@@ -115,6 +129,8 @@ sms_process_query(cl, name, argc, argv_ro, action, actarg)
     struct save_queue *sq_create();
     char *build_sort();
 
+    ingres_errno = 0;
+
     /* list queries command */
     if (!strcmp(name, "_list_queries")) {
        list_queries(cl->args->sms_version_no, action, actarg);
@@ -136,9 +152,10 @@ sms_process_query(cl, name, argc, argv_ro, action, actarg)
     if (q == (struct query *)0) return(SMS_NO_HANDLE);
     v = q->validate;
 
-    ingres_errno = 0;
-    if (q->type != RETRIEVE)
+    if (q->type != RETRIEVE) {
+##     set lockmode session where readlock = exclusive
 ##      begin transaction
+    }
 
     /* setup argument vector, verify access and arguments */
     if ((status = sms_verify_query(cl, q, argc, argv_ro)) != SMS_SUCCESS)
@@ -308,12 +325,26 @@ out:
                fflush(journal);
            }
        } else {
-##          abort              /* it never happened */
+           if (ingres_errno != INGRES_DEADLOCK) {
+##             abort           /* it never happened */
+           }
        }
+##      set lockmode session where readlock = system
+    }
+
+    if (status == SMS_SUCCESS && ingres_errno != 0) {
+       critical_alert("SMS", "Server didn't notice INGRES ERROR %d",
+                      ingres_errno);
+       status = SMS_INTERNAL;
     }
 
     if (status != SMS_SUCCESS && log_flags & LOG_RES)
        com_err(whoami, status, " (Query failed)");
+    /* until all the clients know about SMS_BUSY, convert this error
+     * to one they will recognize.
+     */
+    if (status == SMS_BUSY)
+      status = SMS_DEADLOCK;
     return(status);
 }
 
@@ -403,13 +434,18 @@ sms_verify_query(cl, q, argc, argv_ro)
     register struct validate *v = q->validate;
     register int i;
     register int privileged = 0;
+    int len;
 
     /* copy the arguments into a local argv that we can modify */
+    if (argc >= QMAXARGS)
+      return(SMS_ARGS);
     for (i = 0; i < argc; i++) {
-       if (strlen(argv_ro[i]) < ARGLEN)
+       if ((len = strlen(argv_ro[i])) < ARGLEN)
            strcpy(Argv[i], argv_ro[i]);
        else
            return(SMS_ARG_TOO_LONG);
+       if (Argv[i][len-1] == '\\')
+         return(SMS_BAD_CHAR);
     }
 
     /* check initial query access */
@@ -778,7 +814,6 @@ set_next_object_id(object, table)
     if (LOG_RES)
         com_err(whoami, 0, "setting ID %s to %d", name, value);
 ##  repeat replace v (#value = @value) where v.#name = @name
-    if (ingres_errno != 0) return(ingres_errno);
     return(SMS_SUCCESS);
 ##}
 
@@ -808,16 +843,3 @@ sanity_check_queries()
        exit(1);
     }
 }
-
-
-/*
- * Local Variables:
- * mode: c
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */
-
This page took 0.050199 seconds and 4 git commands to generate.