]> andersk Git - moira.git/blobdiff - server/mr_scall.c
update for use with new com_err library
[moira.git] / server / mr_scall.c
index 37746d4a6f21a50a61fb7eaf9ec80248c5ff4cba..574ced8ec272526b9ba72103f1bd9b711dd7d23b 100644 (file)
@@ -4,6 +4,8 @@
  *     $Header$
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *     For copying and distribution information, please see the file
+ *     <mit-copyright.h>.
  *
  */
 
 static char *rcsid_sms_scall_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
 #include <krb.h>
 #include <errno.h>
 #include "query.h"
@@ -31,6 +37,8 @@ void
 do_client(cp)
        client *cp;
 {
+       struct stat stbuf;
+
        free_rtn_tuples(cp);
        if (OP_STATUS(cp->pending_op) == OP_CANCELLED) {
                com_err(whoami, 0, "Closed connection (now %d client%s, %d new queries, %d old)",
@@ -39,6 +47,14 @@ do_client(cp)
                        newqueries,
                        oldqueries);
                clist_delete(cp);
+               /* if we no longer have any clients, and we're supposed to
+                * go down, then go down now.
+                */
+               if ((dormant == AWAKE) && (nclients == 0) &&
+                   (stat(SMS_MOTD_FILE, &stbuf) == 0)) {
+                   com_err(whoami, 0, "motd file exists, slumbertime");
+                   dormant = SLEEPY;
+               }
                return;
        }
        switch (cp->action) {
@@ -69,6 +85,8 @@ char *procnames[] = {
         "shutdown",
         "query",
         "access",
+        "dcm",
+        "motd",
 };
 
 
@@ -92,6 +110,14 @@ do_call(cl)
        else if (log_flags & LOG_REQUESTS)
                com_err(whoami, 0, "%s", procnames[pn]);
 
+       if ((dormant == ASLEEP || dormant == GROGGY) &&
+           pn != SMS_NOOP && pn != SMS_MOTD) {
+           cl->reply.sms_status = SMS_DOWN;
+           if (log_flags & LOG_RES)
+             com_err(whoami, SMS_DOWN, "(query refused)");
+           return;
+       }
+
        switch(pn) {
        case SMS_NOOP:
                cl->reply.sms_status = 0;
@@ -116,6 +142,10 @@ do_call(cl)
        case SMS_DO_UPDATE:
                trigger_dcm(0, 0, cl);
                return;
+
+       case SMS_MOTD:
+               get_motd(cl);
+               return;
        }
 }
 
@@ -129,16 +159,6 @@ free_rtn_tuples(cp)
                if (t1 == cp->last) cp->last = NULL;
 
                sms_destroy_reply(t1->retval);
-#ifdef notdef
-               if (t1->retval) {
-                       register sms_params *p = t1->retval;
-                       if (p->sms_flattened)
-                               free(p->sms_flattened);
-                       if (p->sms_argl)
-                               free(p->sms_argl);
-                       free(p);
-               }
-#endif notdef
                delete_operation(t1->op);
                free(t1);
        }
@@ -299,6 +319,8 @@ trigger_dcm(dummy0, dummy1, cl)
        pid = vfork();
        switch (pid) {
        case 0:
+               for (dummy0 = getdtablesize() - 1; dummy0 > 2; dummy0--)
+                 close(dummy0);
                execl("/u1/sms/bin/startdcm", "startdcm", 0);
                exit(1);
                
@@ -311,3 +333,21 @@ trigger_dcm(dummy0, dummy1, cl)
        }
 }
 
+
+get_motd(cl)
+client *cl;
+{
+    int motd, len;
+    char buffer[1024];
+    char *arg[1];
+
+    arg[0] = buffer;
+    cl->reply.sms_status = 0;
+    motd = open(SMS_MOTD_FILE, 0, O_RDONLY);
+    if (motd < 0) return;
+    len = read(motd, buffer, sizeof(buffer) - 1);
+    close(motd);
+    buffer[len] = 0;
+    retr_callback(1, arg, cl);
+    cl->reply.sms_status = 0;
+}
This page took 0.066247 seconds and 4 git commands to generate.