2010-04-28 19:31:03 +00:00
|
|
|
/* LOGMSG.C (c) Copyright Ivan Warren, 2003-2010 */
|
2010-05-25 18:50:21 +00:00
|
|
|
/* (c) Copyright TurboHercules, SAS 2010 */
|
2010-04-28 19:31:03 +00:00
|
|
|
/* logmsg frontend routing */
|
|
|
|
|
/* */
|
|
|
|
|
/* Released under "The Q Public License Version 1" */
|
|
|
|
|
/* (http://www.hercules-390.org/herclic.html) as modifications to */
|
|
|
|
|
/* Hercules. */
|
2003-05-23 15:31:28 +00:00
|
|
|
|
2006-12-08 09:43:35 +00:00
|
|
|
// $Id$
|
|
|
|
|
|
2005-09-24 16:17:46 +00:00
|
|
|
#include "hstdinc.h"
|
|
|
|
|
|
|
|
|
|
#define _HUTIL_DLL_
|
|
|
|
|
#define _LOGMSG_C_
|
|
|
|
|
|
|
|
|
|
#include "hercules.h"
|
2003-05-23 15:31:28 +00:00
|
|
|
|
2005-12-06 17:38:29 +00:00
|
|
|
#define BFR_CHUNKSIZE (256)
|
|
|
|
|
|
|
|
|
|
/******************************************/
|
|
|
|
|
/* UTILITY MACRO BFR_VSNPRINTF */
|
|
|
|
|
/* Original design by Fish */
|
|
|
|
|
/* Modified by Jay Maynard */
|
|
|
|
|
/* Further modification by Ivan Warren */
|
|
|
|
|
/* */
|
|
|
|
|
/* Purpose : set 'bfr' to contain */
|
|
|
|
|
/* a C string based on a message format */
|
|
|
|
|
/* and a va_list of args. */
|
|
|
|
|
/* bfr must be free()d when over with */
|
|
|
|
|
/* this macro can ONLY be used from the */
|
|
|
|
|
/* topmost variable arg function */
|
|
|
|
|
/* that is the va_list cannot be passed */
|
|
|
|
|
/* as a parameter from another function */
|
|
|
|
|
/* since va_xxx functions behavio(u)r */
|
|
|
|
|
/* seems to be undefined in those cases */
|
|
|
|
|
/* char *bfr; must be originally defined */
|
|
|
|
|
/* int siz; must be defined and cont- */
|
|
|
|
|
/* ain a start size */
|
|
|
|
|
/* va_list vl; must be defined and init- */
|
|
|
|
|
/* ialised with va_start */
|
|
|
|
|
/* char *msg; is the message format */
|
|
|
|
|
/* int rc; to contain final size */
|
|
|
|
|
/******************************************/
|
2010-09-22 01:09:43 +00:00
|
|
|
#if defined(_MSVC_)
|
|
|
|
|
#define BFR_VSNPRINTF() \
|
|
|
|
|
bfr=malloc(siz); \
|
|
|
|
|
rc=-1; \
|
|
|
|
|
while(bfr&&rc<0) \
|
|
|
|
|
{ \
|
|
|
|
|
va_start(vl,msg); \
|
|
|
|
|
rc=_vsnprintf_s(bfr,siz,siz-1,msg,vl); \
|
|
|
|
|
va_end(vl); \
|
|
|
|
|
if(rc>=0 && rc<siz) \
|
|
|
|
|
break; \
|
|
|
|
|
rc=-1; \
|
|
|
|
|
siz+=BFR_CHUNKSIZE; \
|
|
|
|
|
bfr=realloc(bfr,siz); \
|
|
|
|
|
}
|
|
|
|
|
#else
|
2010-07-21 06:33:38 +00:00
|
|
|
#define BFR_VSNPRINTF() \
|
|
|
|
|
bfr=malloc(siz); \
|
|
|
|
|
rc=-1; \
|
|
|
|
|
while(bfr&&rc<0) \
|
|
|
|
|
{ \
|
|
|
|
|
va_start(vl,msg); \
|
|
|
|
|
rc=vsnprintf(bfr,siz,msg,vl); \
|
|
|
|
|
va_end(vl); \
|
|
|
|
|
if(rc>=0 && rc<siz) \
|
|
|
|
|
break; \
|
|
|
|
|
rc=-1; \
|
|
|
|
|
siz+=BFR_CHUNKSIZE; \
|
|
|
|
|
bfr=realloc(bfr,siz); \
|
|
|
|
|
}
|
2010-09-22 01:09:43 +00:00
|
|
|
#endif
|
2003-05-23 15:31:28 +00:00
|
|
|
static LOCK log_route_lock;
|
|
|
|
|
|
|
|
|
|
#define MAX_LOG_ROUTES 16
|
|
|
|
|
typedef struct _LOG_ROUTES
|
|
|
|
|
{
|
|
|
|
|
TID t;
|
|
|
|
|
LOG_WRITER *w;
|
|
|
|
|
LOG_CLOSER *c;
|
|
|
|
|
void *u;
|
|
|
|
|
} LOG_ROUTES;
|
|
|
|
|
|
|
|
|
|
LOG_ROUTES log_routes[MAX_LOG_ROUTES];
|
|
|
|
|
|
|
|
|
|
static int log_route_inited=0;
|
|
|
|
|
|
|
|
|
|
static void log_route_init(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if(log_route_inited)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initialize_lock(&log_route_lock);
|
|
|
|
|
for(i=0;i<MAX_LOG_ROUTES;i++)
|
|
|
|
|
{
|
|
|
|
|
log_routes[i].t=0;
|
|
|
|
|
log_routes[i].w=NULL;
|
|
|
|
|
log_routes[i].c=NULL;
|
|
|
|
|
log_routes[i].u=NULL;
|
|
|
|
|
}
|
|
|
|
|
log_route_inited=1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* LOG Routing functions */
|
|
|
|
|
static int log_route_search(TID t)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<MAX_LOG_ROUTES;i++)
|
|
|
|
|
{
|
|
|
|
|
if(log_routes[i].t==t)
|
|
|
|
|
{
|
|
|
|
|
if(t==0)
|
|
|
|
|
{
|
2004-09-23 17:11:57 +00:00
|
|
|
log_routes[i].t=(TID)1;
|
2003-05-23 15:31:28 +00:00
|
|
|
}
|
|
|
|
|
return(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Open a log redirection Driver route on a per-thread basis */
|
|
|
|
|
/* Up to 16 concurent threads may have an alternate logging route */
|
|
|
|
|
/* opened */
|
2005-09-24 16:17:46 +00:00
|
|
|
DLL_EXPORT int log_open(LOG_WRITER *lw,LOG_CLOSER *lc,void *uw)
|
2003-05-23 15:31:28 +00:00
|
|
|
{
|
|
|
|
|
int slot;
|
|
|
|
|
log_route_init();
|
|
|
|
|
obtain_lock(&log_route_lock);
|
|
|
|
|
slot=log_route_search((TID)0);
|
|
|
|
|
if(slot<0)
|
|
|
|
|
{
|
|
|
|
|
release_lock(&log_route_lock);
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
log_routes[slot].t=thread_id();
|
|
|
|
|
log_routes[slot].w=lw;
|
|
|
|
|
log_routes[slot].c=lc;
|
|
|
|
|
log_routes[slot].u=uw;
|
|
|
|
|
release_lock(&log_route_lock);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-24 16:17:46 +00:00
|
|
|
DLL_EXPORT void log_close(void)
|
2003-05-23 15:31:28 +00:00
|
|
|
{
|
|
|
|
|
int slot;
|
|
|
|
|
log_route_init();
|
|
|
|
|
obtain_lock(&log_route_lock);
|
|
|
|
|
slot=log_route_search(thread_id());
|
|
|
|
|
if(slot<0)
|
|
|
|
|
{
|
|
|
|
|
release_lock(&log_route_lock);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
log_routes[slot].c(log_routes[slot].u);
|
|
|
|
|
log_routes[slot].t=0;
|
|
|
|
|
log_routes[slot].w=NULL;
|
|
|
|
|
log_routes[slot].c=NULL;
|
|
|
|
|
log_routes[slot].u=NULL;
|
|
|
|
|
release_lock(&log_route_lock);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-20 09:20:22 +00:00
|
|
|
DLL_EXPORT void writemsg(const char *file, int line, const char* function, int grp, int lvl, char *color, char *msg, ...)
|
2010-04-09 12:41:40 +00:00
|
|
|
{
|
2010-07-21 06:33:38 +00:00
|
|
|
char *bfr = NULL;
|
|
|
|
|
int rc = 1;
|
|
|
|
|
int siz = 1024;
|
2010-04-09 12:41:40 +00:00
|
|
|
va_list vl;
|
2010-05-10 15:00:55 +00:00
|
|
|
|
2010-08-20 09:20:22 +00:00
|
|
|
if(!sysblk.msggrp || (sysblk.msggrp && !grp))
|
2010-08-21 06:10:19 +00:00
|
|
|
{
|
|
|
|
|
while(try_obtain_lock(&sysblk.msglock))
|
|
|
|
|
{
|
|
|
|
|
usleep(100);
|
|
|
|
|
if(host_tod() - sysblk.msglocktime > 1000000)
|
|
|
|
|
{
|
|
|
|
|
release_lock(&sysblk.msglock);
|
|
|
|
|
logmsg("HHC00016" "E" " " HHC00016 "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sysblk.msglocktime = host_tod();
|
|
|
|
|
}
|
2010-05-13 02:16:39 +00:00
|
|
|
|
2010-04-09 12:41:40 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2010-04-27 14:14:13 +00:00
|
|
|
|
2010-04-30 19:39:53 +00:00
|
|
|
#if defined( OPTION_MSGCLR )
|
|
|
|
|
if (!strlen(color))
|
|
|
|
|
{
|
|
|
|
|
switch(msg[8])
|
|
|
|
|
{
|
|
|
|
|
case 'S':
|
|
|
|
|
case 'E':
|
|
|
|
|
case 'W':
|
|
|
|
|
color = "<pnl,color(lightred,black),keep>";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
color = "";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-04-26 14:14:42 +00:00
|
|
|
}
|
2010-04-30 19:39:53 +00:00
|
|
|
#endif // defined( OPTION_MSGCLR )
|
2010-04-27 14:14:13 +00:00
|
|
|
|
2010-04-09 12:41:40 +00:00
|
|
|
switch(lvl)
|
|
|
|
|
{
|
2010-09-12 10:43:48 +00:00
|
|
|
case MLVL_NORMAL:
|
|
|
|
|
case MLVL_VERBOSE:
|
2010-04-30 19:39:53 +00:00
|
|
|
#if defined( OPTION_MSGCLR )
|
2010-06-11 06:31:17 +00:00
|
|
|
if (strlen(color) > 0 && !sysblk.shutdown && sysblk.panel_init)
|
2010-04-30 23:11:08 +00:00
|
|
|
{
|
2010-04-30 19:39:53 +00:00
|
|
|
logmsg(color);
|
2010-04-30 23:11:08 +00:00
|
|
|
}
|
2010-04-30 19:39:53 +00:00
|
|
|
#endif // defined( OPTION_MSGCLR )
|
|
|
|
|
BFR_VSNPRINTF();
|
|
|
|
|
break;
|
2010-09-12 10:43:48 +00:00
|
|
|
case MLVL_DEBUG:
|
2010-07-21 06:33:38 +00:00
|
|
|
|
2010-04-30 19:39:53 +00:00
|
|
|
#if defined( OPTION_MSGCLR )
|
2010-06-11 06:31:17 +00:00
|
|
|
if (strlen(color) > 0 && !sysblk.shutdown && sysblk.panel_init)
|
2010-05-10 15:00:55 +00:00
|
|
|
logmsg("%s%-10.10s %4d ", color, file, line);
|
2010-04-30 19:39:53 +00:00
|
|
|
else
|
2010-05-10 15:00:55 +00:00
|
|
|
logmsg("%-10.10s %4d ", file, line);
|
2010-04-30 19:39:53 +00:00
|
|
|
#else
|
2010-05-10 15:00:55 +00:00
|
|
|
logmsg("%-10.10s %4d ", file, line);
|
2010-04-30 19:39:53 +00:00
|
|
|
#endif
|
|
|
|
|
BFR_VSNPRINTF();
|
|
|
|
|
break;
|
2010-04-09 12:41:40 +00:00
|
|
|
}
|
2010-04-27 14:14:13 +00:00
|
|
|
|
2010-04-09 12:41:40 +00:00
|
|
|
if(bfr)
|
|
|
|
|
{
|
2010-07-21 06:33:38 +00:00
|
|
|
if ( !strncmp(bfr, "HHC", 3) && strlen(bfr) > 10 )
|
|
|
|
|
log_write( 0, ( sysblk.emsg & EMSG_TEXT ) ? &bfr[10] : bfr );
|
|
|
|
|
else
|
|
|
|
|
log_write( 0, bfr );
|
2010-04-09 12:41:40 +00:00
|
|
|
free(bfr);
|
|
|
|
|
}
|
2010-09-12 10:43:48 +00:00
|
|
|
if(MLVL(DEBUG) && (msg[8] == 'S' || msg[8] == 'E' || msg[8] == 'W'))
|
2010-05-27 18:40:59 +00:00
|
|
|
{
|
2010-06-01 01:52:48 +00:00
|
|
|
/* __FILENAME__ resolves differently for the various OS environments */
|
|
|
|
|
/* we are only interested in the filename and ext. */
|
|
|
|
|
char *fn = strdup( file );
|
2010-06-07 19:29:20 +00:00
|
|
|
logmsg("HHC00007" "I" " " HHC00007 "\n", function, basename(fn), line);
|
2010-06-01 01:52:48 +00:00
|
|
|
free( fn );
|
2010-05-27 18:40:59 +00:00
|
|
|
}
|
2010-06-07 19:29:20 +00:00
|
|
|
|
2010-05-10 15:00:55 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2010-06-07 19:29:20 +00:00
|
|
|
|
2010-08-20 09:20:22 +00:00
|
|
|
if(!sysblk.msggrp || (sysblk.msggrp && !grp))
|
|
|
|
|
release_lock(&sysblk.msglock);
|
2010-04-09 12:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
2005-09-24 16:17:46 +00:00
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
/* Log message: Normal routing (panel or buffer, as appropriate) */
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
DLL_EXPORT void logmsg(char *msg,...)
|
2005-02-06 23:18:21 +00:00
|
|
|
{
|
2010-07-21 06:33:38 +00:00
|
|
|
char *bfr = NULL;
|
|
|
|
|
int rc;
|
|
|
|
|
int siz = 1024;
|
2005-02-06 23:18:21 +00:00
|
|
|
va_list vl;
|
2010-07-21 06:33:38 +00:00
|
|
|
|
2010-04-30 19:39:53 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
2005-09-24 16:17:46 +00:00
|
|
|
fflush(stdout);
|
2010-04-30 19:39:53 +00:00
|
|
|
#endif
|
2005-12-06 17:38:29 +00:00
|
|
|
BFR_VSNPRINTF();
|
2010-04-30 19:39:53 +00:00
|
|
|
if ( bfr )
|
|
|
|
|
{
|
2010-07-21 06:33:38 +00:00
|
|
|
if ( !strncmp(bfr, "HHC", 3) && strlen(bfr) > 10 )
|
|
|
|
|
log_write( 0, ( sysblk.emsg & EMSG_TEXT ) ? &bfr[10] : bfr );
|
|
|
|
|
else
|
|
|
|
|
log_write( 0, bfr );
|
2010-04-30 19:39:53 +00:00
|
|
|
}
|
|
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
2005-02-06 23:18:21 +00:00
|
|
|
fflush(stdout);
|
2010-04-30 19:39:53 +00:00
|
|
|
#endif
|
|
|
|
|
if ( bfr )
|
2005-12-06 17:38:29 +00:00
|
|
|
{
|
|
|
|
|
free(bfr);
|
|
|
|
|
}
|
2005-09-24 16:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
2010-04-09 12:41:40 +00:00
|
|
|
// BHe I want to remove these functions for simplification
|
|
|
|
|
#if 0
|
2005-09-24 16:17:46 +00:00
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
/* Log message: Panel only (no logmsg routing) */
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
DLL_EXPORT void logmsgp(char *msg,...)
|
2005-02-06 23:18:21 +00:00
|
|
|
{
|
2005-12-06 17:38:29 +00:00
|
|
|
char *bfr=NULL;
|
2010-07-21 06:33:38 +00:00
|
|
|
char *ptr;
|
2005-12-06 17:38:29 +00:00
|
|
|
int rc;
|
|
|
|
|
int siz=1024;
|
2005-02-06 23:18:21 +00:00
|
|
|
va_list vl;
|
2005-09-24 16:17:46 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2005-12-06 17:38:29 +00:00
|
|
|
BFR_VSNPRINTF();
|
|
|
|
|
if(bfr)
|
2010-07-21 06:33:38 +00:00
|
|
|
{
|
|
|
|
|
if ( !strncmp(bfr, "HHC", 3) && strlen(bfr) > 10 )
|
|
|
|
|
log_write( 1, ( sysblk.emsg & EMSG_TEXT ) ? &bfr[10] : bfr );
|
|
|
|
|
else
|
|
|
|
|
log_write( 1, bfr );
|
|
|
|
|
}
|
2005-09-24 16:17:46 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
2005-02-06 23:18:21 +00:00
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2005-12-06 17:38:29 +00:00
|
|
|
if(bfr)
|
|
|
|
|
{
|
|
|
|
|
free(bfr);
|
|
|
|
|
}
|
2005-02-06 23:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
2005-09-24 16:17:46 +00:00
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
/* Log message: Both panel and logmsg routing */
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
DLL_EXPORT void logmsgb(char *msg,...)
|
2005-02-06 23:18:21 +00:00
|
|
|
{
|
2005-12-06 17:38:29 +00:00
|
|
|
char *bfr=NULL;
|
2010-07-21 06:33:38 +00:00
|
|
|
char *ptr;
|
2005-12-06 17:38:29 +00:00
|
|
|
int rc;
|
|
|
|
|
int siz=1024;
|
2005-02-06 23:18:21 +00:00
|
|
|
va_list vl;
|
2005-09-24 16:17:46 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2005-12-06 17:38:29 +00:00
|
|
|
BFR_VSNPRINTF();
|
|
|
|
|
if(bfr)
|
2010-07-21 06:33:38 +00:00
|
|
|
{
|
|
|
|
|
if ( !strncmp(bfr, "HHC", 3) && strlen(bfr) > 10 )
|
|
|
|
|
log_write( 2, ( sysblk.emsg & EMSG_TEXT ) ? &bfr[10] : bfr );
|
|
|
|
|
else
|
|
|
|
|
log_write( 2, bfr );
|
|
|
|
|
}
|
2005-09-24 16:17:46 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
2005-02-06 23:18:21 +00:00
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2005-12-06 17:38:29 +00:00
|
|
|
if(bfr)
|
|
|
|
|
{
|
|
|
|
|
free(bfr);
|
|
|
|
|
}
|
2005-02-06 23:18:21 +00:00
|
|
|
}
|
2010-04-09 12:41:40 +00:00
|
|
|
#endif
|
2005-02-06 23:18:21 +00:00
|
|
|
|
2005-09-24 16:17:46 +00:00
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
/* Log message: Device trace */
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
DLL_EXPORT void logdevtr(DEVBLK *dev,char *msg,...)
|
|
|
|
|
{
|
2010-07-21 06:33:38 +00:00
|
|
|
char *bfr=NULL;
|
|
|
|
|
int rc;
|
|
|
|
|
int siz=1024;
|
2005-09-24 16:17:46 +00:00
|
|
|
va_list vl;
|
2005-12-06 17:38:29 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2005-09-24 16:17:46 +00:00
|
|
|
if(dev->ccwtrace||dev->ccwstep)
|
|
|
|
|
{
|
2005-12-06 17:38:29 +00:00
|
|
|
BFR_VSNPRINTF();
|
|
|
|
|
if(bfr)
|
2010-07-21 06:33:38 +00:00
|
|
|
{
|
|
|
|
|
if ( !strncmp(bfr, "HHC", 3) && strlen(bfr) > 10 )
|
|
|
|
|
log_write( 2, ( sysblk.emsg & EMSG_TEXT ) ? &bfr[10] : bfr );
|
|
|
|
|
else
|
|
|
|
|
log_write( 2, bfr );
|
|
|
|
|
}
|
2005-09-24 16:17:46 +00:00
|
|
|
}
|
2005-12-06 17:38:29 +00:00
|
|
|
#ifdef NEED_LOGMSG_FFLUSH
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
|
|
|
|
if(bfr)
|
|
|
|
|
{
|
|
|
|
|
free(bfr);
|
|
|
|
|
}
|
2005-09-24 16:17:46 +00:00
|
|
|
} /* end function logdevtr */
|
|
|
|
|
|
2003-05-23 15:31:28 +00:00
|
|
|
/* panel : 0 - No, 1 - Only, 2 - Also */
|
2005-12-06 17:38:29 +00:00
|
|
|
DLL_EXPORT void log_write(int panel,char *msg)
|
2003-05-23 15:31:28 +00:00
|
|
|
{
|
2005-12-04 13:28:11 +00:00
|
|
|
/* (log_write function proper starts here) */
|
2010-07-21 06:33:38 +00:00
|
|
|
int slot;
|
|
|
|
|
char *ptr;
|
|
|
|
|
char *pszMSG;
|
|
|
|
|
|
|
|
|
|
ptr = malloc( (strlen(msg) + 1 + 20) );
|
|
|
|
|
if ( ptr == NULL )
|
|
|
|
|
pszMSG = msg;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( sysblk.emsg & EMSG_TS && strncasecmp( msg, "<pnl", 4 ) )
|
|
|
|
|
{
|
|
|
|
|
struct timeval now;
|
|
|
|
|
time_t tt;
|
|
|
|
|
char hhmmss[10];
|
|
|
|
|
|
|
|
|
|
gettimeofday( &now, NULL ); tt = now.tv_sec;
|
|
|
|
|
strlcpy( hhmmss, ctime(&tt)+11, sizeof(hhmmss) );
|
|
|
|
|
|
|
|
|
|
strcpy(ptr,hhmmss);
|
|
|
|
|
strcat(ptr,msg);
|
|
|
|
|
pszMSG = ptr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
pszMSG = msg;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-23 15:31:28 +00:00
|
|
|
log_route_init();
|
|
|
|
|
if(panel==1)
|
|
|
|
|
{
|
2010-07-21 06:33:38 +00:00
|
|
|
write_pipe( logger_syslogfd[LOG_WRITE], pszMSG, strlen(pszMSG) );
|
|
|
|
|
if ( ptr != NULL ) free(ptr);
|
2003-05-23 15:31:28 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
obtain_lock(&log_route_lock);
|
|
|
|
|
slot=log_route_search(thread_id());
|
|
|
|
|
release_lock(&log_route_lock);
|
|
|
|
|
if(slot<0 || panel>0)
|
|
|
|
|
{
|
2010-07-21 06:33:38 +00:00
|
|
|
write_pipe( logger_syslogfd[LOG_WRITE], pszMSG, strlen(pszMSG) );
|
2003-05-23 15:31:28 +00:00
|
|
|
if(slot<0)
|
2010-07-21 06:33:38 +00:00
|
|
|
{
|
|
|
|
|
if ( ptr != NULL ) free(ptr);
|
2003-05-23 15:31:28 +00:00
|
|
|
return;
|
2010-07-21 06:33:38 +00:00
|
|
|
}
|
2003-05-23 15:31:28 +00:00
|
|
|
}
|
2010-07-21 06:33:38 +00:00
|
|
|
|
|
|
|
|
if ( ptr != NULL ) free(ptr);
|
|
|
|
|
|
2005-12-06 17:38:29 +00:00
|
|
|
log_routes[slot].w(log_routes[slot].u,msg);
|
2003-05-23 15:31:28 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* capture log output routine series */
|
|
|
|
|
/* log_capture is a sample of how to */
|
|
|
|
|
/* use log rerouting. */
|
|
|
|
|
/* log_capture takes 2 args : */
|
|
|
|
|
/* a ptr to a function taking 1 parm */
|
|
|
|
|
/* the function parm */
|
|
|
|
|
struct log_capture_data
|
|
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
char *obfr;
|
|
|
|
|
size_t sz;
|
2003-05-23 15:31:28 +00:00
|
|
|
};
|
|
|
|
|
|
2005-09-24 16:17:46 +00:00
|
|
|
DLL_EXPORT void log_capture_writer(void *vcd,char *msg)
|
2003-05-23 15:31:28 +00:00
|
|
|
{
|
|
|
|
|
struct log_capture_data *cd;
|
2005-09-24 16:17:46 +00:00
|
|
|
if(!vcd||!msg)return;
|
2003-05-23 15:31:28 +00:00
|
|
|
cd=(struct log_capture_data *)vcd;
|
|
|
|
|
if(cd->sz==0)
|
|
|
|
|
{
|
|
|
|
|
cd->sz=strlen(msg)+1;
|
|
|
|
|
cd->obfr=malloc(cd->sz);
|
|
|
|
|
cd->obfr[0]=0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cd->sz+=strlen(msg);
|
|
|
|
|
cd->obfr=realloc(cd->obfr,cd->sz);
|
|
|
|
|
}
|
2003-06-02 13:16:07 +00:00
|
|
|
strcat(cd->obfr,msg);
|
2003-05-23 15:31:28 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2005-09-24 16:17:46 +00:00
|
|
|
DLL_EXPORT void log_capture_closer(void *vcd)
|
2003-05-23 15:31:28 +00:00
|
|
|
{
|
|
|
|
|
UNREFERENCED(vcd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-11 17:14:29 +00:00
|
|
|
DLL_EXPORT char *log_capture(void *(*fun)(void *),void *p)
|
2003-05-23 15:31:28 +00:00
|
|
|
{
|
|
|
|
|
struct log_capture_data cd;
|
|
|
|
|
cd.obfr=NULL;
|
|
|
|
|
cd.sz=0;
|
|
|
|
|
log_open(log_capture_writer,log_capture_closer,&cd);
|
2006-12-11 17:14:29 +00:00
|
|
|
fun(p);
|
2003-05-23 15:31:28 +00:00
|
|
|
log_close();
|
|
|
|
|
return(cd.obfr);
|
|
|
|
|
}
|