From ccdaf5d5cd52555eefe9b22ea4bee98203e33626 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Fri, 16 Jun 1995 10:31:33 +0000 Subject: [PATCH] Added session timeout. --- server/eventl.c | 27 ++++++++++++++++++++++----- server/eventl.h | 8 +++++++- server/seshigh.c | 13 ++++++++++++- server/session.h | 6 +++++- server/statserv.c | 23 +++++++++++++++-------- 5 files changed, 61 insertions(+), 16 deletions(-) diff --git a/server/eventl.c b/server/eventl.c index 42dd1f9..7946839 100644 --- a/server/eventl.c +++ b/server/eventl.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: eventl.c,v $ - * Revision 1.9 1995-06-05 10:53:31 quinn + * Revision 1.10 1995-06-16 10:31:33 quinn + * Added session timeout. + * + * Revision 1.9 1995/06/05 10:53:31 quinn * Added a better SCAN. * * Revision 1.8 1995/05/16 08:51:01 quinn @@ -68,6 +71,7 @@ IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) new->fun = cb; new->next = iochans; new->force_event = 0; + new->last_event = new->max_idle = 0; iochans = new; return new; } @@ -79,13 +83,13 @@ int event_loop() IOCHAN p, nextp; fd_set in, out, except; int res, max; - static struct timeval nullto = {0, 0}; + static struct timeval nullto = {0, 0}, to = {60*5, 0}; struct timeval *timeout; FD_ZERO(&in); FD_ZERO(&out); FD_ZERO(&except); - timeout = 0; /* hang on select */ + timeout = &to; /* hang on select */ max = 0; for (p = iochans; p; p = p->next) { @@ -109,16 +113,29 @@ int event_loop() for (p = iochans; p; p = p->next) { int force_event = p->force_event; + time_t now = time(0); p->force_event = 0; if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT) + { + p->last_event = now; (*p->fun)(p, EVENT_INPUT); + } if (!p->destroyed && (FD_ISSET(p->fd, &out) || - force_event == EVENT_OUTPUT)) + force_event == EVENT_OUTPUT)) + { + p->last_event = now; (*p->fun)(p, EVENT_OUTPUT); + } if (!p->destroyed && (FD_ISSET(p->fd, &except) || force_event == EVENT_EXCEPT)) + { + p->last_event = now; (*p->fun)(p, EVENT_EXCEPT); + } + if (!p->destroyed && p->max_idle && now - p->last_event > + p->max_idle) + (*p->fun)(p, EVENT_TIMEOUT); } for (p = iochans; p; p = nextp) { @@ -135,7 +152,7 @@ int event_loop() for (pr = iochans; pr; pr = pr->next) if (pr->next == p) break; - assert(pr); + assert(pr); /* grave error if it weren't there */ pr->next = p->next; } if (nextp == p) diff --git a/server/eventl.h b/server/eventl.h index 129bf30..3b694a4 100644 --- a/server/eventl.h +++ b/server/eventl.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: eventl.h,v $ - * Revision 1.6 1995-05-16 08:51:02 quinn + * Revision 1.7 1995-06-16 10:31:34 quinn + * Added session timeout. + * + * Revision 1.6 1995/05/16 08:51:02 quinn * License, documentation, and memory fixes * * Revision 1.5 1995/05/15 11:56:37 quinn @@ -45,6 +48,8 @@ int force_event; IOC_CALLBACK fun; void *data; int destroyed; + time_t last_event; + time_t max_idle; struct iochan *next; } *IOCHAN; @@ -63,6 +68,7 @@ int force_event; #define iochan_setfun(i, d) ((i)->fun = d) #define iochan_setevent(i, e) ((i)->force_event = (e)) #define iochan_getnext(i) ((i)->next) +#define iochan_settimeout(i, t) ((i)->max_idle = (t)) IOCHAN iochan_getchan(void); IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags); diff --git a/server/seshigh.c b/server/seshigh.c index 6811402..be46c57 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: seshigh.c,v $ - * Revision 1.35 1995-06-15 07:45:14 quinn + * Revision 1.36 1995-06-16 10:31:36 quinn + * Added session timeout. + * + * Revision 1.35 1995/06/15 07:45:14 quinn * Moving to v3. * * Revision 1.34 1995/06/14 15:26:46 quinn @@ -277,6 +280,14 @@ void ir_session(IOCHAN h, int event) request *req; assert(h && conn && assoc); + if (event == EVENT_TIMEOUT) + { + logf(LOG_LOG, "Timeout - closing connection."); + cs_close(conn); + destroy_association(assoc); + iochan_destroy(h); + return; + } if (event & EVENT_INPUT || event & EVENT_WORK) /* input */ { if (event & EVENT_INPUT) diff --git a/server/session.h b/server/session.h index 5e44a74..83f0dd9 100644 --- a/server/session.h +++ b/server/session.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: session.h,v $ - * Revision 1.8 1995-05-17 08:42:28 quinn + * Revision 1.9 1995-06-16 10:31:38 quinn + * Added session timeout. + * + * Revision 1.8 1995/05/17 08:42:28 quinn * Transfer auth info to backend. Allow backend to reject init gracefully. * * Revision 1.7 1995/05/16 08:51:08 quinn @@ -39,6 +42,7 @@ #include #include #include +#include #include typedef struct request diff --git a/server/statserv.c b/server/statserv.c index 876328e..5edcc2e 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: statserv.c,v $ - * Revision 1.23 1995-06-15 12:30:48 quinn + * Revision 1.24 1995-06-16 10:31:39 quinn + * Added session timeout. + * + * Revision 1.23 1995/06/15 12:30:48 quinn * Setuid-facility. * * Revision 1.22 1995/06/15 07:45:17 quinn @@ -113,10 +116,10 @@ static statserv_options_block control_block = { LOG_DEFAULT_LEVEL, /* log level */ "", /* no PDUs */ "", /* diagnostic output to stderr */ - "tcp:@:9999", /* default listener port */ - PROTO_Z3950, /* application protocol */ - 60, /* idle timeout (minutes) */ - 1024*1024*4, /* maximum PDU size (approx.) to allow */ + "tcp:@:9999", /* default listener port */ + PROTO_Z3950, /* default application protocol */ + 2*60, /* idle timeout (minutes) */ + 1024*1024, /* maximum PDU size (approx.) to allow */ "default-config", /* configuration name to pass to backend */ "" /* set user id */ }; @@ -237,6 +240,7 @@ static void listener(IOCHAN h, int event) exit(1); } iochan_setdata(new_chan, newas); + iochan_settimeout(new_chan, control_block.idle_timeout * 60); logf(LOG_LOG, "accepted connection"); } else @@ -272,17 +276,20 @@ static void add_listener(char *where, int what) } type = tcpip_type; } -#ifdef USE_XTIMOSI else if (!strcmp(mode, "osi")) { +#ifdef USE_XTIMOSI if (!(ap = mosi_strtoaddr(addr))) { fprintf(stderr, "Address resolution failed for TCP.\n"); exit(1); } type = mosi_type; - } +#else + fprintf(stderr, "OSI Transport not allowed by configuration.\n"); + exit(1); #endif + } else { fprintf(stderr, "You must specify either 'osi:' or 'tcp:'.\n"); @@ -375,7 +382,7 @@ int statserv_main(int argc, char **argv) if (!(pw = getpwnam(control_block.setuid))) { - logf(LOG_FATAL|LOG_ERRNO, "%s", control_block.setuid); + logf(LOG_FATAL, "%s: Unknown user", control_block.setuid); exit(1); } if (setuid(pw->pw_uid) < 0) -- 1.7.10.4