X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=server%2Fstatserv.c;h=2a0527c658c7b309d799606069fff54d873b39da;hp=b514f291520588fb8f31142be114178f446a8145;hb=348e11131385e72241a04997e90c8c77147e6423;hpb=8f7995bdfe85beb2ff6fa08e99bb05242f3bf71f diff --git a/server/statserv.c b/server/statserv.c index b514f29..2a0527c 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -7,7 +7,20 @@ * Chas Woodfield, Fretwell Downing Datasystems. * * $Log: statserv.c,v $ - * Revision 1.47 1998-02-10 10:28:57 adam + * Revision 1.51 1998-07-07 15:51:03 adam + * Changed server so that it stops if bind fails - "address already in + * use" typically causes this. + * + * Revision 1.50 1998/06/22 11:32:39 adam + * Added 'conditional cs_listen' feature. + * + * Revision 1.49 1998/02/27 14:04:55 adam + * Fixed bug in statserv_remove. + * + * Revision 1.48 1998/02/11 11:53:36 adam + * Changed code so that it compiles as C++. + * + * Revision 1.47 1998/02/10 10:28:57 adam * Added app_name, service_dependencies, service_display_name and * options_func. options_func allows us to specify a different function * to interogate the command line arguments. The other members allow us @@ -308,6 +321,7 @@ void statserv_remove(IOCHAN pIOChannel) { /* We need to look at another thread */ pNextThread = pCurrentThread->pNext; + pPrevThread = pCurrentThread; } } @@ -398,7 +412,7 @@ static void listener(IOCHAN h, int event) { if ((res = cs_listen(line, 0, 0)) < 0) { - logf(LOG_FATAL, "cs_listen failed."); + logf(LOG_FATAL, "cs_listen failed"); return; } else if (res == 1) @@ -488,6 +502,19 @@ void statserv_closedown() iochan_destroy(p); } +static int check_ip(void *cd, const char *addr, int len, int type) +{ + const unsigned char *ip = (const unsigned char *) addr; + int i; + char str[64]; + + sprintf (str, "%u", *ip); + for (i = 1; i<4; i++) + sprintf (str + strlen(str), ".%u", ip[i]); + logf (LOG_DEBUG, "ip %s", str); + return 0; +} + static void listener(IOCHAN h, int event) { COMSTACK line = (COMSTACK) iochan_getdata(h); @@ -525,7 +552,7 @@ static void listener(IOCHAN h, int event) { if (pp != h) { - COMSTACK l = iochan_getdata(pp); + COMSTACK l = (COMSTACK)iochan_getdata(pp); cs_close(l); iochan_destroy(pp); } @@ -555,9 +582,9 @@ static void listener(IOCHAN h, int event) return; } } - if ((res = cs_listen(line, 0, 0)) < 0) + if ((res = cs_listen_check(line, 0, 0, check_ip, 0)) < 0) { - logf(LOG_FATAL, "cs_listen failed."); + logf(LOG_WARN, "cs_listen failed"); return; } else if (res == 1) @@ -586,7 +613,7 @@ static void listener(IOCHAN h, int event) /* close our half of the listener socket */ for (pp = pListener; pp; pp = iochan_getnext(pp)) { - COMSTACK l = iochan_getdata(pp); + COMSTACK l = (COMSTACK)iochan_getdata(pp); cs_close(l); iochan_destroy(pp); } @@ -712,11 +739,15 @@ static void add_listener(char *where, int what) if (cs_bind(l, ap, CS_SERVER) < 0) { logf(LOG_FATAL|LOG_ERRNO, "Failed to bind to %s", where); + cs_close (l); + return; } if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT | EVENT_EXCEPT))) { logf(LOG_FATAL|LOG_ERRNO, "Failed to create IOCHAN-type"); + cs_close (l); + return; } iochan_setdata(lst, l); @@ -799,12 +830,14 @@ int statserv_start(int argc, char **argv) if ((pListener == NULL) && *control_block.default_listen) add_listener(control_block.default_listen, control_block.default_proto); - logf(LOG_LOG, "Entering event loop."); if (pListener == NULL) ret = 1; else + { + logf(LOG_LOG, "Entering event loop."); ret = event_loop(&pListener); + } nmem_exit (); return ret; }