From: Chris B. <buc...@us...> - 2012-04-13 21:18:38
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "SFCB - Small Footprint CIM Broker". The branch, master has been updated via 3f1adc4d18eff30f4829ef38e3f654c14c532185 (commit) via e0480e068ebf4c87781973a8bd52c7087422f353 (commit) from c3e8b885ff74c3f29537aa32c38b0024fa02e2e8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 3f1adc4d18eff30f4829ef38e3f654c14c532185 Author: buccella <buc...@li...> Date: Fri Apr 13 17:18:36 2012 -0400 [ 3501314 ] Add dynamic logging and syslog output to sfcb trace commit e0480e068ebf4c87781973a8bd52c7087422f353 Author: buccella <buc...@li...> Date: Fri Apr 13 17:18:09 2012 -0400 [ 3501314 ] Add dynamic logging and syslog output to sfcb trace ----------------------------------------------------------------------- Summary of changes: diff --git a/ChangeLog b/ChangeLog index 70041b4..6b84f0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-04-13 Chris Buccella <buc...@li...> + + * Makefile.am, cimRequest.c, httpAdapter.c, httpComm.c, providerDrv.c, + providerMgr.c, sfcBroker.c, sfcb.cfg.pre.in, trace.c, trace.h: + [ 3501314 ] Add dynamic logging and syslog output to sfcb trace + (based on patch by Mike Lisanke) + 2012-04-13 Michael Chase-Salerno <br...@li...> * interopProvider.c: diff --git a/Makefile.am b/Makefile.am index 43ecd4a..f4dd810 100644 --- a/Makefile.am +++ b/Makefile.am @@ -167,7 +167,7 @@ sbin_PROGRAMS = \ sfcbd bin_PROGRAMS = \ - sfcbmofpp sfcbdump sfcbinst2mof + sfcbmofpp sfcbdump sfcbinst2mof sfcbtrace noinst_PROGRAMS = \ sfcbdumpP32onI32 classSchema2c sfcbsem @@ -410,6 +410,9 @@ sfcbdump_SOURCES=sfcbdump.c sfcbinst2mof_SOURCES=sfcbinst2mof.c sfcbinst2mof_LDADD = -lsfcFileRepository +sfcbtrace_SOURCES=sfcbtrace.c +sfcbtrace_LDADD = -lsfcBrokerCore + classSchema2c_SOURCES=classSchema2c.c classSchema2c_LDADD=-lsfcBrokerCore classSchema2c_DEPENDENCIES=libsfcBrokerCore.la diff --git a/NEWS b/NEWS index cf08bf1..3c35c75 100644 --- a/NEWS +++ b/NEWS @@ -91,6 +91,9 @@ Everything in 1.3.10, plus: Changes in 1.3.15 ================= +New Features: +- 3501314 Add dynamic logging and syslog output to sfcb trace + Bugs Fixed: - 3514627 unsupported sfcb.cfg param - use exit call - 3516184 commClose close socket when file hndl is null diff --git a/cimRequest.c b/cimRequest.c index 44da6f5..58a0ac6 100644 --- a/cimRequest.c +++ b/cimRequest.c @@ -527,7 +527,7 @@ genResponses(BinRequestContext * binCtx, struct timeval sv, ev; - if (_sfcb_trace_mask & TRACE_RESPONSETIMING) { + if (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING) { gettimeofday(&sv, NULL); getrusage(RUSAGE_SELF, &us); } @@ -542,7 +542,7 @@ genResponses(BinRequestContext * binCtx, if (binCtx->pDone < binCtx->pCount) rs.segments[6].txt = NULL; #ifdef SFCB_DEBUG - if (_sfcb_trace_mask & TRACE_RESPONSETIMING) { + if (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING) { gettimeofday(&ev, NULL); getrusage(RUSAGE_SELF, &ue); _sfcb_trace(1, __FILE__, __LINE__, @@ -1788,7 +1788,7 @@ handleCimRequest(CimRequestContext * ctx, int flags) 0 = format understood 1 = format not understood */ - if (_sfcb_trace_mask & TRACE_RESPONSETIMING) { + if (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING) { gettimeofday(&sv, NULL); getrusage(RUSAGE_SELF, &us); } @@ -1822,7 +1822,7 @@ handleCimRequest(CimRequestContext * ctx, int flags) hdr.binCtx->rHdr = &hdr; #ifdef SFCB_DEBUG - if (_sfcb_trace_mask & TRACE_RESPONSETIMING) { + if (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING) { gettimeofday(&ev, NULL); getrusage(RUSAGE_SELF, &ue); _sfcb_trace(1, __FILE__, __LINE__, diff --git a/httpAdapter.c b/httpAdapter.c index 188502d..0ea9b4a 100644 --- a/httpAdapter.c +++ b/httpAdapter.c @@ -1186,13 +1186,13 @@ doHttpRequest(CommHndl conn_fd) ctx.sessionId = sessionId; #ifdef SFCB_DEBUG - if ((_sfcb_trace_mask & TRACE_RESPONSETIMING)) { + if ((*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING)) { gettimeofday(&sv, NULL); getrusage(RUSAGE_SELF, &us); uset = 1; } - if ((_sfcb_trace_mask & TRACE_XMLIN)) { + if ((*_ptr_sfcb_trace_mask & TRACE_XMLIN)) { _sfcb_trace(1, __FILE__, __LINE__, _sfcb_format_trace("-#- xmlIn %d bytes:\n%*s", inBuf.content_length, @@ -1224,7 +1224,7 @@ doHttpRequest(CommHndl conn_fd) releaseAuthHandle(); #ifdef SFCB_DEBUG - if (uset && (_sfcb_trace_mask & TRACE_RESPONSETIMING)) { + if (uset && (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING)) { gettimeofday(&ev, NULL); getrusage(RUSAGE_SELF, &ue); _sfcb_trace(1, __FILE__, __LINE__, diff --git a/httpComm.c b/httpComm.c index 64b060e..11dc0cf 100644 --- a/httpComm.c +++ b/httpComm.c @@ -64,7 +64,7 @@ commWrite(CommHndl to, void *data, size_t count) _SFCB_ENTER(TRACE_HTTPDAEMON | TRACE_XMLOUT, "commWrite"); #ifdef SFCB_DEBUG - if ((_sfcb_trace_mask & TRACE_XMLOUT)) { + if ((*_ptr_sfcb_trace_mask & TRACE_XMLOUT)) { char *mp, *m = alloca(count * 2), *d = (char *) data; diff --git a/providerDrv.c b/providerDrv.c index 4a8d4b0..3cc6400 100644 --- a/providerDrv.c +++ b/providerDrv.c @@ -63,7 +63,7 @@ char *opsName[]; struct timeval sv,ev; #define TIMING_START(req,pInfo) \ - if (pInfo && req && (_sfcb_trace_mask & TRACE_RESPONSETIMING) ) {\ + if (pInfo && req && (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING) ) {\ gettimeofday(&sv,NULL);\ getrusage(RUSAGE_SELF,&us);\ getrusage(RUSAGE_CHILDREN,&cs);\ diff --git a/providerMgr.c b/providerMgr.c index 1270a0b..6af92a7 100644 --- a/providerMgr.c +++ b/providerMgr.c @@ -1267,7 +1267,7 @@ intInvokeProvider(BinRequestContext * ctx, ComSockets sockets) struct timeval sv, ev; - if (_sfcb_trace_mask & TRACE_RESPONSETIMING) { + if (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING) { gettimeofday(&sv, NULL); getrusage(RUSAGE_SELF, &us); } @@ -1431,7 +1431,7 @@ intInvokeProvider(BinRequestContext * ctx, ComSockets sockets) releaseHeap(heapCtl); #ifdef SFCB_DEBUG - if (_sfcb_trace_mask & TRACE_RESPONSETIMING) { + if (*_ptr_sfcb_trace_mask & TRACE_RESPONSETIMING) { gettimeofday(&ev, NULL); getrusage(RUSAGE_SELF, &ue); _sfcb_trace(1, __FILE__, __LINE__, diff --git a/sfcBroker.c b/sfcBroker.c index d45c1eb..e4789e7 100644 --- a/sfcBroker.c +++ b/sfcBroker.c @@ -253,6 +253,8 @@ stopBroker(void *p) pthread_mutex_unlock(&syncMtx); + _SFCB_TRACE_STOP(); + if (restartBroker) { char *emsg = strerror(errno); execvp("sfcbd", restartArgv); @@ -750,22 +752,21 @@ main(int argc, char *argv[]) getControlNum("traceMask", &tmask); } - if (tmask) { - if (getControlNum("traceLevel", &tracelevel) || tracelevel == 0) { - /* - * no tracelevel found in config file, use default - */ - tracelevel = 1; - } - if (getenv("SFCB_TRACE_FILE") == NULL && - getControlChars("traceFile", &tracefile) == 0) { - /* - * only set tracefile from config file if not specified via env - */ - _SFCB_TRACE_SETFILE(tracefile); - } - _SFCB_TRACE_START(tracelevel, tmask); + if (getControlNum("traceLevel", &tracelevel) || tracelevel == 0) { + /* + * no tracelevel found in config file, use default + */ + tracelevel = 1; + } + if (getenv("SFCB_TRACE_FILE") == NULL && + getControlChars("traceFile", &tracefile) == 0) { + /* + * only set tracefile from config file if not specified via env + */ + _SFCB_TRACE_SETFILE(tracefile); } + _SFCB_TRACE_START(tracelevel, tmask); + // SFCB_DEBUG #ifndef SFCB_DEBUG if (tmask) diff --git a/sfcb.cfg.pre.in b/sfcb.cfg.pre.in index bd587df..6d116a9 100644 --- a/sfcb.cfg.pre.in +++ b/sfcb.cfg.pre.in @@ -265,6 +265,7 @@ sslCiphers: ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH ## Location of the trace file. ## Can be overriden by setting environment variable SFCB_TRACE_FILE +## The special value "syslog" will send trace to the syslog ## Default is stderr #traceFile: stderr diff --git a/sfcbtrace.c b/sfcbtrace.c new file mode 100644 index 0000000..83e28d9 --- /dev/null +++ b/sfcbtrace.c @@ -0,0 +1,98 @@ + +/* + * + * (C) Copyright IBM Corp. 2012 + * + * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + * + * You can obtain a current copy of the Eclipse Public License from + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * Author: Mike Lisanke <mli...@us...> + * Chris Buccella <buc...@li...> + * + * Description: + * + * Sets the component trace mask for SFCB trace output + * +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <ctype.h> +#include "trace.h" + +int shmkey = 0xdeb001; +extern TraceId traceIds[]; + +void print_help() { + printf( "sfcbtrace - toggle the tracemask for SFCB trace output\n\n"); + printf( "Usage: sfcbtrace <trace_mask> <shm_key>\n"); + printf( "\ttrace_mask - an unsigned long or hex value for component(s) to trace (default=0) \n"); + printf( "\tshm_key - the shared memory ID being used by SFCB (default=%x)\n\n", shmkey); + + printf("Traceable Components: Int Hex\n"); + int i; + for (i = 0; traceIds[i].id; i++) + printf(" %18s: %d\t0x%05X\n", traceIds[i].id, traceIds[i].code, traceIds[i].code); + + return; +} + +int main(int argc, char **argv) { + + int shmid; + unsigned long tmask = 0; + void *vpDP = NULL; + unsigned long *pulDP = NULL; + + if (argc > 3) { + print_help(); + exit(1); + } + + if (argc == 1) { + print_help(); + exit(0); + } + else + tmask = strtoul( argv[1], NULL, 16 ); + + if (argc == 3) { + shmkey = strtoul( argv[2], NULL, 16 ); + } + + if (errno) fprintf(stderr, "errno set\n"); + + if ((shmid = shmget( shmkey, sizeof(unsigned long), 0660 )) < 0) { + if (errno == ENOENT) + printf("No segment for key %x (sfcbd not running?)\n", shmkey); + else if (errno == EACCES) + printf("Permission denied; can't set segment\n"); + else { + printf( "shmget(%x,...) failed in %s at line %d\n", shmkey, __FILE__, __LINE__ ); + print_help(); + } + exit(3); + } + + vpDP = shmat( shmid, NULL, 0 ); + if ( (vpDP == (void*)-1) || (vpDP == NULL) ) { /* shmat returns an error */ + printf( "shmat(%x,) returned %08X with errno = %s(%u) in %s at line %d\n", shmid, (unsigned int)vpDP, strerror(errno), errno, __FILE__, __LINE__ ); + exit(4); + } + + pulDP = (unsigned long *)vpDP; + + *pulDP = tmask; + printf( "debug key %x was set to value %lx\n", shmkey, *pulDP ); + + exit(0); +} diff --git a/trace.c b/trace.c index 55aaae6..145679b 100644 --- a/trace.c +++ b/trace.c @@ -33,6 +33,9 @@ #include <sys/types.h> #include <unistd.h> #include <pthread.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <stdlib.h> #include "config.h" /* @@ -52,7 +55,12 @@ int terminating = 0; int _sfcb_debug = 0; unsigned long _sfcb_trace_mask = 0; +/* use pointer indirect _sfcb_trace_mask to allow shared memory flag */ +unsigned long *_ptr_sfcb_trace_mask = &_sfcb_trace_mask; +void *vpDP = NULL; +int shmid; char *_SFCB_TRACE_FILE = NULL; +int _SFCB_TRACE_TO_SYSLOG = 0; TraceId traceIds[] = { {"providerMgr", TRACE_PROVIDERMGR}, @@ -109,6 +117,7 @@ _sfcb_trace_start(int n) void _sfcb_trace_stop() { + shmctl(shmid, IPC_RMID, 0); _sfcb_debug = 0; } @@ -119,6 +128,25 @@ _sfcb_trace_init() char *var = NULL; char *err = NULL; FILE *ferr = NULL; + int tryid = 0xDEB001; + + while ((shmid = shmget(tryid, sizeof(unsigned long), (IPC_CREAT | 0660))) < 0 && (errno == EEXIST)) tryid++; + mlogf(M_INFO,M_SHOW,"--- Shared memory ID for tracing: %x\n", tryid); + if (shmid < 0) { + mlogf(M_ERROR,M_SHOW, "shmget(%x) failed in %s at line %d.\n", tryid, __FILE__, __LINE__ ); + abort(); + } + else { + vpDP = shmat( shmid, NULL, 0 ); + + if (vpDP == (void*)-1) {// shmat returns an error + mlogf(M_ERROR,M_SHOW, "shmat(%u,) failed with errno = %s(%u) in %s at line %d.\n", shmid, strerror(errno), errno, __FILE__, __LINE__ ); + abort(); + } + else { + _ptr_sfcb_trace_mask = (unsigned long *)vpDP; + } + } var = getenv("SFCB_TRACE"); if (var != NULL) { @@ -183,14 +211,23 @@ _sfcb_trace(int level, char *file, int line, char *msg) strftime(tm, 20, "%m/%d/%Y %H:%M:%S", &cttm); } - if (colorTrace) { - changeTextColor(0); - fprintf(ferr, "[%i] [%s] %d/%p --- %s(%i) : %s\n", level, tm, - currentProc, (void *) pthread_self(), file, line, msg); - changeTextColor(1); - } else { - fprintf(ferr, "[%i] [%s] %d/%p --- %s(%i) : %s\n", level, tm, - currentProc, (void *) pthread_self(), file, line, msg); + if (*_ptr_sfcb_trace_mask) { + if (_SFCB_TRACE_TO_SYSLOG) { + /* ERROR is the default syslog level, if a user does not specify INFO or DEBUG. + ERROR guarantees output will end up in syslog */ + mlogf(M_ERROR,M_SHOW,"[%i] [%s] %d/%p --- %s(%i) : %s\n", level, tm, currentProc, (void *)pthread_self(), file, + line, msg); + } + else if (colorTrace) { + changeTextColor(0); + fprintf(ferr, "[%i] [%s] %d/%p --- %s(%i) : %s\n", level, tm, currentProc, (void *)pthread_self(), file, + line, msg); + changeTextColor(1); + } + else { + fprintf(ferr, "[%i] [%s] %d/%p --- %s(%i) : %s\n", level, tm, currentProc, (void *)pthread_self(), file, + line, msg); + } } free(tm); @@ -201,13 +238,13 @@ _sfcb_trace(int level, char *file, int line, char *msg) if ((_SFCB_TRACE_FILE != NULL)) { fclose(ferr); } - + } -extern void -_sfcb_set_trace_mask(int n) +extern void _sfcb_set_trace_mask(unsigned long n) { - _sfcb_trace_mask = n; + unsigned long *pulDP = (unsigned long*)vpDP; + *pulDP = n; } extern void @@ -216,7 +253,11 @@ _sfcb_set_trace_file(char *file) if (_SFCB_TRACE_FILE) { free(_SFCB_TRACE_FILE); } - if (strcmp(file, "stderr") == 0) { + if (strcmp(file, "syslog") == 0) { + _SFCB_TRACE_FILE = NULL; + _SFCB_TRACE_TO_SYSLOG = 1; + } + else if (strcmp(file,"stderr") == 0) { _SFCB_TRACE_FILE = NULL; } else { _SFCB_TRACE_FILE = strdup(file); diff --git a/trace.h b/trace.h index dc1021a..238a863 100644 --- a/trace.h +++ b/trace.h @@ -25,10 +25,14 @@ #include "mlog.h" +extern unsigned long _sfcb_trace_mask; +/* use pointer indirect _sfcb_trace_mask to allow shared memory flag */ +extern unsigned long *_ptr_sfcb_trace_mask; + #ifdef SFCB_DEBUG #define _SFCB_TRACE(LEVEL,STR) \ - if ((_sfcb_trace_mask & __traceMask) && (LEVEL<=_sfcb_debug) && (LEVEL>0) ) \ + if ((*_ptr_sfcb_trace_mask & __traceMask) && (LEVEL<=_sfcb_debug) && (LEVEL>0) ) \ _sfcb_trace(LEVEL,__FILE__,__LINE__,_sfcb_format_trace STR); #define _SFCB_ENTER(n,f) \ @@ -59,7 +63,7 @@ #define _SFCB_TRACE_FUNCTION(LEVEL,f) \ _SFCB_TRACE(LEVEL,("Invoking trace function %s",#f)); \ - if ((_sfcb_trace_mask & __traceMask) && (LEVEL<=_sfcb_debug) && (LEVEL>0) ) { \ + if ((*_ptr_sfcb_trace_mask & __traceMask) && (LEVEL<=_sfcb_debug) && (LEVEL>0) ) { \ f;} #define _SFCB_ABORT() {\ @@ -70,14 +74,13 @@ _sfcb_trap(n); extern int _sfcb_debug; -extern unsigned long _sfcb_trace_mask; extern char *_sfcb_format_trace(char *fmt, ...); extern void _sfcb_trace(int, char *, int, char *); extern void _sfcb_trace_start(int l); extern void _sfcb_trace_init(); extern void _sfcb_trace_stop(); -extern void _sfcb_set_trace_mask(int n); +extern void _sfcb_set_trace_mask(unsigned long n); extern void _sfcb_set_trace_file(char *file); extern void _sfcb_trap(int n); @@ -98,8 +101,6 @@ extern void _sfcb_trap(int n); #define TRAP(n) #endif -extern void _sfcb_set_trace_mask(int n); - typedef struct traceId { char *id; int code; hooks/post-receive -- SFCB - Small Footprint CIM Broker |