]> andersk Git - moira.git/blobdiff - server/mr_scall.c
improved DEC version of message about delete key;
[moira.git] / server / mr_scall.c
index db42bdc8aba2e47683b24fb6400831a006243aa2..574ced8ec272526b9ba72103f1bd9b711dd7d23b 100644 (file)
@@ -14,6 +14,9 @@ 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"
@@ -34,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)",
@@ -42,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) {
@@ -72,6 +85,8 @@ char *procnames[] = {
         "shutdown",
         "query",
         "access",
+        "dcm",
+        "motd",
 };
 
 
@@ -95,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;
@@ -119,6 +142,10 @@ do_call(cl)
        case SMS_DO_UPDATE:
                trigger_dcm(0, 0, cl);
                return;
+
+       case SMS_MOTD:
+               get_motd(cl);
+               return;
        }
 }
 
@@ -306,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.03869 seconds and 4 git commands to generate.