* NT threaded server code by
* Chas Woodfield, Fretwell Downing Informatics.
*
- * $Id: statserv.c,v 1.26 2005-03-08 11:07:50 adam Exp $
+ * $Id: statserv.c,v 1.30 2005-05-08 07:13:57 adam Exp $
*/
/**
#if HAVE_XML2
#include <libxml/parser.h>
#include <libxml/tree.h>
+#include <libxml/xinclude.h>
#endif
#if YAZ_POSIX_THREADS
static IOCHAN pListener = NULL;
+static char gfs_root_dir[FILENAME_MAX+1];
static struct gfs_server *gfs_server_list = 0;
static struct gfs_listen *gfs_listen_list = 0;
static NMEM gfs_nmem = 0;
return n;
}
+static void gfs_server_chdir(struct gfs_server *gfs)
+{
+ if (gfs_root_dir[0])
+ {
+ if (chdir(gfs_root_dir))
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "chdir %s", gfs_root_dir);
+ }
+ if (gfs->directory)
+ {
+ if (chdir(gfs->directory))
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "chdir %s",
+ gfs->directory);
+ }
+}
+
int control_association(association *assoc, const char *host, int force_open)
{
char vhost[128], *cp;
{
statserv_setcontrol(assoc->last_control);
if (assoc->backend && assoc->init)
+ {
+ gfs_server_chdir(gfs);
(assoc->last_control->bend_close)(assoc->backend);
+ }
assoc->backend = 0;
xfree(assoc->init);
assoc->init = 0;
- if (gfs->directory)
- {
- if (chdir(gfs->directory))
- yaz_log(YLOG_WARN|YLOG_ERRNO, "chdir %s",
- gfs->directory);
- }
}
assoc->cql_transform = gfs->cql_transform;
assoc->server_node_ptr = gfs->server_node_ptr;
assoc->last_control = &gfs->cb;
statserv_setcontrol(&gfs->cb);
+ gfs_server_chdir(gfs);
yaz_log(YLOG_DEBUG, "server select: %s", gfs->cb.configname);
return 1;
}
static void xml_config_open()
{
+ if (!getcwd(gfs_root_dir, FILENAME_MAX))
+ {
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "getcwd failed");
+ gfs_root_dir[0] = '\0';
+ }
#ifdef WIN32
init_control_tls = 1;
current_control_tls = TlsAlloc();
xml_config_doc = xmlParseFile(control_block.xml_config);
if (!xml_config_doc)
{
- yaz_log(YLOG_WARN, "Could not parse %s", control_block.xml_config);
- return ;
+ yaz_log(YLOG_FATAL, "Could not parse %s", control_block.xml_config);
+ exit(1);
+ }
+ else
+ {
+ int noSubstitutions = xmlXIncludeProcess(xml_config_doc);
+ if (noSubstitutions == -1)
+ {
+ yaz_log(YLOG_WARN, "XInclude processing failed for config %s",
+ control_block.xml_config);
+ exit(1);
+ }
}
}
xml_config_read();
gfs->cb.configname);
statserv_setcontrol(&gfs->cb);
if (control_block.bend_start)
+ {
+ gfs_server_chdir(gfs);
(control_block.bend_start)(&gfs->cb);
+ }
}
}
else
if (control_block.bend_start)
(*control_block.bend_start)(&control_block);
}
-
}
static void xml_config_bend_stop()
void statserv_setcontrol(statserv_options_block *block)
{
+ chdir(gfs_root_dir);
#ifdef WIN32
if (init_control_tls)
TlsSetValue(current_control_tls, block);
control_block.loglevel = yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL);
yaz_log_init_level(control_block.loglevel);
+ get_logbits(1);
while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:",
argv, argc, &arg)) != -2)
{
control_block.loglevel =
yaz_log_mask_str_x(arg,control_block.loglevel);
yaz_log_init(control_block.loglevel, me, control_block.logfile);
+ get_logbits(1);
break;
case 'a':
option_copy(control_block.apdufile, arg);
return 1;
}
}
- get_logbits(1);
return 0;
}