X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fstatserv.c;h=815b2e9aabac53832cc7e5bd83f3ae5d1d96720d;hp=adf1443b47a1311e519d06df9651d4f556d901a5;hb=8cb8947e3a7bff4dbf8f124871cb4905df1adce7;hpb=3a7d6f123828f282b26eddbb9724e4e03827605f diff --git a/src/statserv.c b/src/statserv.c index adf1443..815b2e9 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ @@ -163,7 +163,6 @@ static xmlNodePtr xml_config_get_root(void) yaz_log(YLOG_WARN, "Bad/missing root element for config %s", control_block.xml_config); return 0; - } } return ptr; @@ -227,6 +226,7 @@ static struct gfs_server * gfs_server_new(const char *id) n->directory = 0; n->docpath = 0; n->stylesheet = 0; + n->client_query_charset = 0; n->id = nmem_strdup_null(gfs_nmem, id); n->retrieval = yaz_retrieval_create(); return n; @@ -286,9 +286,15 @@ int control_association(association *assoc, const char *host, int force_open) int host_match = 0; if ( !gfs->host || (host && gfs->host && !strcmp(host, gfs->host))) host_match = 1; - if (!gfs->listen_ref || - gfs->listen_ref == assoc->client_chan->chan_id) + if (!gfs->listen_ref) listen_match = 1; + else + { + int i; + for (i = 0; gfs->listen_ref[i] != -1; i++) + if (gfs->listen_ref[i] == assoc->client_chan->chan_id) + listen_match = 1; + } if (listen_match && host_match) { if (force_open || @@ -390,17 +396,27 @@ static void xml_config_read(const char *base_path) gfs->server_node_ptr = ptr_server; if (listenref) { - int id_no; - struct gfs_listen *gl = gfs_listen_list; - for (id_no = 1; gl; gl = gl->next, id_no++) - if (gl->id && !strcmp(gl->id, listenref)) - { - gfs->listen_ref = id_no; - break; - } - if (!gl) - yaz_log(YLOG_WARN, "Non-existent listenref '%s' in server " - "config element", listenref); + char **refs; + int num, i; + nmem_strsplit(gfs_nmem, ",", listenref, &refs, &num); + gfs->listen_ref = (int*) nmem_malloc(gfs_nmem, + sizeof(int) * (num + 1)); + for (i = 0; i < num; i++) + { + int id_no; + struct gfs_listen *gl = gfs_listen_list; + gfs->listen_ref[i] = 0; + for (id_no = 1; gl; gl = gl->next, id_no++) + if (gl->id && !strcmp(gl->id, refs[i])) + { + gfs->listen_ref[i] = id_no; + break; + } + if (!gl) + yaz_log(YLOG_WARN, "Non-existent listenref '%s' " + "in server config element", refs[i]); + } + gfs->listen_ref[i] = -1; } for (ptr = ptr_server->children; ptr; ptr = ptr->next) { @@ -475,6 +491,12 @@ static void xml_config_read(const char *base_path) nmem_malloc(gfs_nmem, strlen(s) + 2); sprintf(gfs->stylesheet, "/%s", s); } + else if (!strcmp((const char *) ptr->name, + "client_query_charset")) + { + gfs->client_query_charset = + nmem_dup_xml_content(gfs_nmem, ptr->children); + } else if (!strcmp((const char *) ptr->name, "explain")) { ; /* being processed separately */ @@ -505,9 +527,8 @@ static void xml_config_read(const char *base_path) } #endif -static void xml_config_open(void) +static int xml_config_open(void) { - WRBUF base_path; const char *last_p; const char *fname = control_block.xml_config; if (!getcwd(gfs_root_dir, FILENAME_MAX)) @@ -526,7 +547,7 @@ static void xml_config_open(void) gfs_nmem = nmem_create(); #if YAZ_HAVE_XML2 if (fname[0] == '\0') - return; + return 0; if (!xml_config_doc) { @@ -534,7 +555,7 @@ static void xml_config_open(void) if (!xml_config_doc) { yaz_log(YLOG_FATAL, "Could not parse %s", fname); - exit(1); + return -1; } else { @@ -543,11 +564,10 @@ static void xml_config_open(void) { yaz_log(YLOG_WARN, "XInclude processing failed for config %s", fname); - exit(1); + return -1; } } } - base_path = wrbuf_alloc(); last_p = strrchr(fname, #ifdef WIN32 '\\' @@ -556,12 +576,16 @@ static void xml_config_open(void) #endif ); if (last_p) + { + WRBUF base_path = wrbuf_alloc(); wrbuf_write(base_path, fname, last_p - fname); + xml_config_read(wrbuf_cstr(base_path)); + wrbuf_destroy(base_path); + } else - wrbuf_puts(base_path, "."); - xml_config_read(wrbuf_cstr(base_path)); - wrbuf_destroy(base_path); + xml_config_read(0); #endif + return 0; } static void xml_config_close(void) @@ -584,16 +608,18 @@ static void xml_config_close(void) #endif } -static void xml_config_add_listeners(void) +static int xml_config_add_listeners(void) { struct gfs_listen *gfs = gfs_listen_list; int id_no; + int ret = 0; for (id_no = 1; gfs; gfs = gfs->next, id_no++) { - if (gfs->address) - add_listener(gfs->address, id_no); + if (!ret && gfs->address) + ret = add_listener(gfs->address, id_no); } + return ret; } static void xml_config_bend_start(void) @@ -813,7 +839,7 @@ static void statserv_closedown() void __cdecl event_loop_thread(IOCHAN iochan) { - iochan_event_loop(&iochan); + iochan_event_loop(&iochan, 0); } /* WIN32 listener */ @@ -1061,7 +1087,7 @@ static void *new_session(void *vp) control_block.one_shot = 1; if (control_block.threads) { - iochan_event_loop(&new_chan); + iochan_event_loop(&new_chan, 0); } else { @@ -1228,19 +1254,31 @@ static void statserv_reset(void) { } +static int sig_received = 0; + +#ifndef WIN32 +static void normal_stop_handler(int num) +{ + sig_received = num; +} +#endif + static void daemon_handler(void *data) { IOCHAN *pListener = data; - iochan_event_loop(pListener); + iochan_event_loop(pListener, &sig_received); } -#ifndef WIN32 -static void normal_stop_handler(int num) +static void show_version(void) { - yaz_log(log_server, "Received SIGTERM. PID=%ld", (long) getpid()); + char vstr[20], sha1_str[41]; + + yaz_version(vstr, sha1_str); + printf("YAZ version: %s %s\n", YAZ_VERSION, YAZ_VERSION_SHA1); + if (strcmp(sha1_str, YAZ_VERSION_SHA1)) + printf("YAZ DLL/SO: %s %s\n", vstr, sha1_str); exit(0); } -#endif static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) { @@ -1266,7 +1304,8 @@ static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) if (control_block.options_func(argc, argv)) return 1; - xml_config_open(); + if (xml_config_open()) + return 1; xml_config_bend_start(); @@ -1280,7 +1319,8 @@ static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) } else { - xml_config_add_listeners(); + if (xml_config_add_listeners()) + return 1; if (!pListener) add_listener("tcp:@:9999", 0); @@ -1303,6 +1343,10 @@ static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) daemon_handler, &pListener, *control_block.pid_fname ? control_block.pid_fname : 0, *control_block.setuid ? control_block.setuid : 0); +#ifndef WIN32 + if (sig_received) + yaz_log(YLOG_LOG, "Received SIGTERM PID=%ld", (long) getpid()); +#endif return 0; } @@ -1321,7 +1365,7 @@ int check_options(int argc, char **argv) get_logbits(1); - while ((ret = options("1a:iszSTl:v:u:c:w:t:k:Kd:A:p:DC:f:m:r:", + while ((ret = options("1a:iszSTl:v:u:c:w:t:k:Kd:A:p:DC:f:m:r:V", argv, argc, &arg)) != -2) { switch (ret) @@ -1437,11 +1481,14 @@ int check_options(int argc, char **argv) } yaz_log_init_max_size(r * 1024); break; + case 'V': + show_version(); + break; default: fprintf(stderr, "Usage: %s [ -a -v " " -l -u -c -t " " -k -d -p -C certfile" - " -zKiDST1 -m -w ... ]\n", me); + " -zKiDSTV1 -m -w ... ]\n", me); return 1; } }