From: Sebastian Hammer Date: Sat, 10 Feb 1996 12:23:41 +0000 (+0000) Subject: Enable inetd operations fro TCP/IP stack X-Git-Tag: YAZ.1.8~808 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=9d17b5cfa8555d4762f162785edede1e0314cc07 Enable inetd operations fro TCP/IP stack --- diff --git a/include/comstack.h b/include/comstack.h index 8e619cb..2c8b4bd 100644 --- a/include/comstack.h +++ b/include/comstack.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: comstack.h,v $ - * Revision 1.13 1995-11-01 13:54:33 quinn + * Revision 1.14 1996-02-10 12:23:41 quinn + * Enable inetd operations fro TCP/IP stack + * + * Revision 1.13 1995/11/01 13:54:33 quinn * Minor adjustments * * Revision 1.12 1995/10/30 12:41:27 quinn @@ -113,7 +116,7 @@ struct comstack; typedef struct comstack *COMSTACK; -typedef COMSTACK (*CS_TYPE)(int blocking, int protocol); +typedef COMSTACK (*CS_TYPE)(int s, int blocking, int protocol); struct comstack { @@ -163,7 +166,9 @@ struct comstack #define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al)) #define cs_accept(handle) ((*(handle)->f_accept)(handle)) #define cs_close(handle) ((*(handle)->f_close)(handle)) -#define cs_create(type, blocking, proto) ((*type)(blocking, proto)) +#define cs_create(type, blocking, proto) ((*type)(-1, blocking, proto)) +#define cs_createbysocket(sock, type, blocking, proto) \ + ((*type)(sock, blocking, proto)) #define cs_type(handle) ((handle)->type) #define cs_fileno(handle) ((handle)->iofile) #define cs_stackerr(handle) ((handle)->stackerr) diff --git a/include/tcpip.h b/include/tcpip.h index 1aa4eba..4a898ac 100644 --- a/include/tcpip.h +++ b/include/tcpip.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: tcpip.h,v $ - * Revision 1.5 1995-09-29 17:12:13 quinn + * Revision 1.6 1996-02-10 12:23:42 quinn + * Enable inetd operations fro TCP/IP stack + * + * Revision 1.5 1995/09/29 17:12:13 quinn * Smallish * * Revision 1.4 1995/09/28 10:12:36 quinn @@ -67,6 +70,6 @@ struct sockaddr_in *tcpip_strtoaddr(const char *str); -COMSTACK tcpip_type(int blocking, int protocol); +COMSTACK tcpip_type(int s, int blocking, int protocol); #endif diff --git a/include/xmosi.h b/include/xmosi.h index 0b1a17a..384a2ba 100644 --- a/include/xmosi.h +++ b/include/xmosi.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: xmosi.h,v $ - * Revision 1.4 1995-09-29 17:12:13 quinn + * Revision 1.5 1996-02-10 12:23:43 quinn + * Enable inetd operations fro TCP/IP stack + * + * Revision 1.4 1995/09/29 17:12:13 quinn * Smallish * * Revision 1.3 1995/09/27 15:02:53 quinn @@ -60,6 +63,6 @@ struct netbuf *mosi_strtoaddr(const char *str); -COMSTACK mosi_type(int blocking, int protocol); +COMSTACK mosi_type(int s, int blocking, int protocol); #endif diff --git a/server/statserv.c b/server/statserv.c index 7587618..f40caac 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: statserv.c,v $ - * Revision 1.32 1996-01-19 15:41:52 quinn + * Revision 1.33 1996-02-10 12:23:49 quinn + * Enable inetd operations fro TCP/IP stack + * + * Revision 1.32 1996/01/19 15:41:52 quinn * *** empty log message *** * * Revision 1.31 1995/11/17 11:09:39 adam @@ -274,6 +277,34 @@ static void listener(IOCHAN h, int event) } } +static void inetd_connection(int what) +{ + COMSTACK line; + IOCHAN chan; + association *assoc; + char *addr; + + if (!(line = cs_createbysocket(0, tcpip_type, 0, what))) + { + logf(LOG_ERRNO|LOG_FATAL, "Failed to create comstack on socket 0"); + exit(1); + } + if (!(chan = iochan_create(cs_fileno(line), ir_session, EVENT_INPUT))) + { + logf(LOG_FATAL, "Failed to create iochan"); + exit(1); + } + if (!(assoc = create_association(chan, line))) + { + logf(LOG_FATAL, "Failed to create association structure"); + exit(1); + } + iochan_setdata(chan, assoc); + iochan_settimeout(chan, control_block.idle_timeout * 60); + addr = cs_addrstr(line); + logf(LOG_LOG, "Inetd association from %s", addr ? addr : "[UNKNOWN]"); +} + /* * Set up a listening endpoint, and give it to the event-handler. */ @@ -363,12 +394,12 @@ void statserv_setcontrol(statserv_options_block *block) int statserv_main(int argc, char **argv) { - int ret, listeners = 0; + int ret, listeners = 0, inetd = 0; char *arg; int protocol = control_block.default_proto; me = argv[0]; - while ((ret = options("a:szSl:v:u:c:", argv, argc, &arg)) != -2) + while ((ret = options("a:iszSl:v:u:c:w:", argv, argc, &arg)) != -2) { switch (ret) { @@ -393,17 +424,31 @@ int statserv_main(int argc, char **argv) strcpy(control_block.setuid, arg ? arg : ""); break; case 'c': strcpy(control_block.configname, arg ? arg : ""); break; + case 'i': + inetd = 1; break; + case 'w': + if (chdir(arg)) + { + perror(arg); + exit(1); + } + break; default: - fprintf(stderr, "Usage: %s [ -a -v " + fprintf(stderr, "Usage: %s [ -i -a -v " " -l -u -c " - " -zsS ... ]\n", me); + " -zsS -w ... ]\n", me); exit(1); } } - if (control_block.dynamic) - signal(SIGCHLD, catchchld); - if (!listeners && *control_block.default_listen) - add_listener(control_block.default_listen, protocol); + if (inetd) + inetd_connection(protocol); + else + { + if (control_block.dynamic) + signal(SIGCHLD, catchchld); + if (!listeners && *control_block.default_listen) + add_listener(control_block.default_listen, protocol); + } if (*control_block.setuid) { struct passwd *pw;