* $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"
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)",
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) {
"shutdown",
"query",
"access",
+ "dcm",
+ "motd",
};
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;
case SMS_DO_UPDATE:
trigger_dcm(0, 0, cl);
return;
+
+ case SMS_MOTD:
+ get_motd(cl);
+ return;
}
}
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);
}
pid = vfork();
switch (pid) {
case 0:
+ for (dummy0 = getdtablesize() - 1; dummy0 > 2; dummy0--)
+ close(dummy0);
execl("/u1/sms/bin/startdcm", "startdcm", 0);
exit(1);
}
}
+
+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;
+}