From 3b96525a40981e162b959f3e842e0ff20e314320 Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Thu, 18 Nov 2004 15:18:10 +0000 Subject: [PATCH] Deprecated log.h and created a new ylog.h Renamed all LOG_ #defines to matching YLOG_, and used them everywhere Used the new dynamic log system in deveral places --- client/client.c | 4 +- include/yaz/Makefile.am | 4 +- include/yaz/log.h | 114 ++++++++------------------------------ include/yaz/yaz-util.h | 4 +- include/yaz/ylog.h | 141 +++++++++++++++++++++++++++++++++++++++++++++++ src/eventl.c | 21 +++++-- src/log.c | 62 ++++++++++----------- src/logrpn.c | 12 ++-- src/nmem.c | 81 ++++++++++++++++++--------- src/odr.c | 24 ++++++-- src/odr_oct.c | 3 +- src/readconf.c | 6 +- src/seshigh.c | 104 +++++++++++++++++----------------- src/statserv.c | 78 +++++++++++++------------- src/tcpdchk.c | 14 ++--- src/tcpip.c | 3 +- src/tpath.c | 4 +- src/unix.c | 3 +- src/xmalloc.c | 111 +++++++++++++++++++++++++++---------- src/zoom-c.c | 119 ++++++++++++++++++++++++--------------- test/tstlog.c | 6 +- zoom/zoomsh.c | 6 +- ztest/read-grs.c | 6 +- ztest/ztest.c | 6 +- 24 files changed, 572 insertions(+), 364 deletions(-) create mode 100644 include/yaz/ylog.h diff --git a/client/client.c b/client/client.c index 3a3cc7e..be42824 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.255 2004-11-02 11:37:21 heikki Exp $ + * $Id: client.c,v 1.256 2004-11-18 15:18:10 heikki Exp $ */ #include @@ -51,7 +51,7 @@ #include #include #include -#include +#include #if HAVE_READLINE_READLINE_H #include diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 083e5e4..bc1d356 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,7 +1,7 @@ -## $Id: Makefile.am,v 1.22 2003-07-29 15:08:28 adam Exp $ +## $Id: Makefile.am,v 1.23 2004-11-18 15:18:13 heikki Exp $ pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \ - diagbib1.h sortspec.h log.h logrpn.h marcdisp.h nmem.h odr.h oid.h \ + diagbib1.h sortspec.h ylog.h log.h logrpn.h marcdisp.h nmem.h odr.h oid.h \ options.h otherinfo.h pquery.h prt-ext.h readconf.h statserv.h \ tcpip.h unix.h tpath.h wrbuf.h xmalloc.h \ yaz-ccl.h yaz-iconv.h yaz-util.h yaz-version.h yconfig.h proto.h \ diff --git a/include/yaz/log.h b/include/yaz/log.h index 6c203ab..a7bd8bf 100644 --- a/include/yaz/log.h +++ b/include/yaz/log.h @@ -23,116 +23,48 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: log.h,v 1.19 2004-11-16 17:08:11 heikki Exp $ + * $Id: log.h,v 1.20 2004-11-18 15:18:13 heikki Exp $ */ /** * \file log.h - * \brief Header for logging utility + * \brief The old, deprecated header for log.c */ #ifndef LOG_H #define LOG_H +#include +#warning "use of log.h is deprecated, use logf.h instead" + #include #include #include YAZ_BEGIN_CDECL -#define LOG_FATAL 0x00000001 -#define LOG_DEBUG 0x00000002 -#define LOG_WARN 0x00000004 -#define LOG_LOG 0x00000008 -#define LOG_ERRNO 0x00000010 /* append strerror to message */ -#define LOG_FILE 0x00000020 -#define LOG_APP 0x00000040 /* Application level events (new-connection) */ -#define LOG_MALLOC 0x00000080 /* debugging mallocs */ -#define LOG_NOTIME 0x00000100 /* do not output date and time */ -#define LOG_APP2 0x00000200 /* Application-level events, such as api calls */ -#define LOG_APP3 0x00000400 /* For more application-level events */ -#define LOG_FLUSH 0x00000800 /* Flush log after every write (DEBUG does too) */ -#define LOG_LOGLVL 0x00001000 /* log when modules query log levels */ - /* this has to be a hard-coded bit, not to loop*/ - -#define LOG_ALL (0xffff&~LOG_MALLOC&~LOG_NOTIME) - -#define LOG_DEFAULT_LEVEL (LOG_FATAL | LOG_ERRNO | LOG_LOG | LOG_WARN) - -#define LOG_LAST_BIT LOG_LOGLVL /* the last bit used for regular log bits */ - /* the rest are for dynamic modules */ - -#define logf yaz_log - -/** - * yaz_log_init is a shorthand for initializing the log level and prefixes */ -YAZ_EXPORT void yaz_log_init(int level, const char *prefix, const char *name); - -/** yaz_log_init_file sets the file name used for yaz_log */ -YAZ_EXPORT void yaz_log_init_file(const char *fname); - -/** yaz_log_init_level sets the logging level. Use an OR of the bits above */ -YAZ_EXPORT void yaz_log_init_level(int level); - -/** yaz_log_init_prefix sets the log prefix */ -YAZ_EXPORT void yaz_log_init_prefix(const char *prefix); - -/** yaz_log_init_prefix2 sets an optional second prefix */ -YAZ_EXPORT void yaz_log_init_prefix2(const char *prefix); - -/** - * yaz_log_time_format sets the format of the timestamp. See man 3 strftime - * Calling with "old" sets to the old format "11:55:06-02/11" - * Calling with NULL or "" sets to the new format "20041102-115719" - * If not called at all, the old format is used, for backward compatibility - */ -YAZ_EXPORT void yaz_log_time_format(const char *fmt); - -/** - * yaz_log_init_max_size sets the max size for a log file. - * zero means no limit. Negative means built-in limit (1GB) +/* The old LOG_ bit names are here for compatibility only. They may + * conflict with bits defined in syslog.h, or other places. 'LOG' + * really is not such a good name. YLOG must be more unique */ -YAZ_EXPORT void yaz_log_init_max_size(int mx); - -/** - * yaz_log writes an entry in the log. Defaults to stderr if not initialized - * to a file with yaz_log_init_file. The level must match the level set via - * yaz_log_init_level, optionally defined via yaz_log_mask_str. */ -YAZ_EXPORT void yaz_log(int level, const char *fmt, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 2, 3))) -#endif - ; - -/** - * yaz_log_mask_str converts a comma-separated list of log levels to a bit - * mask. Starts from default level, and adds bits as specified, unless 'none' - * is specified, which clears the list. If a name matches the name of a - * LOG_BIT above, that one is set. Otherwise a new value is picked, and given - * to that name, to be found with yaz_log_module_level */ -YAZ_EXPORT int yaz_log_mask_str(const char *str); - -/** yaz_log_mask_str_x is like yaz_log_mask_str, but with a given start value*/ -YAZ_EXPORT int yaz_log_mask_str_x(const char *str, int level); +#define LOG_FATAL YLOG_FATAL +#define LOG_DEBUG YLOG_DEBUG +#define LOG_WARN YLOG_WARN +#define LOG_LOG YLOG_LOG /* Deprecated, use the modern dynamic log levels*/ +#define LOG_ERRNO YLOG_ERRNO + /* LOG_FILE discontinued */ +#define LOG_APP YLOG_APP /* Deprecated */ + /* LOG_MALLOC discontinued */ +#define LOG_NOTIME YLOG_NOTIME /* do not output date and time */ +#define LOG_APP2 YLOG_APP2 /* deprecated */ +#define LOG_APP3 YLOG_APP3 /* deprecated */ +#define LOG_FLUSH YLOG_FLUSH + /* LOG_LOGLVL so new that nobody should be using it. */ +#define LOG_ALL YLOG_ALL -/** - * yaz_log_module_level returns a log level mask corresponding to the module - * name. If that had been specified on the -v arguments (that is, passed to - * yaz_log_mask_str), then a non-zero mask is returned. If not, we get a - * zero. This can later be used in yaz_log for the level argument - */ -YAZ_EXPORT int yaz_log_module_level(const char *name); - -/** yaz_log_file returns the file handle for yaz_log. */ -YAZ_EXPORT FILE *yaz_log_file(void); +#define LOG_DEFAULT_LEVEL YLOG_DEFAULT_LEVEL -YAZ_EXPORT void log_event_start(void (*func)(int level, const char *msg, void *info), - void *info); -YAZ_EXPORT void log_event_end(void (*func)(int level, const char *msg, void *info), - void *info); -YAZ_EXPORT void yaz_log_reopen(void); -YAZ_END_CDECL #endif diff --git a/include/yaz/yaz-util.h b/include/yaz/yaz-util.h index b21fb88..60d665a 100644 --- a/include/yaz/yaz-util.h +++ b/include/yaz/yaz-util.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: yaz-util.h,v 1.10 2004-10-15 00:18:59 adam Exp $ + * $Id: yaz-util.h,v 1.11 2004-11-18 15:18:13 heikki Exp $ */ /** * \file yaz-util.h @@ -36,7 +36,7 @@ #include #include #include -#include +#include /* used to be log.h, but that is deprecated */ #include #include #include diff --git a/include/yaz/ylog.h b/include/yaz/ylog.h new file mode 100644 index 0000000..09f2247 --- /dev/null +++ b/include/yaz/ylog.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 1995-2004, Index Data. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The name of Index Data or the individual authors may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR + * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + * $Id: ylog.h,v 1.1 2004-11-18 15:18:13 heikki Exp $ + */ + +/** + * \file log.h + * \brief Header for logging utility + */ + +#ifndef YLOG_H +#define YLOG_H + +#include +#include +#include + +YAZ_BEGIN_CDECL + +#define YLOG_FATAL 0x00000001 +#define YLOG_DEBUG 0x00000002 +#define YLOG_WARN 0x00000004 +#define YLOG_LOG 0x00000008 +#define YLOG_ERRNO 0x00000010 /* append strerror to message */ +/*#define YLOG_FILE 0x00000020 */ +/*#define YLOG_APP 0x00000040 */ + /* Application level events (new-connection) */ +#define YLOG_MALLOC 0x00000080 /* debugging mallocs */ +#define YLOG_NOTIME 0x00000100 /* do not output date and time */ +/* #define YLOG_APP2 0x00000200 */ + /* Application-level events, such as api calls */ +/* #define YLOG_APP3 0x00000400 */ + /* For more application-level events */ +#define YLOG_FLUSH 0x00000800 /* Flush log after every write (DEBUG does too) */ +#define YLOG_LOGLVL 0x00001000 /* log when modules query log levels */ + /* this has to be a hard-coded bit, not to loop*/ + +#define YLOG_ALL (0xffff&~YLOG_MALLOC&~YLOG_NOTIME) + +#define YLOG_DEFAULT_LEVEL (YLOG_FATAL | YLOG_ERRNO | YLOG_LOG | YLOG_WARN) + +#define YLOG_LAST_BIT YLOG_LOGLVL /* the last bit used for regular log bits */ + /* the rest are for dynamic modules */ + +#define logf yaz_log + +/** + * yaz_log_init is a shorthand for initializing the log level and prefixes */ +YAZ_EXPORT void yaz_log_init(int level, const char *prefix, const char *name); + +/** yaz_log_init_file sets the file name used for yaz_log */ +YAZ_EXPORT void yaz_log_init_file(const char *fname); + +/** yaz_log_init_level sets the logging level. Use an OR of the bits above */ +YAZ_EXPORT void yaz_log_init_level(int level); + +/** yaz_log_init_prefix sets the log prefix */ +YAZ_EXPORT void yaz_log_init_prefix(const char *prefix); + +/** yaz_log_init_prefix2 sets an optional second prefix */ +YAZ_EXPORT void yaz_log_init_prefix2(const char *prefix); + +/** + * yaz_log_time_format sets the format of the timestamp. See man 3 strftime + * Calling with "old" sets to the old format "11:55:06-02/11" + * Calling with NULL or "" sets to the new format "20041102-115719" + * If not called at all, the old format is used, for backward compatibility + */ +YAZ_EXPORT void yaz_log_time_format(const char *fmt); + +/** + * yaz_log_init_max_size sets the max size for a log file. + * zero means no limit. Negative means built-in limit (1GB) + */ +YAZ_EXPORT void yaz_log_init_max_size(int mx); + +/** + * yaz_log writes an entry in the log. Defaults to stderr if not initialized + * to a file with yaz_log_init_file. The level must match the level set via + * yaz_log_init_level, optionally defined via yaz_log_mask_str. */ +YAZ_EXPORT void yaz_log(int level, const char *fmt, ...) +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + ; + +/** + * yaz_log_mask_str converts a comma-separated list of log levels to a bit + * mask. Starts from default level, and adds bits as specified, unless 'none' + * is specified, which clears the list. If a name matches the name of a + * YLOG_BIT above, that one is set. Otherwise a new value is picked, and given + * to that name, to be found with yaz_log_module_level */ +YAZ_EXPORT int yaz_log_mask_str(const char *str); + +/** yaz_log_mask_str_x is like yaz_log_mask_str, but with a given start value*/ +YAZ_EXPORT int yaz_log_mask_str_x(const char *str, int level); + + +/** + * yaz_log_module_level returns a log level mask corresponding to the module + * name. If that had been specified on the -v arguments (that is, passed to + * yaz_log_mask_str), then a non-zero mask is returned. If not, we get a + * zero. This can later be used in yaz_log for the level argument + */ +YAZ_EXPORT int yaz_log_module_level(const char *name); + +/** yaz_log_file returns the file handle for yaz_log. */ +YAZ_EXPORT FILE *yaz_log_file(void); + +YAZ_EXPORT void log_event_start(void (*func)(int level, const char *msg, void *info), + void *info); +YAZ_EXPORT void log_event_end(void (*func)(int level, const char *msg, void *info), + void *info); + +YAZ_EXPORT void yaz_log_reopen(void); +YAZ_END_CDECL + +#endif diff --git a/src/eventl.c b/src/eventl.c index 6fa5b98..6d22779 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: eventl.c,v 1.2 2004-10-15 00:19:00 adam Exp $ + * $Id: eventl.c,v 1.3 2004-11-18 15:18:13 heikki Exp $ */ /** @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include "eventl.h" @@ -41,10 +41,19 @@ #define YAZ_EV_SELECT select #endif +static int log_level=0; +static int log_level_initialized=0; + IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) { IOCHAN new_iochan; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("eventl"); + log_level_initialized=1; + } + if (!(new_iochan = (IOCHAN)xmalloc(sizeof(*new_iochan)))) return 0; new_iochan->destroyed = 0; @@ -81,7 +90,7 @@ int event_loop(IOCHAN *iochans) for (p = *iochans; p; p = p->next) { time_t w, ftime; - yaz_log(LOG_DEBUG, "fd=%d flags=%d force_event=%d", + yaz_log(log_level, "fd=%d flags=%d force_event=%d", p->fd, p->flags, p->force_event); if (p->force_event) to.tv_sec = 0; /* polling select */ @@ -104,9 +113,9 @@ int event_loop(IOCHAN *iochans) to.tv_sec = w; } } - yaz_log(LOG_DEBUG, "select start %ld", (long) to.tv_sec); + yaz_log(log_level, "select start %ld", (long) to.tv_sec); res = YAZ_EV_SELECT(max + 1, &in, &out, &except, &to); - yaz_log(LOG_DEBUG, "select end"); + yaz_log(log_level, "select end"); if (res < 0) { if (yaz_errno() == EINTR) @@ -127,7 +136,7 @@ int event_loop(IOCHAN *iochans) cs_close(conn); destroy_association(assoc); iochan_destroy(*iochans); - yaz_log(LOG_DEBUG, "error select, destroying iochan %p", + yaz_log(log_level, "error select, destroying iochan %p", *iochans); } } diff --git a/src/log.c b/src/log.c index ecdb458..f6690e5 100644 --- a/src/log.c +++ b/src/log.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: log.c,v 1.15 2004-11-17 13:03:07 heikki Exp $ + * $Id: log.c,v 1.16 2004-11-18 15:18:13 heikki Exp $ */ /** @@ -34,7 +34,7 @@ #include #include #include -#include +#include static NMEM_MUTEX log_mutex = 0; static int mutex_init_flag = 0; /* not yet initialized */ @@ -54,7 +54,7 @@ char *strerror(int n) -static int l_level = LOG_DEFAULT_LEVEL; +static int l_level = YLOG_DEFAULT_LEVEL; static FILE *l_file = NULL; static char l_prefix[512] = ""; static char l_prefix2[512] = ""; @@ -76,24 +76,24 @@ static struct { char *name; } mask_names[MAX_MASK_NAMES] = { - { LOG_FATAL, "fatal"}, - { LOG_DEBUG, "debug"}, - { LOG_WARN, "warn" }, - { LOG_LOG, "log" }, - { LOG_ERRNO, ""}, - { LOG_MALLOC, "malloc"}, - { LOG_APP, "app" }, - { LOG_NOTIME, "" }, - { LOG_APP2, "app2" }, - { LOG_APP3, "app3" }, - { LOG_ALL, "all" }, - { LOG_FLUSH, "flush" }, - { LOG_LOGLVL, "loglevel" }, + { YLOG_FATAL, "fatal"}, + { YLOG_DEBUG, "debug"}, + { YLOG_WARN, "warn" }, + { YLOG_LOG, "log" }, + { YLOG_ERRNO, ""}, + { YLOG_MALLOC, "malloc"}, + /* { YLOG_APP, "app" }, */ + { YLOG_NOTIME, "" }, + /* { YLOG_APP2, "app2" }, */ + /* { YLOG_APP3, "app3" }, */ + { YLOG_ALL, "all" }, + { YLOG_FLUSH, "flush" }, + { YLOG_LOGLVL, "loglevel" }, { 0, "none" }, { 0, NULL } /* the rest will be filled in if the user defines dynamic modules*/ }; -static unsigned int next_log_bit = LOG_LAST_BIT<<1; /* first dynamic bit */ +static unsigned int next_log_bit = YLOG_LAST_BIT<<1; /* first dynamic bit */ static void init_mutex() { @@ -140,7 +140,7 @@ void yaz_log_reopen(void) { fclose (l_file); } - if (l_level & LOG_FLUSH) + if (l_level & YLOG_FLUSH) setvbuf(new_file, 0, _IONBF, 0); l_file = new_file; } @@ -167,25 +167,25 @@ static void rotate_log() void yaz_log_init_level (int level) { - if ( (l_level & LOG_FLUSH) != (level & LOG_FLUSH) ) + if ( (l_level & YLOG_FLUSH) != (level & YLOG_FLUSH) ) { l_level = level; yaz_log_reopen(); /* make sure we set buffering right */ } else l_level = level; - if (l_level & LOG_LOGLVL) + if (l_level & YLOG_LOGLVL) { /* dump the log level bits */ char *bittype="Static "; int i; - yaz_log(LOG_LOGLVL,"Setting log level to %d = 0x%08x",l_level,l_level); + yaz_log(YLOG_LOGLVL,"Setting log level to %d = 0x%08x",l_level,l_level); for (i = 0; mask_names[i].name; i++) if (mask_names[i].mask && *mask_names[i].name) if (strcmp(mask_names[i].name,"all")!=0) { - yaz_log(LOG_LOGLVL,"%s log bit %08x '%s' is %s", + yaz_log(YLOG_LOGLVL,"%s log bit %08x '%s' is %s", bittype, mask_names[i].mask, mask_names[i].name, (level & mask_names[i].mask)? "ON": "off"); - if (mask_names[i].mask>LOG_LAST_BIT) + if (mask_names[i].mask>YLOG_LAST_BIT) bittype="Dynamic"; } } @@ -274,7 +274,7 @@ void yaz_log(int level, const char *fmt, ...) if ( mask_names[i].mask & level) { if (*mask_names[i].name && mask_names[i].mask && - mask_names[i].mask != LOG_ALL) + mask_names[i].mask != YLOG_ALL) { sprintf(flags + strlen(flags), "[%s]", mask_names[i].name); level &= ~mask_names[i].mask; @@ -292,7 +292,7 @@ void yaz_log(int level, const char *fmt, ...) #endif #endif /* WIN32 */ - if (o_level & LOG_ERRNO) + if (o_level & YLOG_ERRNO) { strcat(buf, " ["); yaz_strerror(buf+strlen(buf), 2048); @@ -303,14 +303,14 @@ void yaz_log(int level, const char *fmt, ...) (*start_hook_func)(o_level, buf, start_hook_info); ti = time(0); tim = localtime(&ti); - if (l_level & LOG_NOTIME) + if (l_level & YLOG_NOTIME) tbuf[0] = '\0'; else strftime(tbuf, TIMEFORMAT_LEN-1, l_actual_format, tim); tbuf[TIMEFORMAT_LEN-1] = '\0'; fprintf(l_file, "%s %s%s %s%s\n", tbuf, l_prefix, flags, l_prefix2, buf); - if (l_level & (LOG_FLUSH|LOG_DEBUG) ) + if (l_level & (YLOG_FLUSH|YLOG_DEBUG) ) fflush(l_file); if (end_hook_func) (*end_hook_func)(o_level, buf, end_hook_info); @@ -358,7 +358,7 @@ static int define_module_bit(const char *name) ; if ( (i>=MAX_MASK_NAMES) || (next_log_bit >= 1<<31 )) { - yaz_log(LOG_WARN,"No more log bits left, not logging '%s'", name); + yaz_log(YLOG_WARN,"No more log bits left, not logging '%s'", name); return 0; } mask_names[i].mask = next_log_bit; @@ -377,19 +377,19 @@ int yaz_log_module_level(const char *name) for (i = 0; mask_names[i].name; i++) if (0==strcmp(n,mask_names[i].name)) { - yaz_log(LOG_LOGLVL,"returning log bit 0x%x for '%s' %s", + yaz_log(YLOG_LOGLVL,"returning log bit 0x%x for '%s' %s", mask_names[i].mask, n, strcmp(n,name)?name:"" ); return mask_names[i].mask; } - yaz_log(LOG_LOGLVL,"returning NO log bit for '%s' %s", n, + yaz_log(YLOG_LOGLVL,"returning NO log bit for '%s' %s", n, strcmp(n,name)?name:"" ); return 0; } int yaz_log_mask_str (const char *str) { - return yaz_log_mask_str_x (str, LOG_DEFAULT_LEVEL); + return yaz_log_mask_str_x (str, YLOG_DEFAULT_LEVEL); } int yaz_log_mask_str_x (const char *str, int level) diff --git a/src/logrpn.c b/src/logrpn.c index a46fd84..5d211e1 100644 --- a/src/logrpn.c +++ b/src/logrpn.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2004, Index Data * All rights reserved. * - * $Id: logrpn.c,v 1.6 2004-11-17 00:18:54 adam Exp $ + * $Id: logrpn.c,v 1.7 2004-11-18 15:18:13 heikki Exp $ */ /** @@ -13,9 +13,10 @@ #include #include -#include +#include #include + static const char *relToStr(int v) { const char *str = 0; @@ -437,7 +438,6 @@ static void wrbuf_apt(WRBUF b, Z_AttributesPlusTerm *zapt) static void wrbuf_structure (WRBUF b, Z_RPNStructure *zs, enum oid_value ast) { - int i; if (zs->which == Z_RPNStructure_complex) { Z_Operator *op = zs->u.complex->roperator; @@ -532,7 +532,7 @@ static void wrbuf_rpn_query(WRBUF b, Z_RPNQuery *rpn) void log_rpn_query (Z_RPNQuery *rpn) { - log_rpn_query_level(LOG_LOG, rpn); + log_rpn_query_level(YLOG_LOG, rpn); } void log_scan_term_level (int loglevel, @@ -553,7 +553,7 @@ void log_scan_term_level (int loglevel, void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast) { - log_scan_term_level (LOG_LOG, zapt, ast); + log_scan_term_level (YLOG_LOG, zapt, ast); } void wrbuf_scan_term(WRBUF b, Z_AttributesPlusTerm *zapt, oid_value ast) @@ -585,7 +585,7 @@ void yaz_log_zquery_level (int loglevel, Z_Query *q) void yaz_log_zquery (Z_Query *q) { - yaz_log_zquery_level(LOG_LOG,q); + yaz_log_zquery_level(YLOG_LOG,q); } void wrbuf_put_zquery(WRBUF b, Z_Query *q) diff --git a/src/nmem.c b/src/nmem.c index 73d65e7..a16603d 100644 --- a/src/nmem.c +++ b/src/nmem.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data. * See the file LICENSE for details. * - * $Id: nmem.c,v 1.5 2004-11-03 22:33:17 adam Exp $ + * $Id: nmem.c,v 1.6 2004-11-18 15:18:13 heikki Exp $ */ /** @@ -11,6 +11,9 @@ * * This is a simple and fairly wasteful little module for nibble memory * allocation. Evemtually we'll put in something better. + * + * FIXME - it also has some semaphore stuff, and stuff to handle errno. + * These should be moved to some other place! */ #if HAVE_CONFIG_H #include @@ -21,7 +24,7 @@ #include #include #include -#include +#include #include #ifdef WIN32 @@ -38,6 +41,9 @@ #define NMEM_CHUNK (4*1024) +static int log_level=0; +static int log_level_initialized=0; + #ifdef WIN32 static CRITICAL_SECTION critical_section; #define NMEM_ENTER EnterCriticalSection(&critical_section) @@ -69,6 +75,12 @@ struct nmem_mutex { YAZ_EXPORT void nmem_mutex_create(NMEM_MUTEX *p) { + if (!log_level_initialized) + { + log_level=yaz_log_module_level("nmem"); + log_level_initialized=1; + } + NMEM_ENTER; if (!*p) { @@ -143,15 +155,15 @@ static void free_block(nmem_block *p) memset(p->buf, 'Y', p->size); p->next = freelist; freelist = p; -#if NMEM_DEBUG - yaz_log (LOG_DEBUG, "nmem free_block p=%p", p); -#endif + if (log_level) + yaz_log (log_level, "nmem free_block p=%p", p); } #if NMEM_DEBUG void nmem_print_list (void) { - nmem_print_list_l(LOG_DEBUG); + if(log_level) + nmem_print_list_l(log_level); } void nmem_print_list_l (int level) @@ -173,17 +185,16 @@ static nmem_block *get_block(int size) { nmem_block *r, *l; -#if NMEM_DEBUG - yaz_log (LOG_DEBUG, "nmem get_block size=%d", size); -#endif + if (log_level) + yaz_log (log_level, "nmem get_block size=%d", size); + for (r = freelist, l = 0; r; l = r, r = r->next) if (r->size >= size) break; if (r) { -#if NMEM_DEBUG - yaz_log (LOG_DEBUG, "nmem get_block found free block p=%p", r); -#endif + if (log_level) + yaz_log (log_level, "nmem get_block found free block p=%p", r); if (l) l->next = r->next; else @@ -195,9 +206,9 @@ static nmem_block *get_block(int size) if (get < size) get = size; -#if NMEM_DEBUG - yaz_log (LOG_DEBUG, "nmem get_block alloc new block size=%d", get); -#endif + if(log_level) + yaz_log (log_level, "nmem get_block alloc new block size=%d", get); + r = (nmem_block *)xmalloc(sizeof(*r)); r->buf = (char *)xmalloc(r->size = get); } @@ -208,10 +219,8 @@ static nmem_block *get_block(int size) void nmem_reset(NMEM n) { nmem_block *t; - -#if NMEM_DEBUG - yaz_log (LOG_DEBUG, "nmem_reset p=%p", n); -#endif + + yaz_log (log_level, "nmem_reset p=%p", n); if (!n) return; NMEM_ENTER; @@ -235,12 +244,13 @@ void *nmem_malloc(NMEM n, int size) char *r; #if NMEM_DEBUG - yaz_log (LOG_DEBUG, "%s:%d: nmem_malloc p=%p size=%d", file, line, - n, size); + if (log_level) + yaz_log (log_level, "%s:%d: nmem_malloc p=%p size=%d", + file, line, n, size); #endif if (!n) { - yaz_log (LOG_FATAL, "calling nmem_malloc with an null pointer"); + yaz_log (YLOG_FATAL, "calling nmem_malloc with an null pointer"); abort (); } #ifdef WIN32 @@ -277,6 +287,11 @@ NMEM nmem_create(void) #if NMEM_DEBUG struct nmem_debug_info *debug_p; #endif + if (!log_level_initialized) + { + log_level=yaz_log_module_level("nmem"); + log_level_initialized=1; + } NMEM_ENTER; nmem_active_no++; @@ -288,7 +303,7 @@ NMEM nmem_create(void) NMEM_LEAVE; #if NMEM_DEBUG - yaz_log (LOG_DEBUG, "%s:%d: nmem_create %d p=%p", file, line, + yaz_log (YLOG_DEBUG, "%s:%d: nmem_create %d p=%p", file, line, nmem_active_no, r); #endif r->blocks = 0; @@ -299,7 +314,7 @@ NMEM nmem_create(void) for (debug_p = nmem_debug_list; debug_p; debug_p = debug_p->next) if (debug_p->p == r) { - yaz_log (LOG_FATAL, "multi used block in nmem"); + yaz_log (YLOG_FATAL, "multi used block in nmem"); abort (); } debug_p = xmalloc (sizeof(*debug_p)); @@ -329,7 +344,7 @@ void nmem_destroy(NMEM n) return; #if NMEM_DEBUG - yaz_log (LOG_DEBUG, "%s:%d: nmem_destroy %d p=%p", file, line, + yaz_log (log_level, "%s:%d: nmem_destroy %d p=%p", file, line, nmem_active_no-1, n); NMEM_ENTER; for (debug_p = &nmem_debug_list; *debug_p; debug_p = &(*debug_p)->next) @@ -345,7 +360,7 @@ void nmem_destroy(NMEM n) nmem_print_list(); if (!ok) { - yaz_log (LOG_WARN, "%s:%d destroying unallocated nmem block p=%p", + yaz_log (YLOG_WARN, "%s:%d destroying unallocated nmem block p=%p", file, line, n); return; } @@ -383,12 +398,18 @@ void nmem_critical_leave (void) void nmem_init (void) { + if (!log_level_initialized) + { + log_level=yaz_log_module_level("nmem"); + log_level_initialized=1; + } + if (++nmem_init_flag == 1) { #ifdef WIN32 InitializeCriticalSection(&critical_section); #elif YAZ_GNU_THREADS - yaz_log (LOG_LOG, "pth_init"); + yaz_log (log_level, "pth_init"); /* ??? */ pth_init (); #endif nmem_active_no = 0; @@ -452,6 +473,12 @@ void yaz_set_errno(int v) void yaz_strerror(char *buf, int max) { char *cp; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("nmem"); + log_level_initialized=1; + } + #ifdef WIN32 DWORD err = GetLastError(); if (err) diff --git a/src/odr.c b/src/odr.c index 1e31f29..964193e 100644 --- a/src/odr.c +++ b/src/odr.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: odr.c,v 1.8 2004-10-15 00:19:00 adam Exp $ + * $Id: odr.c,v 1.9 2004-11-18 15:18:13 heikki Exp $ * */ @@ -20,8 +20,12 @@ #include #include +#include #include "odr-priv.h" +static int log_level=0; +static int log_level_initialized=0; + Odr_null *ODR_NULLVAL = (Odr_null *) "NULL"; /* the presence of a null value */ Odr_null *odr_nullval (void) @@ -170,11 +174,15 @@ int odr_set_charset(ODR o, const char *to, const char *from) return 0; } -#include ODR odr_createmem(int direction) { ODR o; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("odr"); + log_level_initialized=1; + } if (!(o = (ODR)xmalloc(sizeof(*o)))) return 0; @@ -189,12 +197,18 @@ ODR odr_createmem(int direction) o->op->iconv_handle = 0; odr_setprint(o, stderr); odr_reset(o); - yaz_log (LOG_DEBUG, "odr_createmem dir=%d o=%p", direction, o); + yaz_log (log_level, "odr_createmem dir=%d o=%p", direction, o); return o; } void odr_reset(ODR o) { + if (!log_level_initialized) + { + log_level=yaz_log_module_level("odr"); + log_level_initialized=1; + } + odr_seterror(o, ONONE, 0); o->bp = o->buf; odr_seek(o, ODR_S_SET, 0); @@ -208,7 +222,7 @@ void odr_reset(ODR o) o->lenlen = 1; if (o->op->iconv_handle != 0) yaz_iconv(o->op->iconv_handle, 0, 0, 0, 0); - yaz_log (LOG_DEBUG, "odr_reset o=%p", o); + yaz_log (log_level, "odr_reset o=%p", o); } void odr_destroy(ODR o) @@ -222,7 +236,7 @@ void odr_destroy(ODR o) yaz_iconv_close (o->op->iconv_handle); xfree(o->op); xfree(o); - yaz_log (LOG_DEBUG, "odr_destroy o=%p", o); + yaz_log (log_level, "odr_destroy o=%p", o); } void odr_setbuf(ODR o, char *buf, int len, int can_grow) diff --git a/src/odr_oct.c b/src/odr_oct.c index 3d10943..1ea7353 100644 --- a/src/odr_oct.c +++ b/src/odr_oct.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: odr_oct.c,v 1.6 2004-10-15 00:19:00 adam Exp $ + * $Id: odr_oct.c,v 1.7 2004-11-18 15:18:13 heikki Exp $ */ /** * \file odr_oct.c @@ -12,7 +12,6 @@ #include #endif -#include #include "odr-priv.h" /* diff --git a/src/readconf.c b/src/readconf.c index 3e99be0..b8ca118 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -2,7 +2,7 @@ * Copyright (C) 1994-2004, Index Data * All rights reserved. * - * $Id: readconf.c,v 1.2 2004-10-15 00:19:00 adam Exp $ + * $Id: readconf.c,v 1.3 2004-11-18 15:18:13 heikki Exp $ */ /** @@ -17,7 +17,7 @@ #include #include -#include +#include #include #define l_isspace(c) ((c) == '\t' || (c) == ' ' || (c) == '\n' || (c) == '\r') @@ -69,7 +69,7 @@ int readconf(char *name, void *rprivate, if (!(f = fopen(name, "r"))) { - yaz_log(LOG_WARN|LOG_ERRNO, "readconf: %s", name); + yaz_log(YLOG_WARN|YLOG_ERRNO, "readconf: %s", name); return -1; } for (;;) diff --git a/src/seshigh.c b/src/seshigh.c index 4f423b5..2bd951f 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.35 2004-11-16 22:14:44 adam Exp $ + * $Id: seshigh.c,v 1.36 2004-11-18 15:18:13 heikki Exp $ */ /** * \file seshigh.c @@ -50,7 +50,7 @@ #include "session.h" #include #include -#include +#include #include #include #include @@ -153,7 +153,7 @@ association *create_association(IOCHAN channel, COMSTACK link) { if (!(apduf = fopen(filename, "w"))) { - yaz_log(LOG_WARN|LOG_ERRNO, "can't open apdu dump %s", filename); + yaz_log(YLOG_WARN|YLOG_ERRNO, "can't open apdu dump %s", filename); return 0; } setvbuf(apduf, 0, _IONBF, 0); @@ -165,7 +165,7 @@ association *create_association(IOCHAN channel, COMSTACK link) sprintf(filename + strlen(filename), ".%d", getpid()); if (!(f = fopen(filename, "w"))) { - yaz_log(LOG_WARN|LOG_ERRNO, "%s", filename); + yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", filename); return 0; } setvbuf(f, 0, _IONBF, 0); @@ -272,7 +272,7 @@ void ir_session(IOCHAN h, int event) { if (assoc->state != ASSOC_UP) { - yaz_log(LOG_DEBUG, "Final timeout - closing connection."); + yaz_log(YLOG_DEBUG, "Final timeout - closing connection."); /* do we need to lod this at all */ cs_close(conn); destroy_association(assoc); @@ -290,7 +290,7 @@ void ir_session(IOCHAN h, int event) yaz_log (log_session, "ir_session (accept)"); if (!cs_accept (conn)) { - yaz_log (LOG_WARN, "accept failed"); + yaz_log (YLOG_WARN, "accept failed"); destroy_association(assoc); iochan_destroy(h); } @@ -315,7 +315,7 @@ void ir_session(IOCHAN h, int event) { if ((assoc->cs_put_mask & EVENT_INPUT) == 0 && (event & assoc->cs_get_mask)) { - yaz_log(LOG_DEBUG, "ir_session (input)"); + yaz_log(YLOG_DEBUG, "ir_session (input)"); /* We aren't speaking to this fellow */ if (assoc->state == ASSOC_DEAD) { @@ -346,7 +346,7 @@ void ir_session(IOCHAN h, int event) iochan_setevent(h, EVENT_INPUT); /* we got a complete PDU. Let's decode it */ - yaz_log(LOG_DEBUG, "Got PDU, %d bytes: lead=%02X %02X %02X", res, + yaz_log(YLOG_DEBUG, "Got PDU, %d bytes: lead=%02X %02X %02X", res, assoc->input_buffer[0] & 0xff, assoc->input_buffer[1] & 0xff, assoc->input_buffer[2] & 0xff); @@ -355,14 +355,14 @@ void ir_session(IOCHAN h, int event) odr_setbuf(assoc->decode, assoc->input_buffer, res, 0); if (!z_GDU(assoc->decode, &req->gdu_request, 0, 0)) { - yaz_log(LOG_WARN, "ODR error on incoming PDU: %s [element %s] " + yaz_log(YLOG_WARN, "ODR error on incoming PDU: %s [element %s] " "[near byte %d] ", odr_errmsg(odr_geterror(assoc->decode)), odr_getelement(assoc->decode), odr_offset(assoc->decode)); if (assoc->decode->error != OHTTP) { - yaz_log(LOG_WARN, "PDU dump:"); + yaz_log(YLOG_WARN, "PDU dump:"); odr_dumpBER(yaz_log_file(), assoc->input_buffer, res); request_release(req); do_close(assoc, Z_Close_protocolError,"Malformed package"); @@ -379,7 +379,7 @@ void ir_session(IOCHAN h, int event) if (assoc->print) { if (!z_GDU(assoc->print, &req->gdu_request, 0, 0)) - yaz_log(LOG_WARN, "ODR print error: %s", + yaz_log(YLOG_WARN, "ODR print error: %s", odr_errmsg(odr_geterror(assoc->print))); odr_reset(assoc->print); } @@ -399,7 +399,7 @@ void ir_session(IOCHAN h, int event) request *req = request_head(&assoc->outgoing); assoc->cs_put_mask = 0; - yaz_log(LOG_DEBUG, "ir_session (output)"); + yaz_log(YLOG_DEBUG, "ir_session (output)"); req->state = REQUEST_PENDING; switch (res = cs_put(conn, req->response, req->len_response)) { @@ -410,9 +410,9 @@ void ir_session(IOCHAN h, int event) iochan_destroy(h); break; case 0: /* all sent - release the request structure */ - yaz_log(LOG_DEBUG, "Wrote PDU, %d bytes", req->len_response); + yaz_log(YLOG_DEBUG, "Wrote PDU, %d bytes", req->len_response); #if 0 - yaz_log(LOG_DEBUG, "HTTP out:\n%.*s", req->len_response, + yaz_log(YLOG_DEBUG, "HTTP out:\n%.*s", req->len_response, req->response); #endif nmem_destroy(req->request_mem); @@ -440,7 +440,7 @@ void ir_session(IOCHAN h, int event) } if (event & EVENT_EXCEPT) { - yaz_log(LOG_WARN, "ir_session (exception)"); + yaz_log(YLOG_WARN, "ir_session (exception)"); cs_close(conn); destroy_association(assoc); iochan_destroy(h); @@ -497,7 +497,7 @@ static int srw_bend_init(association *assoc) assoc->backend = 0; if (!(binitres = (*cb->bend_init)(assoc->init))) { - yaz_log(LOG_WARN, "Bad response from backend."); + yaz_log(YLOG_WARN, "Bad response from backend."); return 0; } assoc->backend = binitres->handle; @@ -622,10 +622,10 @@ static void srw_bend_search(association *assoc, request *req, *http_code = 200; yaz_log(log_requestdetail, "Got SRW SearchRetrieveRequest"); - yaz_log(LOG_DEBUG, "srw_bend_search"); + yaz_log(YLOG_DEBUG, "srw_bend_search"); if (!assoc->init) { - yaz_log(LOG_DEBUG, "srw_bend_init"); + yaz_log(YLOG_DEBUG, "srw_bend_init"); if (!srw_bend_init(assoc)) { srw_error = 3; /* assume Authentication error */ @@ -781,7 +781,7 @@ static void srw_bend_search(association *assoc, request *req, srw_res->records[j].recordPacking = packing; srw_res->records[j].recordData_buf = 0; - yaz_log(LOG_DEBUG, "srw_bend_fetch %d", i+start); + yaz_log(YLOG_DEBUG, "srw_bend_fetch %d", i+start); errcode = srw_bend_fetch(assoc, i+start, srw_req, srw_res->records + j); if (errcode) @@ -832,7 +832,7 @@ static void srw_bend_explain(association *assoc, request *req, *http_code = 404; if (!assoc->init) { - yaz_log(LOG_DEBUG, "srw_bend_init"); + yaz_log(YLOG_DEBUG, "srw_bend_init"); if (!srw_bend_init(assoc)) { return; @@ -891,13 +891,13 @@ static void process_http_request(association *assoc, request *req) if (r == 2) { r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset); - yaz_log(LOG_DEBUG, "yaz_srw_decode returned %d", r); + yaz_log(YLOG_DEBUG, "yaz_srw_decode returned %d", r); } if (r == 2) /* not taken */ { r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset, &diagnostic, &num_diagnostic); - yaz_log(LOG_DEBUG, "yaz_sru_decode returned %d", r); + yaz_log(YLOG_DEBUG, "yaz_sru_decode returned %d", r); } if (r == 0) /* decode SRW/SRU OK .. */ { @@ -1136,12 +1136,12 @@ static int process_z_request(association *assoc, request *req, char **msg) } if (res) { - yaz_log(LOG_DEBUG, " result immediately available"); + yaz_log(YLOG_DEBUG, " result immediately available"); retval = process_z_response(assoc, req, res); } else if (fd < 0) { - yaz_log(LOG_DEBUG, " result unavailble"); + yaz_log(YLOG_DEBUG, " result unavailble"); retval = 0; } else /* no result yet - one will be provided later */ @@ -1150,7 +1150,7 @@ static int process_z_request(association *assoc, request *req, char **msg) /* Set up an I/O handler for the fd supplied by the backend */ - yaz_log(LOG_DEBUG, " establishing handler for result"); + yaz_log(YLOG_DEBUG, " establishing handler for result"); req->state = REQUEST_PENDING; if (!(chan = iochan_create(fd, backend_response, EVENT_INPUT))) abort(); @@ -1170,7 +1170,7 @@ void backend_response(IOCHAN i, int event) Z_APDU *res; int fd; - yaz_log(LOG_DEBUG, "backend_response"); + yaz_log(YLOG_DEBUG, "backend_response"); assert(assoc && req && req->state != REQUEST_IDLE); /* determine what it is we're waiting for */ switch (req->apdu_request->which) @@ -1184,19 +1184,19 @@ void backend_response(IOCHAN i, int event) res = response_scanRequest(assoc, req, 0, &fd); break; #endif default: - yaz_log(LOG_FATAL, "Serious programmer's lapse or bug"); + yaz_log(YLOG_FATAL, "Serious programmer's lapse or bug"); abort(); } if ((res && process_z_response(assoc, req, res) < 0) || fd < 0) { - yaz_log(LOG_WARN, "Fatal error when talking to backend"); + yaz_log(YLOG_WARN, "Fatal error when talking to backend"); do_close(assoc, Z_Close_systemProblem, 0); iochan_destroy(i); return; } else if (!res) /* no result yet - try again later */ { - yaz_log(LOG_DEBUG, " no result yet"); + yaz_log(YLOG_DEBUG, " no result yet"); iochan_setfd(i, fd); /* in case fd has changed */ } } @@ -1211,13 +1211,13 @@ static int process_gdu_response(association *assoc, request *req, Z_GDU *res) if (assoc->print) { if (!z_GDU(assoc->print, &res, 0, 0)) - yaz_log(LOG_WARN, "ODR print error: %s", + yaz_log(YLOG_WARN, "ODR print error: %s", odr_errmsg(odr_geterror(assoc->print))); odr_reset(assoc->print); } if (!z_GDU(assoc->encode, &res, 0, 0)) { - yaz_log(LOG_WARN, "ODR error when encoding PDU: %s [element %s]", + yaz_log(YLOG_WARN, "ODR error when encoding PDU: %s [element %s]", odr_errmsg(odr_geterror(assoc->decode)), odr_getelement(assoc->decode)); request_release(req); @@ -1236,7 +1236,7 @@ static int process_gdu_response(association *assoc, request *req, Z_GDU *res) #if 1 if (request_head(&assoc->incoming)) { - yaz_log (LOG_DEBUG, "more work to be done"); + yaz_log (YLOG_DEBUG, "more work to be done"); iochan_setevent(assoc->client_chan, EVENT_WORK); } #endif @@ -1298,25 +1298,25 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->backend = 0; if (!(binitres = (*cb->bend_init)(assoc->init))) { - yaz_log(LOG_WARN, "Bad response from backend."); + yaz_log(YLOG_WARN, "Bad response from backend."); return 0; } assoc->backend = binitres->handle; if ((assoc->init->bend_sort)) - yaz_log (LOG_DEBUG, "Sort handler installed"); + yaz_log (YLOG_DEBUG, "Sort handler installed"); if ((assoc->init->bend_search)) - yaz_log (LOG_DEBUG, "Search handler installed"); + yaz_log (YLOG_DEBUG, "Search handler installed"); if ((assoc->init->bend_present)) - yaz_log (LOG_DEBUG, "Present handler installed"); + yaz_log (YLOG_DEBUG, "Present handler installed"); if ((assoc->init->bend_esrequest)) - yaz_log (LOG_DEBUG, "ESRequest handler installed"); + yaz_log (YLOG_DEBUG, "ESRequest handler installed"); if ((assoc->init->bend_delete)) - yaz_log (LOG_DEBUG, "Delete handler installed"); + yaz_log (YLOG_DEBUG, "Delete handler installed"); if ((assoc->init->bend_scan)) - yaz_log (LOG_DEBUG, "Scan handler installed"); + yaz_log (YLOG_DEBUG, "Scan handler installed"); if ((assoc->init->bend_segment)) - yaz_log (LOG_DEBUG, "Segment handler installed"); + yaz_log (YLOG_DEBUG, "Segment handler installed"); resp->referenceId = req->referenceId; *options = '\0'; @@ -1420,7 +1420,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.35 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.36 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, @@ -1430,7 +1430,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) if (binitres->errcode) { - yaz_log(LOG_DEBUG, "Connection rejected by backend."); + yaz_log(YLOG_DEBUG, "Connection rejected by backend."); *resp->result = 0; assoc->state = ASSOC_DEAD; resp->userInformationField = init_diagnostics(assoc->encode, @@ -1553,7 +1553,7 @@ static Z_NamePlusRecord *surrogatediagrec(association *assoc, char *dbname, odr_malloc (assoc->encode, sizeof(*rec)); Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (assoc->encode, sizeof(*drec)); - yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo); + yaz_log(YLOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo); rec->databaseName = dbname; rec->which = Z_NamePlusRecord_surrogateDiagnostic; rec->u.surrogateDiagnostic = drec; @@ -1575,7 +1575,7 @@ static Z_DiagRecs *diagrecs(association *assoc, int error, char *addinfo) Z_DefaultDiagFormat *rec = (Z_DefaultDiagFormat *) odr_malloc (assoc->encode, sizeof(*rec)); - yaz_log(LOG_DEBUG, "DiagRecs: %d -- %s", error, addinfo ? addinfo : ""); + yaz_log(YLOG_DEBUG, "DiagRecs: %d -- %s", error, addinfo ? addinfo : ""); recs->num_diagRecs = 1; recs->diagRecs = recp; @@ -1678,7 +1678,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, this_length = freq.len; else this_length = odr_total(a->encode) - total_length - dumped_records; - yaz_log(LOG_DEBUG, " fetched record, len=%d, total=%d dumped=%d", + yaz_log(YLOG_DEBUG, " fetched record, len=%d, total=%d dumped=%d", this_length, total_length, dumped_records); if (a->preferredMessageSize > 0 && this_length + total_length > a->preferredMessageSize) @@ -1696,7 +1696,7 @@ static Z_Records *pack_records(association *a, char *setname, int start, yaz_log(log_requestdetail, " Record > prefmsgsz"); if (toget > 1) { - yaz_log(LOG_DEBUG, " Dropped it"); + yaz_log(YLOG_DEBUG, " Dropped it"); reclist->records[reclist->num_records] = surrogatediagrec(a, freq.basename, 16, 0); reclist->num_records++; @@ -1790,7 +1790,7 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb, else { /* FIXME - make a diagnostic for it */ - yaz_log(LOG_WARN,"Search not supported ?!?!"); + yaz_log(YLOG_WARN,"Search not supported ?!?!"); } return response_searchRequest(assoc, reqb, bsrr, fd); } @@ -1825,7 +1825,7 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, *fd = -1; if (!bsrt && !bend_searchresponse(assoc->backend, bsrt)) { - yaz_log(LOG_FATAL, "Bad result from backend"); + yaz_log(YLOG_FATAL, "Bad result from backend"); return 0; } else if (bsrt->errcode) @@ -2175,7 +2175,7 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) odr_malloc(assoc->encode, o->len = o->size = strlen(bsrr->entries[i].term)); memcpy(o->buf, bsrr->entries[i].term, o->len); - yaz_log(LOG_DEBUG, " term #%d: '%s' (%d)", i, + yaz_log(YLOG_DEBUG, " term #%d: '%s' (%d)", i, bsrr->entries[i].term, bsrr->entries[i].occurrences); } else @@ -2458,7 +2458,7 @@ int bend_backend_respond (bend_association a, bend_request req) int r; r = process_z_request (a, req, &msg); if (r < 0) - yaz_log (LOG_WARN, "%s", msg); + yaz_log (YLOG_WARN, "%s", msg); return r; } @@ -2536,7 +2536,7 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) esrequest.errstring); /* Backend indicates error, request will not be processed */ - yaz_log(LOG_DEBUG,"Request could not be processed...failure !"); + yaz_log(YLOG_DEBUG,"Request could not be processed...failure !"); *resp->operationStatus = Z_ExtendedServicesResponse_failure; resp->num_diagnostics = diagRecs->num_diagRecs; resp->diagnostics = diagRecs->diagRecs; @@ -2554,7 +2554,7 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) resp->taskPackage = z_ext_record (assoc->encode, VAL_EXTENDED, (const char *) esrequest.taskPackage, -1); - yaz_log(LOG_DEBUG,"Send the result apdu"); + yaz_log(YLOG_DEBUG,"Send the result apdu"); return apdu; } diff --git a/src/statserv.c b/src/statserv.c index a32ce35..9d12c7a 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -5,7 +5,7 @@ * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.11 2004-11-16 17:08:11 heikki Exp $ + * $Id: statserv.c,v 1.12 2004-11-18 15:18:13 heikki Exp $ */ /** @@ -41,7 +41,7 @@ #ifdef USE_XTIMOSI #include #endif -#include +#include #include "eventl.h" #include "session.h" #include @@ -61,7 +61,7 @@ statserv_options_block control_block = { 1, /* dynamic mode */ 0, /* threaded mode */ 0, /* one shot (single session) */ - LOG_DEFAULT_LEVEL, /* log level */ + YLOG_DEFAULT_LEVEL, /* log level */ "", /* no PDUs */ "", /* diagnostic output to stderr */ "tcp:@:9999", /* default listener port */ @@ -290,12 +290,12 @@ static void listener(IOCHAN h, int event) { if ((res = cs_listen(line, 0, 0)) < 0) { - yaz_log(LOG_FATAL, "cs_listen failed"); + yaz_log(YLOG_FATAL, "cs_listen failed"); return; } else if (res == 1) return; - yaz_log(LOG_DEBUG, "listen ok"); + yaz_log(YLOG_DEBUG, "listen ok"); iochan_setevent(h, EVENT_OUTPUT); iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */ } @@ -307,24 +307,24 @@ static void listener(IOCHAN h, int event) if (!new_line) { - yaz_log(LOG_FATAL, "Accept failed."); + yaz_log(YLOG_FATAL, "Accept failed."); iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); return; } - yaz_log(LOG_DEBUG, "Accept ok"); + yaz_log(YLOG_DEBUG, "Accept ok"); if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session, EVENT_INPUT))) { - yaz_log(LOG_FATAL, "Failed to create iochan"); + yaz_log(YLOG_FATAL, "Failed to create iochan"); iochan_destroy(h); return; } - yaz_log(LOG_DEBUG, "Creating association"); + yaz_log(YLOG_DEBUG, "Creating association"); if (!(newas = create_association(new_chan, new_line))) { - yaz_log(LOG_FATAL, "Failed to create new assoc."); + yaz_log(YLOG_FATAL, "Failed to create new assoc."); iochan_destroy(h); return; } @@ -332,7 +332,7 @@ static void listener(IOCHAN h, int event) newas->cs_put_mask = 0; newas->cs_accept_mask = 0; - yaz_log(LOG_DEBUG, "Setting timeout %d", control_block.idle_timeout); + yaz_log(YLOG_DEBUG, "Setting timeout %d", control_block.idle_timeout); iochan_setdata(new_chan, newas); iochan_settimeout(new_chan, 60); @@ -342,19 +342,19 @@ static void listener(IOCHAN h, int event) if (newHandle == (HANDLE) -1) { - yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create new thread."); + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to create new thread."); iochan_destroy(h); return; } /* We successfully created the thread, so add it to the list */ statserv_add(newHandle, new_chan); - yaz_log(LOG_DEBUG, "Created new thread, id = %ld iochan %p",(long) newHandle, new_chan); + yaz_log(YLOG_DEBUG, "Created new thread, id = %ld iochan %p",(long) newHandle, new_chan); iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */ } else { - yaz_log(LOG_FATAL, "Bad event on listener."); + yaz_log(YLOG_FATAL, "Bad event on listener."); iochan_destroy(h); return; } @@ -417,13 +417,13 @@ static void listener(IOCHAN h, int event) ++no_sessions; if (pipe(hand) < 0) { - yaz_log(LOG_FATAL|LOG_ERRNO, "pipe"); + yaz_log(YLOG_FATAL|YLOG_ERRNO, "pipe"); iochan_destroy(h); return; } if ((res = fork()) < 0) { - yaz_log(LOG_FATAL|LOG_ERRNO, "fork"); + yaz_log(YLOG_FATAL|YLOG_ERRNO, "fork"); iochan_destroy(h); return; } @@ -461,13 +461,13 @@ static void listener(IOCHAN h, int event) if ((res = read(hand[0], dummy, 1)) < 0 && yaz_errno() != EINTR) { - yaz_log(LOG_FATAL|LOG_ERRNO, "handshake read"); + yaz_log(YLOG_FATAL|YLOG_ERRNO, "handshake read"); return; } else if (res >= 0) break; } - yaz_log(LOG_DEBUG, "P: Child has taken the call"); + yaz_log(YLOG_DEBUG, "P: Child has taken the call"); close(hand[0]); return; } @@ -475,12 +475,12 @@ static void listener(IOCHAN h, int event) if ((res = cs_listen_check(line, 0, 0, control_block.check_ip, control_block.daemon_name)) < 0) { - yaz_log(LOG_WARN|LOG_ERRNO, "cs_listen failed"); + yaz_log(YLOG_WARN|YLOG_ERRNO, "cs_listen failed"); return; } else if (res == 1) return; - yaz_log(LOG_DEBUG, "listen ok"); + yaz_log(YLOG_DEBUG, "listen ok"); iochan_setevent(h, EVENT_OUTPUT); iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */ } @@ -491,11 +491,11 @@ static void listener(IOCHAN h, int event) if (!new_line) { - yaz_log(LOG_FATAL, "Accept failed."); + yaz_log(YLOG_FATAL, "Accept failed."); iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */ return; } - yaz_log(LOG_DEBUG, "accept ok"); + yaz_log(YLOG_DEBUG, "accept ok"); if (control_block.dynamic) { IOCHAN pp; @@ -507,7 +507,7 @@ static void listener(IOCHAN h, int event) iochan_destroy(pp); } /* release dad */ - yaz_log(LOG_DEBUG, "Releasing parent"); + yaz_log(YLOG_DEBUG, "Releasing parent"); close(hand[1]); } else @@ -534,9 +534,9 @@ static void listener(IOCHAN h, int event) pth_attr_set (attr, PTH_ATTR_JOINABLE, FALSE); pth_attr_set (attr, PTH_ATTR_STACK_SIZE, 32*1024); pth_attr_set (attr, PTH_ATTR_NAME, "session"); - yaz_log (LOG_DEBUG, "pth_spawn begin"); + yaz_log (YLOG_DEBUG, "pth_spawn begin"); child_thread = pth_spawn (attr, new_session, new_line); - yaz_log (LOG_DEBUG, "pth_spawn finish"); + yaz_log (YLOG_DEBUG, "pth_spawn finish"); pth_attr_destroy (attr); } else @@ -552,7 +552,7 @@ static void listener(IOCHAN h, int event) } else { - yaz_log(LOG_FATAL, "Bad event on listener."); + yaz_log(YLOG_FATAL, "Bad event on listener."); iochan_destroy(h); } } @@ -581,12 +581,12 @@ static void *new_session (void *vp) if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session, mask))) { - yaz_log(LOG_FATAL, "Failed to create iochan"); + yaz_log(YLOG_FATAL, "Failed to create iochan"); return 0; } if (!(newas = create_association(new_chan, new_line))) { - yaz_log(LOG_FATAL, "Failed to create new assoc."); + yaz_log(YLOG_FATAL, "Failed to create new assoc."); return 0; } newas->cs_accept_mask = cs_accept_mask; @@ -640,19 +640,19 @@ static void inetd_connection(int what) } else { - yaz_log(LOG_FATAL, "Failed to create association structure"); + yaz_log(YLOG_FATAL, "Failed to create association structure"); } chan->next = pListener; pListener = chan; } else { - yaz_log(LOG_FATAL, "Failed to create iochan"); + yaz_log(YLOG_FATAL, "Failed to create iochan"); } } else { - yaz_log(LOG_ERRNO|LOG_FATAL, "Failed to create comstack on socket 0"); + yaz_log(YLOG_ERRNO|YLOG_FATAL, "Failed to create comstack on socket 0"); } } @@ -679,7 +679,7 @@ static int add_listener(char *where, int what) l = cs_create_host(where, 2, &ap); if (!l) { - yaz_log(LOG_FATAL, "Failed to listen on %s", where); + yaz_log(YLOG_FATAL, "Failed to listen on %s", where); return -1; } if (*control_block.cert_fname) @@ -687,14 +687,14 @@ static int add_listener(char *where, int what) if (cs_bind(l, ap, CS_SERVER) < 0) { - yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to bind to %s", where); + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to bind to %s", where); cs_close (l); return -1; } if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT | EVENT_EXCEPT))) { - yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create IOCHAN-type"); + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to create IOCHAN-type"); cs_close (l); return -1; } @@ -806,7 +806,7 @@ int statserv_start(int argc, char **argv) FILE *f = fopen(control_block.pid_fname, "w"); if (!f) { - yaz_log(LOG_FATAL|LOG_ERRNO, "Couldn't create %s", + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Couldn't create %s", control_block.pid_fname); exit(0); } @@ -835,12 +835,12 @@ int statserv_start(int argc, char **argv) if (!(pw = getpwnam(control_block.setuid))) { - yaz_log(LOG_FATAL, "%s: Unknown user", control_block.setuid); + yaz_log(YLOG_FATAL, "%s: Unknown user", control_block.setuid); return(1); } if (setuid(pw->pw_uid) < 0) { - yaz_log(LOG_FATAL|LOG_ERRNO, "setuid"); + yaz_log(YLOG_FATAL|YLOG_ERRNO, "setuid"); exit(1); } } @@ -854,7 +854,7 @@ int statserv_start(int argc, char **argv) ret = 1; else { - yaz_log(LOG_DEBUG, "Entering event loop."); + yaz_log(YLOG_DEBUG, "Entering event loop."); ret = event_loop(&pListener); } return ret; @@ -959,7 +959,7 @@ int check_options(int argc, char **argv) case 'p': if (strlen(arg) >= sizeof(control_block.pid_fname)) { - yaz_log(LOG_FATAL, "pid fname too long"); + yaz_log(YLOG_FATAL, "pid fname too long"); exit(1); } strcpy(control_block.pid_fname, arg); diff --git a/src/tcpdchk.c b/src/tcpdchk.c index fe5ce24..5f18801 100644 --- a/src/tcpdchk.c +++ b/src/tcpdchk.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: tcpdchk.c,v 1.2 2004-10-15 00:19:01 adam Exp $ + * $Id: tcpdchk.c,v 1.3 2004-11-18 15:18:13 heikki Exp $ */ /** * \file tcpdchk.c @@ -14,13 +14,16 @@ #include #include +#include +#include + #if HAVE_TCPD_H #include #include -int allow_severity = LOG_INFO; +int allow_severity = LOG_INFO; /* not YLOG !! */ int deny_severity = LOG_WARNING; #ifdef LOG_DEBUG @@ -32,9 +35,6 @@ int deny_severity = LOG_WARNING; #endif -#include -#include - int check_ip_tcpd(void *cd, const char *addr, int len, int type) { const char *daemon_name = (const char *) cd; @@ -70,11 +70,11 @@ int check_ip_tcpd(void *cd, const char *addr, int len, int type) i = hosts_access(&request_info); if (!i) { - yaz_log (LOG_DEBUG, "access denied from %s", + yaz_log (YLOG_DEBUG, "access denied from %s", host_name ? host_name : host_addr); return 1; } - yaz_log (LOG_DEBUG, "access granted from %s", + yaz_log (YLOG_DEBUG, "access granted from %s", host_name ? host_name : host_addr); #endif } diff --git a/src/tcpip.c b/src/tcpip.c index 890dcc4..f417c24 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: tcpip.c,v 1.11 2004-10-15 00:19:01 adam Exp $ + * $Id: tcpip.c,v 1.12 2004-11-18 15:18:14 heikki Exp $ */ /** * \file tcpip.c @@ -28,7 +28,6 @@ #include #include -#include #include #ifdef WIN32 diff --git a/src/tpath.c b/src/tpath.c index a525a91..45d0784 100644 --- a/src/tpath.c +++ b/src/tpath.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data. * See the file LICENSE for details. * - * $Id: tpath.c,v 1.2 2004-10-15 00:19:01 adam Exp $ + * $Id: tpath.c,v 1.3 2004-11-18 15:18:14 heikki Exp $ */ /** * \file tpath.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include FILE *yaz_path_fopen(const char *path, const char *name, const char *mode) { diff --git a/src/unix.c b/src/unix.c index 75ceb17..8f8abd2 100644 --- a/src/unix.c +++ b/src/unix.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: unix.c,v 1.6 2004-10-15 00:19:01 adam Exp $ + * $Id: unix.c,v 1.7 2004-11-18 15:18:14 heikki Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ /** @@ -30,7 +30,6 @@ #include #include -#include #include #ifndef YAZ_SOCKLEN_T diff --git a/src/xmalloc.c b/src/xmalloc.c index 132d172..948e518 100644 --- a/src/xmalloc.c +++ b/src/xmalloc.c @@ -2,7 +2,7 @@ * Copyright (C) 1994-2004, Index Data * All rights reserved. * - * $Id: xmalloc.c,v 1.2 2004-10-15 00:19:01 adam Exp $ + * $Id: xmalloc.c,v 1.3 2004-11-18 15:18:14 heikki Exp $ */ /** * \file xmalloc.c @@ -17,13 +17,16 @@ #include #include -#include +#include #include #ifndef TRACE_XMALLOC #define TRACE_XMALLOC 1 #endif +static int log_level=0; +static int log_level_initialized=0; + #if TRACE_XMALLOC > 1 static const unsigned char head[] = {88, 77, 66, 55, 44, 33, 22, 11}; @@ -40,11 +43,18 @@ struct dmalloc_info { struct dmalloc_info *dmalloc_list = 0; + void *xmalloc_d(size_t nbytes, const char *file, int line) { char *res; struct dmalloc_info *dinfo; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + if (!(res = (char*) malloc(nbytes + sizeof(*dinfo)+16*sizeof(char)))) return 0; dinfo = (struct dmalloc_info *) res; @@ -75,12 +85,12 @@ void xfree_d(void *ptr, const char *file, int line) ((char*)ptr - 8*sizeof(char) - sizeof(*dinfo)); if (memcmp(head, (char*) ptr - 8*sizeof(char), 8*sizeof(char))) { - yaz_log(LOG_FATAL, "xfree_d bad head, %s:%d, %p", file, line, ptr); + yaz_log(YLOG_FATAL, "xfree_d bad head, %s:%d, %p", file, line, ptr); abort(); } if (memcmp((char*) ptr + dinfo->len, tail, 8*sizeof(char))) { - yaz_log(LOG_FATAL, "xfree_d bad tail, %s:%d, %p", file, line, ptr); + yaz_log(YLOG_FATAL, "xfree_d bad tail, %s:%d, %p", file, line, ptr); abort(); } if (dinfo->prev) @@ -100,6 +110,12 @@ void *xrealloc_d(void *p, size_t nbytes, const char *file, int line) char *ptr = (char*) p; char *res; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + if (!ptr) { if (!nbytes) @@ -110,14 +126,14 @@ void *xrealloc_d(void *p, size_t nbytes, const char *file, int line) { if (memcmp(head, ptr - 8*sizeof(char), 8*sizeof(char))) { - yaz_log(LOG_FATAL, "xrealloc_d bad head, %s:%d, %p", + yaz_log(YLOG_FATAL, "xrealloc_d bad head, %s:%d, %p", file, line, ptr); abort(); } dinfo = (struct dmalloc_info *) (ptr-8*sizeof(char) - sizeof(*dinfo)); if (memcmp(ptr + dinfo->len, tail, 8*sizeof(char))) { - yaz_log(LOG_FATAL, "xrealloc_d bad tail, %s:%d, %p", + yaz_log(YLOG_FATAL, "xrealloc_d bad tail, %s:%d, %p", file, line, ptr); abort(); } @@ -162,6 +178,12 @@ void *xcalloc_d(size_t nmemb, size_t size, const char *file, int line) struct dmalloc_info *dinfo; size_t nbytes = nmemb * size; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + if (!(res = (char*) calloc(1, nbytes+sizeof(*dinfo)+16*sizeof(char)))) return 0; dinfo = (struct dmalloc_info *) res; @@ -187,15 +209,21 @@ void xmalloc_trav_d(const char *file, int line) size_t size = 0; struct dmalloc_info *dinfo = dmalloc_list; - yaz_log (LOG_MALLOC, "malloc_trav %s:%d", file, line); + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + + yaz_log (log_level, "malloc_trav %s:%d", file, line); while (dinfo) { - yaz_log (LOG_MALLOC, " %20s:%d p=%p size=%d", dinfo->file, dinfo->line, + yaz_log (log_level, " %20s:%d p=%p size=%d", dinfo->file, dinfo->line, ((char*) dinfo)+sizeof(*dinfo)+8*sizeof(char), dinfo->len); size += dinfo->len; dinfo = dinfo->next; } - yaz_log (LOG_MALLOC, "total bytes %ld", (long) size); + yaz_log (log_level, "total bytes %ld", (long) size); } #else @@ -209,6 +237,12 @@ void xmalloc_trav_d(const char *file, int line) void xmalloc_trav_f(const char *s, const char *file, int line) { + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + xmalloc_trav_d(file, line); } @@ -216,13 +250,18 @@ void *xrealloc_f (void *o, size_t size, const char *file, int line) { void *p = xrealloc_d (o, size, file, line); -#if TRACE_XMALLOC - yaz_log (LOG_MALLOC, + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + + if(log_level) + yaz_log (log_level, "%s:%d: xrealloc(s=%d) %p -> %p", file, line, size, o, p); -#endif if (!p) { - yaz_log (LOG_FATAL|LOG_ERRNO, "Out of memory, realloc (%d bytes)", + yaz_log (YLOG_FATAL|YLOG_ERRNO, "Out of memory, realloc (%d bytes)", size); exit(1); } @@ -233,12 +272,18 @@ void *xmalloc_f (size_t size, const char *file, int line) { void *p = xmalloc_d (size, file, line); -#if TRACE_XMALLOC - yaz_log (LOG_MALLOC, "%s:%d: xmalloc(s=%d) %p", file, line, size, p); -#endif + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + + if (log_level) + yaz_log (log_level, "%s:%d: xmalloc(s=%d) %p", file, line, size, p); + if (!p) { - yaz_log (LOG_FATAL, "Out of memory - malloc (%d bytes)", size); + yaz_log (YLOG_FATAL, "Out of memory - malloc (%d bytes)", size); exit (1); } return p; @@ -247,12 +292,18 @@ void *xmalloc_f (size_t size, const char *file, int line) void *xcalloc_f (size_t nmemb, size_t size, const char *file, int line) { void *p = xcalloc_d (nmemb, size, file, line); -#if TRACE_XMALLOC - yaz_log (LOG_MALLOC, "%s:%d: xcalloc(s=%d) %p", file, line, size, p); -#endif + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + + if (log_level) + yaz_log (log_level, "%s:%d: xcalloc(s=%d) %p", file, line, size, p); + if (!p) { - yaz_log (LOG_FATAL, "Out of memory - calloc (%d, %d)", nmemb, size); + yaz_log (YLOG_FATAL, "Out of memory - calloc (%d, %d)", nmemb, size); exit (1); } return p; @@ -261,9 +312,15 @@ void *xcalloc_f (size_t nmemb, size_t size, const char *file, int line) char *xstrdup_f (const char *s, const char *file, int line) { char *p = (char *)xmalloc_d (strlen(s)+1, file, line); -#if TRACE_XMALLOC - yaz_log (LOG_MALLOC, "%s:%d: xstrdup(s=%d) %p", file, line, strlen(s)+1, p); -#endif + if (!log_level_initialized) + { + log_level=yaz_log_module_level("malloc"); + log_level_initialized=1; + } + + if (log_level) + yaz_log (log_level, "%s:%d: xstrdup(s=%d) %p", file, line, strlen(s)+1, p); + strcpy (p, s); return p; } @@ -272,9 +329,7 @@ void xfree_f(void *p, const char *file, int line) { if (!p) return ; -#if TRACE_XMALLOC - if (p) - yaz_log (LOG_MALLOC, "%s:%d: xfree %p", file, line, p); -#endif + if (log_level) + yaz_log (log_level, "%s:%d: xfree %p", file, line, p); xfree_d(p, file, line); } diff --git a/src/zoom-c.c b/src/zoom-c.c index ad24eac..e95ca03 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2004, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.31 2004-10-15 00:19:01 adam Exp $ + * $Id: zoom-c.c,v 1.32 2004-11-18 15:18:14 heikki Exp $ */ /** * \file zoom-c.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -28,6 +28,9 @@ #include #endif +static int log_level=0; +static int log_level_initialized=0; + typedef enum { zoom_pending, zoom_complete @@ -94,6 +97,12 @@ static void set_dset_error (ZOOM_connection c, int error, const char *addinfo, const char *addinfo2) { char *cp; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("zoom"); + log_level_initialized=1; + } + xfree (c->addinfo); c->addinfo = 0; c->error = error; @@ -114,7 +123,7 @@ static void set_dset_error (ZOOM_connection c, int error, else if (addinfo) c->addinfo = xstrdup(addinfo); if (error) - yaz_log(LOG_DEBUG, "Error %s %s:%d %s %s", + yaz_log(log_level, "Error %s %s:%d %s %s", c->host_port ? c->host_port : "<>", dset, error, addinfo ? addinfo : "", addinfo2 ? addinfo2 : ""); @@ -227,6 +236,12 @@ ZOOM_connection_create (ZOOM_options options) { ZOOM_connection c = (ZOOM_connection) xmalloc (sizeof(*c)); + if (!log_level_initialized) + { + log_level=yaz_log_module_level("zoom"); + log_level_initialized=1; + } + c->proto = PROTO_Z3950; c->cs = 0; c->mask = 0; @@ -339,13 +354,19 @@ ZOOM_connection_connect(ZOOM_connection c, const char *val; ZOOM_task task; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("zoom"); + log_level_initialized=1; + } + if (c->cs) { - yaz_log (LOG_DEBUG, "reconnect"); + yaz_log (log_level, "reconnect"); c->reconnect_ok = 1; return; } - yaz_log(LOG_DEBUG, "connect"); + yaz_log(log_level, "connect"); xfree (c->proxy); val = ZOOM_options_get (c->options, "proxy"); if (val && *val) @@ -421,7 +442,7 @@ ZOOM_query_destroy(ZOOM_query s) return; (s->refcount)--; - yaz_log (LOG_DEBUG, "ZOOM_query_destroy count=%d", s->refcount); + yaz_log (log_level, "ZOOM_query_destroy count=%d", s->refcount); if (s->refcount == 0) { odr_destroy (s->odr); @@ -510,7 +531,7 @@ void ZOOM_resultset_addref (ZOOM_resultset r) if (r) { (r->refcount)++; - yaz_log (LOG_DEBUG, "ZOOM_resultset_addref r=%p count=%d", + yaz_log (log_level, "ZOOM_resultset_addref r=%p count=%d", r, r->refcount); } } @@ -519,7 +540,13 @@ ZOOM_resultset ZOOM_resultset_create () { ZOOM_resultset r = (ZOOM_resultset) xmalloc (sizeof(*r)); - yaz_log (LOG_DEBUG, "ZOOM_resultset_create r = %p", r); + if (!log_level_initialized) + { + log_level=yaz_log_module_level("zoom"); + log_level_initialized=1; + } + + yaz_log (log_level, "ZOOM_resultset_create r = %p", r); r->refcount = 1; r->size = 0; r->odr = odr_createmem (ODR_ENCODE); @@ -587,12 +614,12 @@ ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) { if (!c->cs) { - yaz_log(LOG_DEBUG, "NO COMSTACK"); + yaz_log(log_level, "NO COMSTACK"); ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); } else { - yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT"); + yaz_log(log_level, "PREPARE FOR RECONNECT"); c->reconnect_ok = 1; } } @@ -625,12 +652,12 @@ ZOOM_API(void) { if (!c->cs) { - yaz_log(LOG_DEBUG, "NO COMSTACK"); + yaz_log(log_level, "NO COMSTACK"); ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); } else { - yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT"); + yaz_log(log_level, "PREPARE FOR RECONNECT"); c->reconnect_ok = 1; } } @@ -673,7 +700,7 @@ ZOOM_resultset_destroy(ZOOM_resultset r) if (!r) return; (r->refcount)--; - yaz_log (LOG_DEBUG, "ZOOM_resultset_destroy r = %p count=%d", + yaz_log (log_level, "ZOOM_resultset_destroy r = %p count=%d", r, r->refcount); if (r->refcount == 0) { @@ -735,12 +762,12 @@ static void ZOOM_resultset_retrieve (ZOOM_resultset r, { if (!c->cs) { - yaz_log(LOG_DEBUG, "NO COMSTACK"); + yaz_log(log_level, "NO COMSTACK"); ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); } else { - yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT"); + yaz_log(log_level, "PREPARE FOR RECONNECT"); c->reconnect_ok = 1; } } @@ -802,13 +829,19 @@ static zoom_ret do_connect (ZOOM_connection c) { void *add; const char *effective_host; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("zoom"); + log_level_initialized=1; + } + if (c->proxy) effective_host = c->proxy; else effective_host = c->host_port; - yaz_log (LOG_DEBUG, "do_connect host=%s", effective_host); + yaz_log (log_level, "do_connect host=%s", effective_host); if (c->cs) cs_close(c->cs); @@ -942,7 +975,7 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) z_APDU(odr_pr, &a, 0, 0); odr_destroy(odr_pr); } - yaz_log (LOG_DEBUG, "encoding failed"); + yaz_log (log_level, "encoding failed"); set_ZOOM_error(c, ZOOM_ERROR_ENCODE, 0); odr_reset(out); return -1; @@ -957,7 +990,7 @@ static zoom_ret send_APDU (ZOOM_connection c, Z_APDU *a) assert (a); if (encode_APDU(c, a, c->odr_out)) return zoom_complete; - yaz_log(LOG_DEBUG, "send APDU type=%d", a->which); + yaz_log(log_level, "send APDU type=%d", a->which); c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0); event = ZOOM_Event_create (ZOOM_EVENT_SEND_APDU); ZOOM_connection_put_event (c, event); @@ -1004,7 +1037,7 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) ZOOM_options_get(c->options, "implementationName"), odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.31 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.32 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = odr_prepend(c->odr_out, @@ -1352,7 +1385,7 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) break; } r->setname = xstrdup (setname); - yaz_log (LOG_DEBUG, "allocating set %s", r->setname); + yaz_log (log_level, "allocating set %s", r->setname); } else r->setname = xstrdup ("default"); @@ -1975,7 +2008,7 @@ static void handle_search_response (ZOOM_connection c, Z_SearchResponse *sr) ZOOM_resultset resultset; ZOOM_Event event; - yaz_log (LOG_DEBUG, "got search response"); + yaz_log (log_level, "got search response"); if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH) return ; @@ -2766,20 +2799,20 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) if (!task) { - yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task task="); + yaz_log (log_level, "ZOOM_connection_exec_task task="); return 0; } - yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task type=%d run=%d", + yaz_log (log_level, "ZOOM_connection_exec_task type=%d run=%d", task->which, task->running); if (c->error != ZOOM_ERROR_NONE) { - yaz_log (LOG_DEBUG, "remove tasks because of error = %d", c->error); + yaz_log (log_level, "remove tasks because of error = %d", c->error); ZOOM_connection_remove_tasks (c); return 0; } if (task->running) { - yaz_log (LOG_DEBUG, "task already running"); + yaz_log (log_level, "task already running"); return 0; } task->running = 1; @@ -2818,16 +2851,16 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) } else { - yaz_log (LOG_DEBUG, "remove tasks because no connection exist"); + yaz_log (log_level, "remove tasks because no connection exist"); ZOOM_connection_remove_tasks (c); } if (ret == zoom_complete) { - yaz_log (LOG_DEBUG, "task removed (complete)"); + yaz_log (log_level, "task removed (complete)"); ZOOM_connection_remove_task (c); return 0; } - yaz_log (LOG_DEBUG, "task pending"); + yaz_log (log_level, "task pending"); return 1; } @@ -2868,7 +2901,7 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) Z_InitResponse *initrs; c->mask = 0; - yaz_log (LOG_DEBUG, "recv APDU type=%d", apdu->which); + yaz_log (log_level, "recv APDU type=%d", apdu->which); switch(apdu->which) { case Z_APDU_initResponse: @@ -2927,7 +2960,7 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) int sel; yaz_get_response_charneg(tmpmem, p, &charset, &lang, &sel); - yaz_log(LOG_DEBUG, "Target accepted: charset %s, " + yaz_log(log_level, "Target accepted: charset %s, " "language %s, select %d", charset ? charset : "none", lang ? lang : "none", sel); if (charset) @@ -3006,7 +3039,7 @@ static void handle_srw_response(ZOOM_connection c, resultset->size = 0; - yaz_log(LOG_DEBUG, "got SRW response OK"); + yaz_log(log_level, "got SRW response OK"); if (res->numberOfRecords) resultset->size = *res->numberOfRecords; @@ -3069,7 +3102,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) const char *connection_head = z_HTTP_header_lookup(hres->headers, "Connection"); c->mask = 0; - yaz_log (LOG_DEBUG, "handle_http"); + yaz_log (log_level, "handle_http"); if (content_type && !yaz_strcmp_del("text/xml", content_type, "; ")) { @@ -3136,7 +3169,7 @@ static int do_read (ZOOM_connection c) r = cs_get (c->cs, &c->buf_in, &c->len_in); more = cs_more(c->cs); - yaz_log (LOG_DEBUG, "do_read len=%d more=%d", r, more); + yaz_log (log_level, "do_read len=%d more=%d", r, more); if (r == 1) return 0; if (r <= 0) @@ -3145,7 +3178,7 @@ static int do_read (ZOOM_connection c) { do_close (c); c->reconnect_ok = 0; - yaz_log (LOG_DEBUG, "reconnect read"); + yaz_log (log_level, "reconnect read"); c->tasks->running = 0; ZOOM_connection_insert_task (c, ZOOM_TASK_CONNECT); } @@ -3200,14 +3233,14 @@ static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out) event = ZOOM_Event_create(ZOOM_EVENT_SEND_DATA); ZOOM_connection_put_event (c, event); - yaz_log (LOG_DEBUG, "do_write_ex len=%d", len_out); + yaz_log (log_level, "do_write_ex len=%d", len_out); if ((r=cs_put (c->cs, buf_out, len_out)) < 0) { if (c->reconnect_ok) { do_close (c); c->reconnect_ok = 0; - yaz_log (LOG_DEBUG, "reconnect write"); + yaz_log (log_level, "reconnect write"); c->tasks->running = 0; ZOOM_connection_insert_task (c, ZOOM_TASK_CONNECT); return zoom_pending; @@ -3226,12 +3259,12 @@ static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out) c->mask += ZOOM_SELECT_WRITE; if (c->cs->io_pending & CS_WANT_READ) c->mask += ZOOM_SELECT_READ; - yaz_log (LOG_DEBUG, "do_write_ex 1 mask=%d", c->mask); + yaz_log (log_level, "do_write_ex 1 mask=%d", c->mask); } else { c->mask = ZOOM_SELECT_READ|ZOOM_SELECT_EXCEPT; - yaz_log (LOG_DEBUG, "do_write_ex 2 mask=%d", c->mask); + yaz_log (log_level, "do_write_ex 2 mask=%d", c->mask); } return zoom_pending; } @@ -3368,7 +3401,7 @@ static int ZOOM_connection_do_io(ZOOM_connection c, int mask) { ZOOM_Event event = 0; int r = cs_look(c->cs); - yaz_log (LOG_DEBUG, "ZOOM_connection_do_io c=%p mask=%d cs_look=%d", + yaz_log (log_level, "ZOOM_connection_do_io c=%p mask=%d cs_look=%d", c, mask, r); if (r == CS_NONE) @@ -3384,7 +3417,7 @@ static int ZOOM_connection_do_io(ZOOM_connection c, int mask) event = ZOOM_Event_create (ZOOM_EVENT_CONNECT); ret = cs_rcvconnect (c->cs); - yaz_log (LOG_DEBUG, "cs_rcvconnect returned %d", ret); + yaz_log (log_level, "cs_rcvconnect returned %d", ret); if (ret == 1) { c->mask = ZOOM_SELECT_EXCEPT; @@ -3569,9 +3602,9 @@ ZOOM_event (int no, ZOOM_connection *cs) #else tv.tv_sec = timeout; tv.tv_usec = 0; - yaz_log (LOG_DEBUG, "select start"); + yaz_log (log_level, "select start"); r = select (max_fd+1, &input, &output, &except, &tv); - yaz_log (LOG_DEBUG, "select stop, returned r=%d", r); + yaz_log (log_level, "select stop, returned r=%d", r); for (i = 0; i #include #include -#include +#include int main(int argc, char **argv) { char *arg; int ret; - int level = LOG_LOG; + int level = YLOG_LOG; while ((ret = options("f:v:l:m:", argv, argc, &arg)) != -2) { diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index be86ef6..6f37182 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -2,7 +2,7 @@ * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: zoomsh.c,v 1.29 2004-04-29 08:54:56 adam Exp $ + * $Id: zoomsh.c,v 1.30 2004-11-18 15:18:14 heikki Exp $ */ /* ZOOM-C Shell */ @@ -23,7 +23,7 @@ #include -#include +#include #include #include #include @@ -269,7 +269,7 @@ static void cmd_debug (ZOOM_connection *c, ZOOM_resultset *r, ZOOM_options options, const char **args) { - yaz_log_init_level(LOG_ALL); + yaz_log_init_level(YLOG_ALL); } static void cmd_search (ZOOM_connection *c, ZOOM_resultset *r, diff --git a/ztest/read-grs.c b/ztest/read-grs.c index 2bc09f9..1156e03 100644 --- a/ztest/read-grs.c +++ b/ztest/read-grs.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data. * See the file LICENSE for details. * - * $Id: read-grs.c,v 1.8 2003-01-06 08:20:29 adam Exp $ + * $Id: read-grs.c,v 1.9 2004-11-18 15:18:14 heikki Exp $ */ /* @@ -14,7 +14,7 @@ #include #include -#include +#include #define GRS_MAX_FIELDS 50 @@ -42,7 +42,7 @@ static Z_GenericRecord *read_grs1(FILE *f, ODR o) return r; if (sscanf(buf, "(%d,%[^)])", &type, value) != 2) { - yaz_log(LOG_WARN, "Bad data in '%s'", buf); + yaz_log(YLOG_WARN, "Bad data in '%s'", buf); return 0; } if (!type && *value == '0') diff --git a/ztest/ztest.c b/ztest/ztest.c index ba2731b..1396c4e 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2004, Index Data. * See the file LICENSE for details. * - * $Id: ztest.c,v 1.66 2004-11-16 17:08:11 heikki Exp $ + * $Id: ztest.c,v 1.67 2004-11-18 15:18:14 heikki Exp $ */ /* @@ -41,7 +41,7 @@ int ztest_search (void *handle, bend_search_rr *rr) /* if database is stop, stop this process.. For debugging only. */ if (!yaz_matchstr (rr->basenames[0], "stop")) { - nmem_print_list_l(LOG_LOG); + nmem_print_list_l(YLOG_LOG); exit(0); } #endif @@ -404,7 +404,7 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) } else { - yaz_log (LOG_WARN, "Unknown Extended Service(%d)", + yaz_log (YLOG_WARN, "Unknown Extended Service(%d)", rr->esr->taskSpecificParameters->which); } -- 1.7.10.4