head 1.70; access; symbols FSL_1_7_0:1.70 FSL_1_6_1:1.70 FSL_1_6_0:1.68 FSL_1_6b2:1.68 FSL_1_6b1:1.68 FSL_1_5_0:1.67 FSL_1_5a3:1.67 FSL_1_5a2:1.67 FSL_1_5a1:1.67 FSL_1_4_0:1.66 FSL_1_4b1:1.66 FSL_1_4a1:1.65 FSL_1_3_0:1.61 FSL_1_3b1:1.61 FSL_1_2_1:1.61 FSL_1_2_0:1.61 FSL_1_1_0:1.61 FSL_1_1b1:1.59 FSL_1_0_8:1.56 FSL_1_0_7:1.56 FSL_1_0_6:1.54 FSL_1_0_5:1.52 FSL_1_0_4:1.52 FSL_1_0_3:1.50 FSL_1_0_2:1.50 FSL_1_0_1:1.50 FSL_1_0_0:1.46 FSL_0_9_0:1.45 FSL_0_1_12:1.41 FSL_0_1_11:1.37 FSL_0_1_10:1.37 FSL_0_1_9:1.32 FSL_0_1_8:1.30 FSL_0_1_7:1.29 FSL_0_1_6:1.28 FSL_0_1_5:1.22 FSL_0_1_1:1.16; locks; strict; comment @ * @; 1.70 date 2005.10.03.09.28.53; author rse; state Exp; branches; next 1.69; 1.69 date 2005.10.03.09.25.52; author rse; state Exp; branches; next 1.68; 1.68 date 2005.02.02.12.52.12; author thl; state Exp; branches; next 1.67; 1.67 date 2004.04.22.10.30.31; author thl; state Exp; branches; next 1.66; 1.66 date 2004.01.09.10.48.27; author thl; state Exp; branches; next 1.65; 1.65 date 2003.10.13.14.01.38; author thl; state Exp; branches; next 1.64; 1.64 date 2003.10.13.13.35.51; author thl; state Exp; branches; next 1.63; 1.63 date 2003.10.13.13.18.28; author thl; state Exp; branches; next 1.62; 1.62 date 2003.10.10.14.07.49; author ms; state Exp; branches; next 1.61; 1.61 date 2003.05.22.14.01.55; author thl; state Exp; branches; next 1.60; 1.60 date 2003.05.22.13.48.45; author thl; state Exp; branches; next 1.59; 1.59 date 2003.05.22.13.04.33; author thl; state Exp; branches; next 1.58; 1.58 date 2003.05.22.12.30.35; author thl; state Exp; branches; next 1.57; 1.57 date 2003.05.20.15.47.23; author thl; state Exp; branches; next 1.56; 1.56 date 2003.01.06.16.41.21; author rse; state Exp; branches; next 1.55; 1.55 date 2002.11.12.13.08.59; author thl; state Exp; branches; next 1.54; 1.54 date 2002.11.09.18.25.21; author rse; state Exp; branches; next 1.53; 1.53 date 2002.11.09.14.49.05; author rse; state Exp; branches; next 1.52; 1.52 date 2002.10.21.12.51.23; author thl; state Exp; branches; next 1.51; 1.51 date 2002.10.21.12.45.55; author thl; state Exp; branches; next 1.50; 1.50 date 2002.08.02.11.40.00; author rse; state Exp; branches; next 1.49; 1.49 date 2002.08.02.11.35.55; author rse; state Exp; branches; next 1.48; 1.48 date 2002.08.02.11.00.23; author rse; state Exp; branches; next 1.47; 1.47 date 2002.08.02.10.56.22; author rse; state Exp; branches; next 1.46; 1.46 date 2002.08.01.15.27.01; author thl; state Exp; branches; next 1.45; 1.45 date 2002.08.01.11.41.05; author rse; state Exp; branches; next 1.44; 1.44 date 2002.07.31.13.20.50; author thl; state Exp; branches; next 1.43; 1.43 date 2002.07.31.12.58.03; author thl; state Exp; branches; next 1.42; 1.42 date 2002.07.31.11.39.13; author thl; state Exp; branches; next 1.41; 1.41 date 2002.07.30.12.03.36; author thl; state Exp; branches; next 1.40; 1.40 date 2002.07.30.11.50.00; author thl; state Exp; branches; next 1.39; 1.39 date 2002.07.30.11.37.19; author thl; state Exp; branches; next 1.38; 1.38 date 2002.07.30.10.08.08; author thl; state Exp; branches; next 1.37; 1.37 date 2002.07.29.15.08.21; author thl; state Exp; branches; next 1.36; 1.36 date 2002.07.29.14.42.05; author thl; state Exp; branches; next 1.35; 1.35 date 2002.07.29.13.07.05; author thl; state Exp; branches; next 1.34; 1.34 date 2002.07.29.12.48.43; author thl; state Exp; branches; next 1.33; 1.33 date 2002.07.29.12.48.17; author thl; state Exp; branches; next 1.32; 1.32 date 2002.07.27.15.37.21; author rse; state Exp; branches; next 1.31; 1.31 date 2002.07.27.15.35.23; author rse; state Exp; branches; next 1.30; 1.30 date 2002.07.25.16.28.43; author rse; state Exp; branches; next 1.29; 1.29 date 2002.07.25.15.21.32; author thl; state Exp; branches; next 1.28; 1.28 date 2002.07.25.15.06.51; author rse; state Exp; branches; next 1.27; 1.27 date 2002.07.25.15.02.13; author thl; state Exp; branches; next 1.26; 1.26 date 2002.07.25.15.00.29; author thl; state Exp; branches; next 1.25; 1.25 date 2002.07.25.14.15.54; author thl; state Exp; branches; next 1.24; 1.24 date 2002.07.25.14.14.24; author thl; state Exp; branches; next 1.23; 1.23 date 2002.07.25.14.05.57; author thl; state Exp; branches; next 1.22; 1.22 date 2002.07.25.10.14.03; author rse; state Exp; branches; next 1.21; 1.21 date 2002.07.24.15.29.01; author thl; state Exp; branches; next 1.20; 1.20 date 2002.07.24.09.45.12; author thl; state Exp; branches; next 1.19; 1.19 date 2002.07.24.07.57.04; author thl; state Exp; branches; next 1.18; 1.18 date 2002.07.23.14.37.50; author thl; state Exp; branches; next 1.17; 1.17 date 2002.07.23.12.21.57; author thl; state Exp; branches; next 1.16; 1.16 date 2002.07.19.13.26.51; author rse; state Exp; branches; next 1.15; 1.15 date 2002.07.19.13.26.20; author rse; state Exp; branches; next 1.14; 1.14 date 2002.07.18.15.53.36; author thl; state Exp; branches; next 1.13; 1.13 date 2002.07.18.15.18.30; author thl; state Exp; branches; next 1.12; 1.12 date 2002.07.18.14.07.33; author rse; state Exp; branches; next 1.11; 1.11 date 2002.07.18.11.26.59; author thl; state Exp; branches; next 1.10; 1.10 date 2002.07.17.15.26.36; author thl; state Exp; branches; next 1.9; 1.9 date 2002.07.17.14.28.00; author thl; state Exp; branches; next 1.8; 1.8 date 2002.07.17.09.57.44; author thl; state Exp; branches; next 1.7; 1.7 date 2002.07.16.15.59.44; author thl; state Exp; branches; next 1.6; 1.6 date 2002.07.16.14.59.53; author thl; state Exp; branches; next 1.5; 1.5 date 2002.07.16.13.49.29; author thl; state Exp; branches; next 1.4; 1.4 date 2002.07.16.13.36.26; author thl; state Exp; branches; next 1.3; 1.3 date 2002.07.16.13.20.33; author thl; state Exp; branches; next 1.2; 1.2 date 2002.07.11.15.43.15; author thl; state Exp; branches; next 1.1; 1.1 date 2002.07.09.09.42.09; author rse; state Exp; branches; next ; desc @@ 1.70 log @Adjust copyright messages to include new year 2005. @ text @/* ** OSSP fsl - Faking/Flexible Syslog Library ** Copyright (c) 2002-2005 Ralf S. Engelschall ** Copyright (c) 2002-2005 The OSSP Project ** Copyright (c) 2002-2005 Cable & Wireless ** ** This file is part of OSSP fsl, a syslog(3) API faking library which ** can be found at http://www.ossp.org/pkg/lib/fsl/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** fsl.c: OSSP fsl library */ /* standard includes we use */ #include #include #include #include #include #include #include #include #include #include #include #include /* standard include we re-implement */ #ifdef __hpux #define _XOPEN_SOURCE_EXTENDED #endif #include /* third party (linked in) */ #include "l2.h" #include "cfg.h" #include "pcre.h" /* autoconfiguration */ #include "config.h" /* use l2_ut_[v]sprintf() as a portable [v]snprintf() replacement for debugging */ #ifdef FSL_DEBUGLOGCODE #include "l2_ut_format.h" #endif /* version */ #define _FSL_VERSION_C_AS_HEADER_ #include "fsl_version.c" #undef _FSL_VERSION_C_AS_HEADER_ /* pcre static vector size */ #define OVECSIZE 30 /* maximum atomic write size, maximum log message size */ #define MAXWRITESIZE 512 /* backward compatibility */ #ifndef LOG_PRIMASK #define LOG_PRIMASK (LOG_EMERG|LOG_ALERT|LOG_CRIT|LOG_ERR|\ LOG_WARNING|LOG_NOTICE|LOG_INFO|LOG_DEBUG) #endif #ifndef LOG_PRI #define LOG_PRI(p) ((p) & LOG_PRIMASK) #endif /* cleanup sequence macros */ #define STMT(stuff) do { stuff } while (0) #define CU(returncode) STMT( rc = returncode; goto CUS; ) #define VCU STMT( goto CUS; ) /* general return codes */ typedef enum { FSL_OK = 0, /* everything ok */ FSL_NOIDENT, /* ok but no "ident" directive found or none matched */ FSL_ERR_ARG, /* invalid argument */ FSL_ERR_USE, /* invalid use */ FSL_ERR_MEM, /* no more memory available */ FSL_ERR_SYS, /* operating system error, see errno */ FSL_ERR_CUS, /* error handled and logged, just run clean up sequence and goodbye */ FSL_ERR_INT /* internal error */ } fsl_rc_t; /* file buffer handling sub-API */ typedef struct { char *base; size_t used; size_t size; } buf_t; /* mapping table for syslog(3) facilities to strings */ static struct { int facility; char *string; } syslogfacility2string[] = { { LOG_AUTH, "auth" }, #ifdef LOG_AUTHPRIV { LOG_AUTHPRIV, "authpriv" }, #endif #ifdef LOG_CONSOLE { LOG_CONSOLE, "console" }, #endif { LOG_CRON, "cron" }, { LOG_DAEMON, "daemon" }, #ifdef LOG_FTP { LOG_FTP, "ftp" }, #endif { LOG_KERN, "kern" }, { LOG_LOCAL0, "local0" }, { LOG_LOCAL1, "local1" }, { LOG_LOCAL2, "local2" }, { LOG_LOCAL3, "local3" }, { LOG_LOCAL4, "local4" }, { LOG_LOCAL5, "local5" }, { LOG_LOCAL6, "local6" }, { LOG_LOCAL7, "local7" }, { LOG_LPR, "lpr" }, { LOG_MAIL, "mail" }, { LOG_NEWS, "news" }, #ifdef LOG_NTP { LOG_NTP, "ntp" }, #endif #ifdef LOG_SECURITY { LOG_SECURITY, "security" }, #endif { LOG_SYSLOG, "syslog" }, { LOG_USER, "user" }, { LOG_UUCP, "uucp" }, { -1, NULL } }; /* mapping table for syslog(3) levels/priorities strings/numbers to L2 levels */ static struct { char *string; int level; l2_level_t deflevelmap; } sysloglevel2string[] = { { "emerg", LOG_EMERG, L2_LEVEL_PANIC }, { "alert", LOG_ALERT, L2_LEVEL_PANIC }, { "crit", LOG_CRIT, L2_LEVEL_CRITICAL }, { "err", LOG_ERR, L2_LEVEL_ERROR }, { "warning", LOG_WARNING, L2_LEVEL_WARNING }, { "notice", LOG_NOTICE, L2_LEVEL_NOTICE }, { "info", LOG_INFO, L2_LEVEL_INFO }, { "debug", LOG_DEBUG, L2_LEVEL_DEBUG }, { NULL, -1, -1 } }; /* mapping table for L2 level strings to L2 level numbers */ static struct { char *string; l2_level_t level; } l2level2string[] = { { "none", 0, }, { "panic", L2_LEVEL_PANIC, }, { "critical", L2_LEVEL_CRITICAL, }, { "error", L2_LEVEL_ERROR, }, { "warning", L2_LEVEL_WARNING, }, { "notice", L2_LEVEL_NOTICE, }, { "info", L2_LEVEL_INFO, }, { "trace", L2_LEVEL_TRACE, }, { "debug", L2_LEVEL_DEBUG, }, { NULL, -1 } }; /* type of run-time syslog(3) to L2 level mapping table */ typedef struct { int syslog; l2_level_t l2; } levelmap_t; /* internal global context structure */ static struct { l2_env_t *l2_env; l2_channel_t *l2_nch; char *cpISF; levelmap_t *levelmap; int maskpri; int logopt; int delayopen; int triedopenlog; #ifdef FSL_DEBUGLOGCODE l2_env_t *fsldebug_l2_env; l2_channel_t *fsldebug_l2_nch; int fsldebug_transientproblem; int fsldebug_permanentproblem; #endif /* ifdef FSL_DEBUGLOGCODE */ char *fsl_config; } ctx = { NULL, NULL, NULL, NULL, LOG_UPTO(LOG_DEBUG), 0, TRUE, FALSE, #ifdef FSL_DEBUGLOGCODE NULL, NULL, FALSE, FALSE, #endif /* ifdef FSL_DEBUGLOGCODE */ "@@(#)OSSP fsl config " "cfgdir=" FSL_CFGDIR " " "prefix=" FSL_PREFIX "\n" "@@(#)OSSP fsl debug " #ifdef FSL_DEBUGLOGCODE "logfile=" FSL_DEBUGLOGFILE " " "logmask=" FSL_DEBUGLOGMASK #else /* ifdef FSL_DEBUGLOGCODE */ "code omitted" #endif /* ifdef FSL_DEBUGLOGCODE */ "\n" }; #ifdef FSL_DEBUGLOGCODE static void vfsldebug(l2_level_t level, const char *message, va_list ap) { /* sizing cp temporary buffer is max out of strlen "(panic,critical,error,warning,notice,info,trace,debug)" + terminating NUL and strlen "bbb dd HH:MM:SS " + terminating NUL = 56 */ static char cp[56]; static char cpo[MAXWRITESIZE]; int cpn; int n; struct stat sb; unsigned int levelmask; time_t t; struct tm *tm; int fd = 0; /* determine level mask */ if ((n = readlink(FSL_DEBUGLOGMASK, cp, sizeof(cp))) == -1) VCU; if (cp[0] == '(' && cp[n-1] == ')') { /* level mask in round brackets like l2spec */ if(l2_util_s2l(&cp[1], n-2, ',', &levelmask) != L2_OK) VCU; } else if (strchr(cp, ',') != NULL) { /* level mask automatic because comma detected */ if(l2_util_s2l(&cp[0], n , ',', &levelmask) != L2_OK) VCU; } else { /* upto level like l2spec */ if(l2_util_s2l(&cp[0], n , 0 , &levelmask) != L2_OK) VCU; levelmask = L2_LEVEL_UPTO(levelmask); } if (level & levelmask) { cpn = 0; /* date and time */ t = time(NULL); tm = localtime(&t); if ((n = strftime(cp, sizeof(cp), "%b %d %H:%M:%S ", tm)) == 0) VCU; l2_util_sprintf( &cpo[cpn], MAXWRITESIZE-cpn, "%s", cp); cpn = strlen(cpo); /* level */ l2_util_sprintf( &cpo[cpn], MAXWRITESIZE-cpn, "<%s> ", l2_util_l2s(cp, sizeof(cp), '\0', level) == L2_OK ? cp : "unknown"); cpn = strlen(cpo); /* program "name" and pid */ l2_util_sprintf( &cpo[cpn], MAXWRITESIZE-cpn, "%s[%lu^%lu] ", ctx.cpISF != NULL ? ctx.cpISF : "unknown", (unsigned long)getpid(), (unsigned long)getppid()); cpn = strlen(cpo); /* message */ l2_util_vsprintf(&cpo[cpn], MAXWRITESIZE-cpn, message, ap); cpn = strlen(cpo); l2_util_sprintf( &cpo[cpn], MAXWRITESIZE-cpn, "\n"); cpn = strlen(cpo); /* write the log */ if (cpn >= 1) { if ((fd = open(FSL_DEBUGLOGFILE, O_WRONLY|O_CREAT|O_APPEND|O_NONBLOCK, 0644)) == -1) VCU; if (fstat(fd, &sb) == -1) VCU; if (sb.st_size >= FSL_DEBUGLOGSTOP) VCU; write(fd, cpo, cpn); } } CUS: if (fd) (void)close(fd); } static void fsldebug(l2_level_t level, const char *message, ...) { va_list ap; va_start(ap, message); vfsldebug(level, message, ap); va_end(ap); return; } #else /* ifdef FSL_DEBUGLOGCODE */ static void fsldebug(l2_level_t level, const char *message, ...) { return; } #endif /* ifdef FSL_DEBUGLOGCODE */ /* append contents of a file to buffer */ static fsl_rc_t appendfiletobuffer(buf_t *buffer, const char *filename) { fsl_rc_t rc; int fd = -1; int filesize; int fileread; int bufferneed; if (filename == NULL || buffer == NULL) CU(FSL_ERR_ARG); fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer() filename=\"%s\"", filename); if ((fd = open(filename, O_RDONLY)) == -1) CU(FSL_ERR_SYS); if ((filesize = (int)lseek(fd, 0, SEEK_END)) == -1) CU(FSL_ERR_SYS); bufferneed = buffer->used + filesize; if (bufferneed > buffer->size) { if (buffer->base == NULL) { if ((buffer->base = (char *)malloc(bufferneed)) == NULL) CU(FSL_ERR_MEM); buffer->size = bufferneed; buffer->used = 0; } else { if ((buffer->base = (char *)realloc(buffer->base, bufferneed)) == NULL) CU(FSL_ERR_MEM); buffer->size = bufferneed; } } if (lseek(fd, 0, SEEK_SET) == -1) CU(FSL_ERR_SYS); if ((fileread = (int)read(fd, buffer->base + buffer->used, (size_t)filesize)) == -1) CU(FSL_ERR_SYS); if (fileread != filesize) CU(FSL_ERR_USE); buffer->used += filesize; CU(FSL_OK); CUS: if (fd != -1) close(fd); return rc; } /* alphabetically compare two filenames, use with qsort(3) */ static int fnamecmp(const void *str1, const void *str2) { const char *s1 = *(const char **)str1; const char *s2 = *(const char **)str2; if ((s1 != NULL) && (s2 != NULL)) return strcmp(s1, s2); /* this must never happen but be prepared for the impossible */ if ((s1 != NULL) && (s2 == NULL)) return strcmp(s1, ""); if ((s1 == NULL) && (s2 != NULL)) return strcmp("", s2); return strcmp("", ""); } /* read all possible files "fsl.*" into buffer */ static fsl_rc_t readallfiles(buf_t *buffer) { fsl_rc_t rc; DIR *dp = NULL; struct dirent *de; char *cfgdir; char *prefix; char **filearr = NULL; size_t filemem = 0; int filecnt = 0; int fileidx = 0; int n = 0; if (buffer == NULL) CU(FSL_ERR_ARG); cfgdir = FSL_CFGDIR; prefix = FSL_PREFIX; fsldebug(L2_LEVEL_TRACE, "readallfiles() globbing \"%s/%s*\"", cfgdir, prefix); if ((dp = opendir(cfgdir)) == NULL) CU(FSL_ERR_SYS); rc = FSL_ERR_ARG; while ((de = readdir(dp)) != NULL) { if ( (strlen(de->d_name) >= strlen(prefix)) && (strncmp(de->d_name, prefix, strlen(prefix)) == 0)) { /* prepare to insert a new file string, so make room for one more */ if ((filearr = (char **)realloc(filearr, filemem + sizeof(char *))) == NULL) CU(FSL_ERR_MEM); else filemem += sizeof(char *); /* allocate for actual filename string from dirent and copy out */ n = strlen(cfgdir) + strlen("/") + strlen(de->d_name) + 1; if ((filearr[filecnt] = (char *)malloc(n)) == NULL) CU(FSL_ERR_MEM); *filearr[filecnt] = '\0'; strcat(filearr[filecnt], cfgdir); strcat(filearr[filecnt], "/"); strcat(filearr[filecnt], de->d_name); filecnt++; } } qsort((void *)filearr, (size_t)filecnt, sizeof(char *), fnamecmp); for (fileidx = 0; fileidx < filecnt; fileidx++) if (appendfiletobuffer(buffer, filearr[fileidx]) == FSL_OK) rc = FSL_OK; CU(rc); CUS: if (dp != NULL) closedir(dp); if (filearr != NULL) { for (fileidx = 0; fileidx < filecnt; fileidx++) free(filearr[fileidx]); free(filearr); } return rc; } /* OSSP cfg node tree traversal function (recursive) */ static void traverse(cfg_t *cfg, cfg_node_t *cfgnode) { int rc; cfg_node_t *cfgchld; cfg_rc_t cfgrv; cfg_node_type_t cfgtyp; char *cp; int cfgchilds; while (cfgnode != NULL) { if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_TOKEN, &cp)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed: %s (%d)", cp, cfgrv); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_TYPE, &cfgtyp)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_TYPE) failed: %s (%d)", cp, cfgrv); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_CHILDS, &cfgchilds)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed: %s (%d)", cp, cfgrv); CU(1); } fsldebug(L2_LEVEL_DEBUG, "traverse: cfgnode=0x%.8lx[%d], cp=\"%s\", type=%d", (unsigned long)cfgnode, cfgchilds, (cp != NULL ? cp : ""), cfgtyp); if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_CHILD1, &cfgchld)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed: %s (%d)", cp, cfgrv); CU(1); } if (cfgchld != NULL) traverse(cfg, cfgchld); if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_RBROTH, &cfgnode)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed: %s (%d)", cp, cfgrv); CU(1); } } CU(0); CUS: return; } /* Substitute $[0-9] in inbuf[inlen] with captured strings passed through capary[nary]. * Returns the number of characters (to be) written to output. Output can be suppressed * by passing a NULL outpbuf. The terminating NUL is not counted but will be written! */ static int substcapture(const char *inbuf, int inlen, const char **capary, int nary, char *outbuf) { int i; /* input cursor, current position */ int n; /* outbuf cursor, next possible write position */ int m; /* index to capary */ char c; /* scratch variable */ i = 0; n = 0; while (i < inlen - 1 /* last char cannot start a two-character sequence, skipping it allows safe look ahead */) { c = inbuf[i]; if (c == '$') { c = inbuf[i+1]; if (c == '$') { if (outbuf != NULL) outbuf[n] = '$'; i += 2; n++; } else if ((c >= '0') && (c <= '9')) { m = c - '0'; if (outbuf != NULL) { outbuf[n] = '\0'; strcat(&outbuf[n], ((m < nary) && (capary[m] != NULL)) ? capary[m] : ""); } i += 2; n += ((m < nary) && (capary[m] != NULL)) ? strlen(capary[m]) : 0; } else { if (outbuf != NULL) outbuf[n] = '$'; i++; n++; if (outbuf != NULL) outbuf[n] = c; i++; n++; } } else { if (outbuf != NULL) outbuf[n] = c; i++; n++; } } if (outbuf != NULL) outbuf[n] = '\0'; return n; } /* process OSSP cfg node tree directives mode=0 processes map/ident, mode=1 processes default */ static fsl_rc_t processcfg(cfg_t *cfg, char *cpISF, int mode) { fsl_rc_t rc; cfg_rc_t cfgrv; cfg_node_t *cfgseq; cfg_node_t *cfgdir; cfg_node_t *cfgarg; cfg_node_type_t cfgtype; int cfgnumc; int cfgnume; char *cfgargtoka[3]; char *cfgargtok; char *argident; char *argmatch; char *argl2spec; char *cp; /* scratch variable */ int i; /* scratch variable */ int n; /* scratch variable */ int ovec[OVECSIZE]; const char **acpMatch; l2_channel_t *ch; /* scratch variable */ l2_result_t l2rv; int matchcount = 0; pcre *pcreRegex = NULL; const char *cpError; int iError; int nMatch; if ((cfg == NULL) || (cpISF == NULL) || (strlen(cpISF) < 3) || (mode < 0) || (mode > 1)) return FSL_ERR_ARG; fsldebug(L2_LEVEL_TRACE, "processcfg() ident/facility=\"%s\", mode=%s", cpISF, mode == 0 ? "map/ident" : "default"); /* find configuration root node and check if it is a sequence and has one or more directives below it */ if ((cfgrv = cfg_node_root(cfg, NULL, &cfgseq)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_root() failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } /* only dump once */ if (mode == 0) traverse(cfg, cfgseq); if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgtype != CFG_NODE_TYPE_SEQ) { fsldebug(L2_LEVEL_ERROR, "processcfg: expected sequence"); CU(FSL_ERR_CUS); } if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgnumc < 1) { fsldebug(L2_LEVEL_ERROR, "processcfg: sequence is missing directives, expected 1, got %d", cfgnumc); CU(FSL_ERR_CUS); } /* get first directive below sequence */ if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILD1, &cfgdir)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } while (cfgdir != NULL) { /* check if operating on a directive */ if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgtype != CFG_NODE_TYPE_DIR) { fsldebug(L2_LEVEL_ERROR, "processcfg: expected directive"); CU(FSL_ERR_CUS); } if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } /* process first child of directive, check if it is an argument and has a valid token attached */ if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILD1, &cfgarg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgarg == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: first argument is NULL"); CU(FSL_ERR_CUS); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgtype != CFG_NODE_TYPE_ARG) { fsldebug(L2_LEVEL_ERROR, "processcfg: expected first argument, got %d", cfgtype); CU(FSL_ERR_CUS); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgargtok == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: first argument has NULL data"); CU(FSL_ERR_CUS); } cfgargtoka[0] = cfgargtok; cfgnume = 0; if (strcmp(cfgargtoka[0], "ident") == 0) cfgnume = 3; if (strcmp(cfgargtoka[0], "default") == 0) cfgnume = 3; if (strcmp(cfgargtoka[0], "map") == 0) cfgnume = 3; if (cfgnume == 0) { fsldebug(L2_LEVEL_ERROR, "processcfg: syntax error, invalid argument \"%s\"", cfgargtoka[0]); CU(FSL_ERR_CUS); } if (cfgnume != cfgnumc) { fsldebug(L2_LEVEL_ERROR, "processcfg: invalid number of arguments for directive, expected %d, got %d", cfgnume, cfgnumc); CU(FSL_ERR_CUS); } for (i = 1; i < cfgnume; i++) { /* process right brother of argument, check if it is an argument and has a valid token attached */ if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_RBROTH, &cfgarg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgarg == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: argument %d is NULL", i); CU(FSL_ERR_CUS); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgtype != CFG_NODE_TYPE_ARG) { fsldebug(L2_LEVEL_ERROR, "processcfg: expected argument %d", i); CU(FSL_ERR_CUS); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } if (cfgargtok == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: argument %d has NULL data", i); CU(FSL_ERR_CUS); } cfgargtoka[i] = cfgargtok; } if ((strcmp(cfgargtoka[0], "ident") == 0) || (strcmp(cfgargtoka[0], "default") == 0)) { argident = cfgargtoka[0]; argmatch = cfgargtoka[1]; argl2spec = cfgargtoka[2]; if ( ((mode == 0) && (strcmp(cfgargtoka[0], "ident") == 0)) || ((mode == 1) && (strcmp(cfgargtoka[0], "default") == 0)) ) { /* process the directive using the three arguments found */ fsldebug(L2_LEVEL_DEBUG, "processcfg: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec); /* compile regular expression into finite state machine and optimize */ if ((pcreRegex = pcre_compile(argmatch, PCRE_ANCHORED|PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_compile() failed with error %s (%d)", cpError, iError); CU(FSL_ERR_CUS); } nMatch = pcre_exec(pcreRegex, NULL, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE); if (nMatch < 0) fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" failed.", cpISF, argmatch); else if (nMatch == 0) fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0", cpISF, argmatch); else fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1)); if (nMatch >= 1) { pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch); if (acpMatch != NULL) for (i = 0; i < nMatch; i++) fsldebug(L2_LEVEL_DEBUG, "processcfg: regex reference[%d]=\'%s\'", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]); n = substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, NULL); if ((cp = (char *)malloc(n + 1)) == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: malloc() failed"); CU(FSL_ERR_CUS); } if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) { fsldebug(L2_LEVEL_ERROR, "processcfg: substcapture() failed"); CU(FSL_ERR_CUS); } argl2spec = cp; fsldebug(L2_LEVEL_DEBUG, "processcfg: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec); /* create L2 channel throuh spec and link into root channel */ if ((l2rv = l2_spec(&ch, ctx.l2_env, "%s", argl2spec)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to create stream from spec %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); } if ((l2rv = l2_channel_link(ctx.l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to link child channel %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); } matchcount++; free(argl2spec); } if (pcreRegex != NULL) { pcre_free(pcreRegex); pcreRegex = NULL; } } else fsldebug(L2_LEVEL_DEBUG, "processcfg: ignoring %s in mode %d", cfgargtoka[0], mode); } else if (strcmp(cfgargtoka[0], "map") == 0) { if (mode == 0) { int mapfrom; int mapto; for (i = 0, mapfrom = -1; (mapfrom == -1) && (sysloglevel2string[i].string != NULL); i++) { if (strcmp(sysloglevel2string[i].string, cfgargtoka[1]) == 0) mapfrom = i; } if (mapfrom == -1) { fsldebug(L2_LEVEL_ERROR, "processcfg: trying to map from unknown syslog level \"%s\"", cfgargtoka[1]); CU(FSL_ERR_CUS); } for (i = 0, mapto = -1; (mapto == -1) && (l2level2string[i].string != NULL); i++) { if (strcmp(l2level2string[i].string, cfgargtoka[2]) == 0) mapto = i; } if (mapto == -1) { fsldebug(L2_LEVEL_ERROR, "processcfg: trying to map to unknown l2 level \"%s\"", cfgargtoka[2]); CU(FSL_ERR_CUS); } ctx.levelmap[mapfrom].l2 = l2level2string[mapto].level; fsldebug(L2_LEVEL_DEBUG, "processcfg: map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level); } else fsldebug(L2_LEVEL_DEBUG, "processcfg: ignoring %s in mode %d", cfgargtoka[0], mode); } else { fsldebug(L2_LEVEL_ERROR, "processcfg: internal, argument \"%s\" not implemented", cfgargtoka[0]); CU(FSL_ERR_CUS); } /* get right brother of current directive */ if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_RBROTH, &cfgdir)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "processcfg: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } } fsldebug(L2_LEVEL_TRACE, "processcfg: matched %d sections while looking for %s sections", matchcount, mode == 0 ? "ident" : "default"); if (matchcount == 0) CU(FSL_NOIDENT); else CU(FSL_OK); CUS: if (pcreRegex != NULL) { pcre_free(pcreRegex); pcreRegex = NULL; } return rc; } /* POSIX API function openlog(3) */ void openlog(const char *ident, int logopt, int facility) { int rc; buf_t buf; fsl_rc_t rv; cfg_t *cfg; cfg_rc_t cfgrv; char *cp; /* scratch variable */ int i; /* scratch variable */ char *cpIdent; char *cpFacility; l2_result_t l2rv; /* initialization */ cfg = NULL; buf.base = NULL; buf.used = 0; buf.size = 0; cpIdent = NULL; /* properly prepare for repeated execution */ closelog(); ctx.triedopenlog = TRUE; /* remember logopt */ ctx.logopt = logopt; /* handle delayed open logopt value */ if (ctx.logopt & LOG_NDELAY) ctx.delayopen = FALSE; /* tracing */ fsldebug(L2_LEVEL_TRACE, "fsl in openlog(3) ident=%s%s%s, logopt=0x%.8lx, facility=0x%.8lx; caught by %s", ident == NULL ? "" : "\"", ident == NULL ? "NULL" : ident, ident == NULL ? "" : "\"" , logopt, facility, fsl_version.v_gnu); /* handle unsupported logopt values */ if (ctx.logopt & LOG_CONS) fsldebug(L2_LEVEL_WARNING, "openlog: ignore unsupported LOG_CONS"); #ifdef LOG_PERROR if (ctx.logopt & LOG_PERROR) fsldebug(L2_LEVEL_WARNING, "openlog: ignore unsupported LOG_PERROR (use OSSP l2 channel \"fd(filedescriptor=2)\" to emulate)"); #endif if (ctx.logopt & LOG_PID) fsldebug(L2_LEVEL_WARNING, "openlog: ignore unsupported LOG_PID (use OSSP l2 formatter %%P in prefix channel to emulate)"); /* create default sysloglevel to l2_level mapping */ fsldebug(L2_LEVEL_DEBUG, "openlog: create default syslog(3) to OSSP l2 level/priority mapping table"); for (i = 0; sysloglevel2string[i].string != NULL; i++) ; if ((ctx.levelmap = (levelmap_t *)malloc(i * sizeof(levelmap_t))) == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed"); CU(1); } for (i = 0; sysloglevel2string[i].string != NULL; i++) { ctx.levelmap[i].syslog = sysloglevel2string[i].level; ctx.levelmap[i].l2 = sysloglevel2string[i].deflevelmap; fsldebug(L2_LEVEL_DEBUG, "openlog: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); } /* create OSSP l2 environment for main application */ if ((l2rv = l2_env_create(&ctx.l2_env)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create OSSP l2 environment: (%d)", l2rv); CU(1); } if ((l2rv = l2_env_levels(ctx.l2_env, L2_LEVEL_ALL, L2_LEVEL_NONE)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults: %s(%d)", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(ctx.l2_env, 'D', l2_util_fmt_dump, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter: %s(%d)", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(ctx.l2_env, 'S', l2_util_fmt_string, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter: %s(%d)", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(ctx.l2_env, 'm', l2_util_fmt_errno, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter: %s(%d)", cp, l2rv); CU(1); } if ((l2rv = l2_channel_create(&ctx.l2_nch, ctx.l2_env, "noop")) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel: %s(%d)", cp, l2rv); CU(1); } /* create IdentSlashFacility */ if ((cpIdent = strdup((ident != NULL) ? ident : "unknown")) == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: strdup() failed"); CU(1); } cpFacility = "unknown"; for (i = 0; syslogfacility2string[i].string != NULL; i++) { if (facility == syslogfacility2string[i].facility) { cpFacility = syslogfacility2string[i].string; break; } } if ((ctx.cpISF = (char *)malloc(strlen(cpIdent) + 1 + strlen(cpFacility) + 1)) == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed"); CU(1); } ctx.cpISF[0] = '\0'; strcat(ctx.cpISF, cpIdent); strcat(ctx.cpISF, "/"); strcat(ctx.cpISF, cpFacility); /* read configuration file(s) into buffer */ if ((rv = readallfiles(&buf)) != FSL_OK) { fsldebug(L2_LEVEL_ERROR, "openlog: readallfiles() failed. Hint: last system error was \"%s\"(%d)", strerror(errno), errno); CU(1); } /* import configuration buffer into OSSP cfg node tree */ if ((cfgrv = cfg_create(&cfg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_create() failed with error %s (%d)", cp, cfgrv); CU(1); } if ((cfgrv = cfg_import(cfg, NULL, CFG_FMT_CFG, buf.base, buf.size)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_import() failed with error %s (%d)", cp, cfgrv); CU(1); } /* process OSSP cfg node tree "map" and "ident" directives */ if ((rv = processcfg(cfg, ctx.cpISF, 0)) != FSL_OK && (rv != FSL_NOIDENT)) { fsldebug(L2_LEVEL_ERROR, "openlog: processcfg() failed with an unrecoverable error (%d)", rv); CU(1); } /* optionally process OSSP cfg node tree "default" directives */ if ((rv == FSL_NOIDENT) && ((rv = processcfg(cfg, ctx.cpISF, 1)) != FSL_OK)) { fsldebug(L2_LEVEL_ERROR, "openlog: processcfg() failed with an unrecoverable error (%d)", rv); CU(1); } /* open logging now or prepare for delayed open */ if (~logopt & LOG_NDELAY) { fsldebug(L2_LEVEL_TRACE, "openlog: logopt LOG_NDELAY delays open of L2 channel tree until first message is being logged"); } else { if ((l2rv = l2_channel_open(ctx.l2_nch)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) immediately", cp, l2rv); CU(1); } fsldebug(L2_LEVEL_TRACE, "openlog: logging succeeded to open channel stream immediately"); } CU(0); CUS: if (ctx.cpISF != NULL) { free(ctx.cpISF); ctx.cpISF = NULL; } if (cpIdent != NULL) free(cpIdent); if (cfg != NULL) if ((cfgrv = cfg_destroy(cfg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_destroy() failed with error %s (%d)", cp, cfgrv); CU(1); } if (buf.base != NULL) free(buf.base); if (rc != 0) closelog(); return; } /* faked POSIX API function closelog(3) */ void closelog(void) { /* tracing */ fsldebug(L2_LEVEL_TRACE, "fsl in closelog(3)"); if (ctx.l2_nch != NULL) { l2_channel_destroy(ctx.l2_nch); ctx.l2_nch = NULL; } if (ctx.l2_env != NULL) { l2_env_destroy(ctx.l2_env); ctx.l2_env = NULL; } if (ctx.levelmap != NULL) { free(ctx.levelmap); ctx.levelmap = NULL; } if (ctx.cpISF != NULL) { free(ctx.cpISF); ctx.cpISF = NULL; } ctx.maskpri = LOG_UPTO(LOG_DEBUG); ctx.logopt = 0; ctx.delayopen = TRUE; ctx.triedopenlog = FALSE; return; } /* faked POSIX API function setlogmask(3) */ int setlogmask(int maskpri) { int oldmask; /* tracing */ fsldebug(L2_LEVEL_TRACE, "fsl in setlogmask(3) maskpri=0x%.8lx", maskpri); oldmask = ctx.maskpri; if (maskpri != 0) ctx.maskpri = maskpri; return oldmask; } /* faked POSIX API function vsyslog(3) */ #ifdef HAVE_VSYSLOG_USVALIST void vsyslog(int priority, const char *fmt, __va_list args) #else void vsyslog(int priority, const char *fmt, va_list args) #endif { unsigned int levelmask; int i; l2_result_t l2rv; char *cp; /* tracing */ fsldebug(L2_LEVEL_TRACE, "fsl in vsyslog(3) fmt=%s%s%s ...", fmt == NULL ? "" : "\"", fmt == NULL ? "NULL" : fmt, fmt == NULL ? "" : "\""); /* check for omitted openlog(3) */ if (ctx.l2_nch == NULL && !ctx.triedopenlog) openlog("fsl", 0, LOG_SYSLOG); /* check for previous proper initialization */ if (ctx.l2_nch == NULL) return; /* check for delayed open */ if ((~ctx.logopt & LOG_NDELAY) && (ctx.delayopen == TRUE)) { if ((l2rv = l2_channel_open(ctx.l2_nch)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "vsyslog: logging failed to open channel stream %s(%d) delayed", cp, l2rv); closelog(); return; } fsldebug(L2_LEVEL_TRACE, "vsyslog: logging succeeded to open channel stream delayed"); ctx.delayopen = FALSE; } /* strip off facility */ priority &= LOG_PRIMASK; fsldebug(L2_LEVEL_DEBUG, "vsyslog: priority=0x%.8lx, ctx.maskpri=0x%.8lx ", (unsigned long)priority, (unsigned long)ctx.maskpri); /* check against maskpri */ if ((LOG_MASK(priority) & ctx.maskpri) == 0) { fsldebug(L2_LEVEL_DEBUG, "vsyslog: short circuit maskpri"); return; } levelmask = 0; for (i = 0; sysloglevel2string[i].string != NULL; i++) { fsldebug(L2_LEVEL_DEBUG, "vsyslog: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); if (ctx.levelmap[i].syslog == priority) { levelmask = ctx.levelmap[i].l2; break; } } fsldebug(L2_LEVEL_DEBUG, "vsyslog: levelmask=0x%.8lx", (unsigned long)levelmask); /* the heart of FSL */ if ((l2rv = l2_channel_vlog(ctx.l2_nch, levelmask, fmt, args)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_PANIC, "vsyslog: application logging failed: %s (%d)", cp, l2rv); } return; } /* faked POSIX API function syslog(3) */ void syslog(int priority, const char *message, ...) { va_list args; /* tracing */ fsldebug(L2_LEVEL_TRACE, "fsl in syslog(3); go ahead using vsyslog(3)"); /* wrap around vsyslog(3) */ va_start(args, message); vsyslog(priority, message, args); va_end(args); return; } @ 1.69 log @flush pending changes @ text @d3 3 a5 3 ** Copyright (c) 2002-2004 Ralf S. Engelschall ** Copyright (c) 2002-2004 The OSSP Project ** Copyright (c) 2002-2004 Cable & Wireless Deutschland @ 1.68 log @Introduce a new %checkout target to devtool.conf @ text @d46 3 @ 1.67 log @relocate vsyslog() function to avoid wrong implicit declaration. Reported by Karl Vogel @ text @d581 1 a581 1 if ((cfgrv = cfg_node_root(cfg, &cfgseq)) != CFG_OK) { @ 1.66 log @Adjust copyright messages to include new year 2004 @ text @a929 15 /* faked POSIX API function syslog(3) */ void syslog(int priority, const char *message, ...) { va_list args; /* tracing */ fsldebug(L2_LEVEL_TRACE, "fsl in syslog(3); go ahead using vsyslog(3)"); /* wrap around vsyslog(3) */ va_start(args, message); vsyslog(priority, message, args); va_end(args); return; } d989 15 @ 1.65 log @improve readability, find and fix str1 == NULL bug @ text @d3 3 a5 3 ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 The OSSP Project ** Copyright (c) 2002-2003 Cable & Wireless Deutschland @ 1.64 log @remove unused filename; revamp while() into for() and repeat for cleanup sequence @ text @d377 5 a381 2 if ((*(const char **)str1 != NULL) && (*(const char **)str2 != NULL)) return strcmp(*(const char **)str1, *(const char **)str2); d385 2 a386 2 if ((*(const char **)str1 != NULL) && (*(const char **)str2 == NULL)) return strcmp(*(const char **)str1, ""); d388 2 a389 2 if ((*(const char **)str1 == NULL) && (*(const char **)str2 != NULL)) return strcmp("", *(const char **)str1); @ 1.63 log @make fnamecmp() more self-explanatory @ text @a396 1 char *filename = NULL; d439 1 a439 1 while (fileidx < filecnt) { /* loop once for every string in sorted array */ a441 4 free(filearr[fileidx]); filearr[fileidx] = NULL; fileidx++; } d446 5 a450 2 if (filename != NULL) free(filename); @ 1.62 log @Sort valid fsl filenames before adding their contents to the buffer. This mostly fixes the problem of the 'drifting' fsl configuration, by ensuring that l2 sections from filenames with a postfix are placed last in the identifier matching logic. @ text @d374 1 a374 1 /* alphabetically compare one string with another, to use with qsort(3) */ d377 12 a388 13 /* because the end goal is to sort an array of strings in alphabetical */ /* decending order, tailor the bahaviour of this compare method to */ /* account for null strings that should go at the end of the array */ if (*(const char **)str1) { if (*(const char **)str2) return strcmp(*(const char **)str1, *(const char **)str2); else return (-1); /* only str2 was null, so str1 is lesser by default */ } else if (*(const char **)str2) return (1); /* only str1 was null, so str2 is lesser by default */ else return (0); /* both str1 and str2 were null, so they are equal */ @ 1.61 log @whitespaces @ text @d374 18 d401 5 a405 1 int n; d420 1 a420 2 n = strlen(de->d_name); if ( (n >= strlen(prefix)) d422 10 a431 1 if ((filename = (char *)malloc(strlen(cfgdir) + 1 + n + 1)) == NULL) d433 5 a437 8 filename[0] = '\0'; strcat(filename, cfgdir); strcat(filename, "/"); strcat(filename, de->d_name); if (appendfiletobuffer(buffer, filename) == FSL_OK) rc = FSL_OK; free(filename); filename = NULL; d439 8 @ 1.60 log @approved by make-up artist @ text @d203 1 a203 1 } ctx = { d220 1 a220 1 "prefix=" FSL_PREFIX d225 1 a225 1 "logmask=" FSL_DEBUGLOGMASK d282 1 a282 1 d507 1 a507 1 /* process OSSP cfg node tree directives d688 1 a688 1 d770 1 a770 1 fsldebug(L2_LEVEL_DEBUG, "openlog: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx", d921 1 a921 1 @ 1.59 log @what(1) gets confused by double quotes so do not use them @ text @d240 1 a240 1 static char cp[56]; /* FIXME */ @ 1.58 log @for details see attached ChangeLog @ text @d219 2 a220 2 "cfgdir=\"" FSL_CFGDIR "\"" " " "prefix=\"" FSL_PREFIX "\"" d224 2 a225 2 "logfile=\"" FSL_DEBUGLOGFILE "\"" " " "logmask=\"" FSL_DEBUGLOGMASK "\"" d227 1 a227 1 "code omitted;" @ 1.57 log @- improve prefixing by renaming variables l2_fslenv > fsldebug_l2_env l2_fslnch > fsldebug_l2_nch triedopenfsldebug > fsldebug_transientproblem openfsldebugpermanenterror > fsldebug_permanentproblem - add function fsldebugcreate() - rename functions and slightly change their operation to work in a stealth mode for LOG_NDELAY support openfsldebug() > fsl closefsllog() > fsldebugdestroy() - make fsldebug() a metafunction and split the old functionality into fsldebugl2() for l2 and fsldebugf2() for stderr filedescriptor - improve prefixing by adding debugging prototypes to support fsldebug() calling fsldebugcreate() which uses fsldebug() for logging static void fsldebugcreate (void); static void fsldebug (l2_level_t, const char *, ...); static int fsldebugl2 (l2_level_t, const char *, va_list); static int fsldebugf2 (l2_level_t, const char *, va_list); static void fsldebugdestroy(void); - change default for delayopen to TRUE as user has to use LOG_NDELAY to force immediate open. - improve handling of NULL strings when debugging - unify debugging messages on entry to captured functions using common prefix 'fsl in ...' - obey LOG_NDELAY on fsl debugging as well - add filedescriptor consumption checks to test suite - remove confusing use of the word "error" in test suite messages - improve Makefile to prepare and detect empty files - tested on FreeBSD, Linux and Solaris - not intended for release - further modifications are underway @ text @d56 5 d69 3 d190 1 d196 1 a196 1 /* fsl debugging */ d201 2 d207 1 d212 1 a212 1 /* fsl debugging */ d216 14 a229 1 FALSE d232 2 a233 9 /* internal debugging prototypes */ static void fsldebugcreate (void); static void fsldebug (l2_level_t, const char *, ...); static int fsldebugl2 (l2_level_t, const char *, va_list); static int fsldebugf2 (l2_level_t, const char *, va_list); static void fsldebugdestroy(void); /* internal debugging functions */ static void fsldebugcreate() d235 67 a301 40 int rc = FSL_OK; char *argl2spec; l2_result_t l2rv; char *cp; /* scratch variable */ l2_channel_t *ch; /* scratch variable */ /* identify previous fault and avoid repetition */ if (ctx.fsldebug_permanentproblem || ctx.fsldebug_transientproblem) return; /* create OSSP l2 environment for fsl itself (internal logging) */ if ((argl2spec = getenv("FSL_DEBUG")) == NULL) argl2spec = FSL_DEBUG; if (strlen(argl2spec) > 0) { if ((l2rv = l2_env_create(&ctx.fsldebug_l2_env)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create L2 environment (%d) for fsl", l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_levels(ctx.fsldebug_l2_env, L2_LEVEL_ALL, L2_LEVEL_NONE)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_formatter(ctx.fsldebug_l2_env, 'D', l2_util_fmt_dump, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_formatter(ctx.fsldebug_l2_env, 'S', l2_util_fmt_string, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_formatter(ctx.fsldebug_l2_env, 'm', l2_util_fmt_errno, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_channel_create(&ctx.fsldebug_l2_nch, ctx.fsldebug_l2_env, "noop")) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel; %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_spec(&ch, ctx.fsldebug_l2_env, "%s", argl2spec)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d) for fsl", cp, l2rv); if (l2rv == L2_ERR_ARG) CU(FSL_ERR_ARG); else CU(FSL_ERR_INT); } if ((l2rv = l2_channel_link(ctx.fsldebug_l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((~ctx.logopt & LOG_NDELAY) && (ctx.delayopen == TRUE)) { fsldebug(L2_LEVEL_ERROR, "openlog: LOG_NDELAY unused forces debugging to use stealth mode until first syslog"); } else { if ((l2rv = l2_channel_open(ctx.fsldebug_l2_nch)) != L2_OK) { cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } d305 2 a306 4 if (rc == FSL_ERR_ARG) ctx.fsldebug_permanentproblem = TRUE; if (rc != FSL_OK) fsldebugdestroy(); d314 1 a314 1 fsldebugl2(level, message, ap) || fsldebugf2(level, message, ap); d318 2 a319 2 static int fsldebugl2(l2_level_t level, const char *message, va_list ap) d321 1 a321 68 int rc = FALSE; /* the pessimist */ l2_result_t l2rv; char *cp; /* identify previous fault and avoid repetition */ if (ctx.fsldebug_permanentproblem || ctx.fsldebug_transientproblem) return rc; /* nothing has been prepared, so do it now */ if (ctx.fsldebug_l2_nch == NULL) fsldebugcreate(); /* identify previous fault and avoid repetition */ if (ctx.fsldebug_permanentproblem || ctx.fsldebug_transientproblem) return rc; /* preparation failed */ if (ctx.fsldebug_l2_nch == NULL) return rc; /* try logging, L2_ERR_USE only occurs if channel is not yet open */ if ((l2rv = l2_channel_vlog(ctx.fsldebug_l2_nch, level, message, ap)) == L2_ERR_USE) { if ((l2rv = l2_channel_open(ctx.fsldebug_l2_nch)) != L2_OK) { ctx.fsldebug_transientproblem = TRUE; /* avoid loop from fsldebug() in next line */ cp = l2_env_strerror(ctx.fsldebug_l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) for fsl", cp, l2rv); ctx.fsldebug_transientproblem = FALSE; /* opening the channel might work at next attempt */ return rc; } l2rv = l2_channel_vlog(ctx.fsldebug_l2_nch, level, message, ap); } if (l2rv == L2_OK) rc = TRUE; /* if openlog(3) "did not request LOG_NDELAY" aka "did request delay" (~ctx.logopt & LOG_NDELAY), * until a syslog(3) was tried (ctx.delayopen == TRUE), operate in stealth mode by closing channel */ if ((~ctx.logopt & LOG_NDELAY) && (ctx.delayopen == TRUE)) (void)l2_channel_close(ctx.fsldebug_l2_nch); return rc; } static int fsldebugf2(l2_level_t level, const char *message, va_list ap) { int rc = TRUE; /* the optimist */ char cp[8]; if (level & L2_LEVEL_UPTO(L2_LEVEL_ERROR)) { fprintf( stderr, "%s: ", l2_util_l2s(cp, sizeof(cp), '\0', level) == L2_OK ? cp[0]&=0xDF, cp : "Log"); vfprintf(stderr, message, ap); fprintf( stderr, "\n"); } return rc; } static void fsldebugdestroy() { if (ctx.fsldebug_l2_nch != NULL) { l2_channel_destroy(ctx.fsldebug_l2_nch); ctx.fsldebug_l2_nch = NULL; } if (ctx.fsldebug_l2_env != NULL) { l2_env_destroy(ctx.fsldebug_l2_env); ctx.fsldebug_l2_env = NULL; } ctx.fsldebug_transientproblem = FALSE; /* fsldebug_permanentproblem kept */ d323 1 d388 2 a389 4 if ((cfgdir = getenv("FSL_CFGDIR")) == NULL) cfgdir = FSL_CFGDIR; if ((prefix = getenv("FSL_PREFIX")) == NULL) prefix = FSL_PREFIX; a727 1 char *cpISF; a735 1 cpISF = NULL; d798 1 a798 1 if ((cpISF = (char *)malloc(strlen(cpIdent) + 1 + strlen(cpFacility) + 1)) == NULL) { d800 4 a803 4 cpISF[0] = '\0'; strcat(cpISF, cpIdent); strcat(cpISF, "/"); strcat(cpISF, cpFacility); d816 1 a816 1 if ((rv = processcfg(cfg, cpISF, 0)) != FSL_OK && (rv != FSL_NOIDENT)) { d820 1 a820 1 if ((rv == FSL_NOIDENT) && ((rv = processcfg(cfg, cpISF, 1)) != FSL_OK)) { d835 4 a838 2 if (cpISF != NULL) free(cpISF); a856 1 fsldebugdestroy(); d868 4 @ 1.56 log @Adjust copyright messages to include new year 2003 @ text @a179 2 l2_env_t *l2_fslenv; l2_channel_t *l2_fslnch; d187 5 a191 2 int triedopenfsldebug; int openfsldebugpermanenterror; a195 2 NULL, NULL, d198 1 d200 3 a202 1 FALSE, d207 59 a265 1 /* internal debugging function */ a268 1 char cp[8]; d271 1 a271 7 /* note that a L2_ERR_USE is only returned by l2_channel_vlog() if the channel is not yet open */ if (ctx.l2_fslnch == NULL || (l2_channel_vlog(ctx.l2_fslnch, level, message, ap) == L2_ERR_USE)) if (level & L2_LEVEL_UPTO(L2_LEVEL_ERROR)) { fprintf( stderr, "%s: ", l2_util_l2s(cp, sizeof(cp), '\0', level) == L2_OK ? cp[0]&=0xDF, cp : "Log"); vfprintf(stderr, message, ap); fprintf( stderr, "\n"); } d276 72 a740 62 static void closefsllog() { if (ctx.l2_fslnch != NULL) { l2_channel_destroy(ctx.l2_fslnch); ctx.l2_fslnch = NULL; } if (ctx.l2_fslenv != NULL) { l2_env_destroy(ctx.l2_fslenv); ctx.l2_fslenv = NULL; } ctx.triedopenfsldebug = FALSE; } static void openfsldebug() { int rc = FSL_OK; char *argl2spec; l2_result_t l2rv; char *cp; /* scratch variable */ l2_channel_t *ch; /* scratch variable */ if (ctx.triedopenfsldebug || ctx.openfsldebugpermanenterror) return; /* properly prepare for repeated execution */ ctx.triedopenfsldebug = TRUE; /* create OSSP l2 environment for fsl itself (internal logging) */ if ((argl2spec = getenv("FSL_DEBUG")) == NULL) argl2spec = FSL_DEBUG; if (strlen(argl2spec) > 0) { if ((l2rv = l2_env_create(&ctx.l2_fslenv)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create L2 environment (%d) for fsl", l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_levels(ctx.l2_fslenv, L2_LEVEL_ALL, L2_LEVEL_NONE)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'D', l2_util_fmt_dump, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'S', l2_util_fmt_string, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'm', l2_util_fmt_errno, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_channel_create(&ctx.l2_fslnch, ctx.l2_fslenv, "noop")) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel; %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_spec(&ch, ctx.l2_fslenv, "%s", argl2spec)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d) for fsl", cp, l2rv); if (l2rv == L2_ERR_ARG) CU(FSL_ERR_ARG); else CU(FSL_ERR_INT); } if ((l2rv = l2_channel_link(ctx.l2_fslnch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } if ((l2rv = l2_channel_open(ctx.l2_fslnch)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) for fsl", cp, l2rv); CU(FSL_ERR_INT); } } CUS: if (rc != FSL_OK) closefsllog(); if (rc == FSL_ERR_ARG) ctx.openfsldebugpermanenterror = TRUE; } d768 6 a773 2 /* create OSSP l2 environment for fsl itself (internal logging) */ openfsldebug(); d776 1 a776 1 fsldebug(L2_LEVEL_TRACE, "openlog() ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx; caught by %s", ident, logopt, facility, fsl_version.v_gnu); d778 2 a779 3 /* remember logopt and handle unsupported values */ ctx.logopt = logopt; if (logopt & LOG_CONS) d782 1 a782 1 if (logopt & LOG_PERROR) d785 1 a785 1 if (logopt & LOG_PID) d851 1 a851 2 if (logopt & LOG_NDELAY) { ctx.delayopen = TRUE; d879 4 a882 2 fsldebug(L2_LEVEL_TRACE, "closelog()"); closefsllog(); d897 1 a897 1 ctx.delayopen = FALSE; d899 1 d908 3 a910 1 fsldebug(L2_LEVEL_TRACE, "setlogmask() maskpri=0x%.8lx", maskpri); d922 3 d944 4 a947 1 /* check for previous omitted attempt of initialization */ d956 1 a956 1 if ((ctx.logopt & LOG_NDELAY) && (ctx.delayopen == TRUE)) { @ 1.55 log @cosmetics @ text @d3 3 a5 3 ** Copyright (c) 2002 Ralf S. Engelschall ** Copyright (c) 2002 The OSSP Project ** Copyright (c) 2002 Cable & Wireless Deutschland @ 1.54 log @cfg_destroy now works @ text @d235 1 a235 1 fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer() filename=\"%s\")", filename); d499 1 a499 1 fsldebug(L2_LEVEL_ERROR, "processcfg: directive missing arguments, expected %d, got %d", cfgnume, cfgnumc); CU(FSL_ERR_CUS); } @ 1.53 log @who said that cfg_destroy() now works? We've to reinvestigate... @ text @a800 1 #if 0 /* FIXME */ a803 1 #endif @ 1.52 log @flush pending changes before tagging @ text @d801 1 a801 1 #if 1 /* FIXME */ @ 1.51 log @Fixed problem reported by martin.konold@@erfrakon.de: In fsl's vsyslog() when handling delayed open and "If the log file is not writable by fsl the application using fsl segfaults." The error condition was checked and logged but operation unintentionally continued. @ text @d801 1 a801 1 #if 0 /* FIXME */ @ 1.50 log @Change building of fsl_version.c from direct inclusion to standard object linking. @ text @d886 1 @ 1.49 log @Remove doubled "FSL" in "caught by FSL OSSP fsl 1.0.0". @ text @d57 1 d59 1 @ 1.48 log @Remove pcre_study(3) usage, because we do no repeated matchings and additionally (according to pcre(3)) studying for non-anchored patterns that do not have a single fixed starting character is useless. @ text @d707 1 a707 1 fsldebug(L2_LEVEL_TRACE, "openlog() ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx; caught by FSL %s", ident, logopt, facility, fsl_version.v_gnu); @ 1.47 log @Compile regular expressions with PCRE_ANCHORED to make sure they are anchored. This means the ident "bar/.*" does not match "foobar/quux". If it should it now has to be written ".*bar/quux". @ text @a432 1 pcre_extra *pcreExtra = NULL; a529 3 pcreExtra = pcre_study(pcreRegex, 0, &cpError); if (cpError != NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_study() failed with error %s", cpError); CU(FSL_ERR_CUS); } d531 1 a531 1 nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE); a559 4 if (pcreExtra != NULL) { pcre_free(pcreExtra); pcreExtra = NULL; } a606 4 if (pcreExtra != NULL) { pcre_free(pcreExtra); pcreExtra = NULL; } @ 1.46 log @use pcre_free() @ text @d529 1 a529 1 if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) { @ 1.45 log @add support for FSL_PREFIX and FSL_DEBUG variables. @ text @d432 6 d527 14 a540 17 { pcre *pcreRegex; pcre_extra *pcreExtra; const char *cpError; int iError; int nMatch; /* compile regular expression into finite state machine and optimize */ if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_compile() failed with error %s (%d)", cpError, iError); CU(FSL_ERR_CUS); } pcreExtra = pcre_study(pcreRegex, 0, &cpError); if (cpError != NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_study() failed with error %s", cpError); CU(FSL_ERR_CUS); } nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE); if (nMatch < 0) fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" failed.", cpISF, argmatch); d542 29 a570 25 if (nMatch == 0) fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0", cpISF, argmatch); else fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1)); if (nMatch >= 1) { pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch); if (acpMatch != NULL) for (i = 0; i < nMatch; i++) fsldebug(L2_LEVEL_DEBUG, "processcfg: regex reference[%d]=\'%s\'", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]); n = substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, NULL); if ((cp = (char *)malloc(n + 1)) == NULL) { fsldebug(L2_LEVEL_ERROR, "processcfg: malloc() failed"); CU(FSL_ERR_CUS); } if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) { fsldebug(L2_LEVEL_ERROR, "processcfg: substcapture() failed"); CU(FSL_ERR_CUS); } argl2spec = cp; fsldebug(L2_LEVEL_DEBUG, "processcfg: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec); /* create L2 channel throuh spec and link into root channel */ if ((l2rv = l2_spec(&ch, ctx.l2_env, "%s", argl2spec)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to create stream from spec %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); } if ((l2rv = l2_channel_link(ctx.l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to link child channel %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); } matchcount++; free(argl2spec); } d615 8 @ 1.44 log @Oops! Null command caused openfsldebugpermanenterror being always set @ text @a75 3 /* prefix of configuration files */ #define FSL_PREFIX "fsl." d277 2 a282 1 fsldebug(L2_LEVEL_TRACE, "readallfiles() globbing \"%s/%s*\"", FSL_CFGDIR, FSL_PREFIX); d284 8 a291 1 if ((dp = opendir(FSL_CFGDIR)) == NULL) d297 3 a299 3 if ( (n >= strlen(FSL_PREFIX)) && (strncmp(de->d_name, FSL_PREFIX, strlen(FSL_PREFIX)) == 0)) { if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + n + 1)) == NULL) d302 1 a302 1 strcat(filename, FSL_CFGDIR); @ 1.43 log @now logging FSL version @ text @d664 1 a664 1 if (rc == FSL_ERR_ARG); @ 1.42 log @avoid repetitive execution of bad l2specs @ text @d56 3 d699 1 a699 1 fsldebug(L2_LEVEL_TRACE, "openlog() ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility); @ 1.41 log @allow syslog() without previous openlog() @ text @d84 2 a85 1 FSL_ERR_CUS /* error handled and logged, just run clean up sequence and goodbye */ d186 3 a188 1 int openlog; d198 2 d603 62 a672 1 char *argl2spec; a677 1 l2_channel_t *ch; /* scratch variable */ d688 1 a688 1 /* properly handle repeated execution */ d690 1 a690 1 ctx.openlog = TRUE; d693 1 a693 22 if ((argl2spec = getenv("FSL_DEBUG")) == NULL) argl2spec = FSL_DEBUG; if (strlen(argl2spec) > 0) { if ((l2rv = l2_env_create(&ctx.l2_fslenv)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create L2 environment (%d) for fsl", l2rv); CU(1); } if ((l2rv = l2_env_levels(ctx.l2_fslenv, L2_LEVEL_ALL, L2_LEVEL_NONE)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults %s(%d) for fsl", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'D', l2_util_fmt_dump, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter %s(%d) for fsl", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'S', l2_util_fmt_string, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter %s(%d) for fsl", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'm', l2_util_fmt_errno, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter %s(%d) for fsl", cp, l2rv); CU(1); } if ((l2rv = l2_channel_create(&ctx.l2_fslnch, ctx.l2_fslenv, "noop")) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel; %s(%d) for fsl", cp, l2rv); CU(1); } if ((l2rv = l2_spec(&ch, ctx.l2_fslenv, "%s", argl2spec)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d) for fsl", cp, l2rv); CU(1); } if ((l2rv = l2_channel_link(ctx.l2_fslnch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d) for fsl", cp, l2rv); CU(1); } if ((l2rv = l2_channel_open(ctx.l2_fslnch)) != L2_OK) { cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) for fsl", cp, l2rv); CU(1); } } a695 1 d804 1 a804 8 if (ctx.l2_fslnch != NULL) { l2_channel_destroy(ctx.l2_fslnch); ctx.l2_fslnch = NULL; } if (ctx.l2_fslenv != NULL) { l2_env_destroy(ctx.l2_fslenv); ctx.l2_fslenv = NULL; } d820 1 a820 1 ctx.openlog = FALSE; d861 1 a861 1 if (ctx.l2_nch == NULL && !ctx.openlog) @ 1.40 log @reduce readfileorallfiles() to readallfiles() only @ text @d185 1 d194 1 d625 1 d652 1 d784 1 d824 4 @ 1.39 log @log errors between l2_channel_create() and l2_channel_open() @ text @a262 26 /* read a single file "fsl.xxx" into buffer */ static fsl_rc_t readfile(buf_t *buffer, const char *ident) { fsl_rc_t rc; char *filename = NULL; if (ident == NULL || buffer == NULL) CU(FSL_ERR_ARG); fsldebug(L2_LEVEL_TRACE, "readfile() ident=\"%s\")", ident); if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + strlen(FSL_PREFIX) + strlen(ident) + 1)) == NULL) CU(FSL_ERR_MEM); filename[0] = '\0'; strcat(filename, FSL_CFGDIR); strcat(filename, "/"); strcat(filename, FSL_PREFIX); strcat(filename, ident); CU(appendfiletobuffer(buffer, filename)); CUS: if (filename != NULL) free(filename); return rc; } a304 19 /* read a single or all possible files */ static fsl_rc_t readfileorallfiles(buf_t *buffer, const char *ident) { fsl_rc_t rv; if (ident == NULL) return FSL_ERR_ARG; fsldebug(L2_LEVEL_TRACE, "readfileorallfiles() ident=\"%s\")", ident); if ((rv = readfile(buffer, ident)) == FSL_OK) return FSL_OK; if (rv != FSL_ERR_SYS || errno != ENOENT) return rv; fsldebug(L2_LEVEL_TRACE, "readfileorallfiles: specific file does not exist, trying all files from directory"); if ((rv = readallfiles(buffer)) != FSL_OK) return rv; return FSL_OK; } d707 2 a708 2 if ((rv = readfileorallfiles(&buf, ident)) != FSL_OK) { fsldebug(L2_LEVEL_ERROR, "openlog: readfileorallfiles() for ident \"%s\" failed. Hint: last system error was \"%s\"(%d)", ident, strerror(errno), errno); CU(1); } @ 1.38 log @fprintf to stdout only if ERROR or worse @ text @d203 2 a204 3 if (ctx.l2_fslnch != NULL) l2_channel_vlog(ctx.l2_fslnch, level, message, ap); else @ 1.37 log @improve readability and consistency of fsldebug logging @ text @d200 1 d206 5 a210 1 vfprintf(stderr, message, ap); d754 1 a754 1 fsldebug(L2_LEVEL_ERROR, "openlog: readfileorallfiles(buf, \"%s\") returned %d, system error: %s(%d)", ident, rv, strerror(errno), errno); CU(1); } @ 1.36 log @support "default" ident handling @ text @d222 1 a222 1 fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(buffer, filename=\"%s\")", filename); d267 1 a267 1 fsldebug(L2_LEVEL_TRACE, "readfile(buffer, ident=\"%s\")", ident); d296 1 a296 1 fsldebug(L2_LEVEL_TRACE, "readallfiles(buffer) globbing \"%s/%s*\"", FSL_CFGDIR, FSL_PREFIX); d334 1 a334 1 fsldebug(L2_LEVEL_TRACE, "readfileorallfiles(buffer, ident=\"%s\")", ident); d340 1 a340 1 fsldebug(L2_LEVEL_TRACE, "readfileorallfiles: file does not exist"); d625 1 a625 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)", cp, cfgrv); CU(FSL_ERR_CUS); } d690 1 a690 2 if (ctx.l2_fslnch != NULL) fsldebug(L2_LEVEL_TRACE, "openlog(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility); d797 1 a798 1 l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "closelog()"); d829 1 a829 2 if (ctx.l2_fslnch != NULL) l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "setlogmask(maskpri=0x%.8lx)", maskpri); a863 6 #if 0 /* tracing */ if (ctx.l2_fslnch != NULL) l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "vsyslog(priority=%d, fmt=\"%s\", ...)", priority, fmt); #endif d893 2 @ 1.35 log @removed lots of useless newlines in fsldebug() calls @ text @d79 1 d83 2 a84 1 FSL_ERR_SYS /* operating system error, see errno */ d431 206 a644 10 cfg_node_t *cfgseq; cfg_node_t *cfgdir; cfg_node_t *cfgarg; cfg_node_type_t cfgtype; int cfgnumc; int cfgnume; char *cfgargtoka[3]; char *cfgargtok; char *argident; char *argmatch; a647 1 int n; /* scratch variable */ a650 2 int ovec[OVECSIZE]; const char **acpMatch; d748 1 a748 1 /* read in configuration file(s) */ d758 7 a764 150 /* find configuration root node and check if it is a sequence and has one or more directives below it */ if ((cfgrv = cfg_node_root(cfg, &cfgseq)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_root() failed with error %s (%d)", cp, cfgrv); CU(1); } traverse(cfg, cfgseq); if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgtype != CFG_NODE_TYPE_SEQ) { fsldebug(L2_LEVEL_ERROR, "openlog: expected sequence"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgnumc < 1) { fsldebug(L2_LEVEL_ERROR, "openlog: sequence is missing directives, expected 1, got %d", cfgnumc); CU(1); } /* get first directive below sequence */ if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILD1, &cfgdir)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)", cp, cfgrv); CU(1); } while (cfgdir != NULL) { /* check if operating on a directive */ if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgtype != CFG_NODE_TYPE_DIR) { fsldebug(L2_LEVEL_ERROR, "openlog: expected directive"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)", cp, cfgrv); CU(1); } /* process first child of directive, check if it is an argument and has a valid token attached */ if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILD1, &cfgarg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgarg == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: first argument is NULL"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgtype != CFG_NODE_TYPE_ARG) { fsldebug(L2_LEVEL_ERROR, "openlog: expected first argument, got %d", cfgtype); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgargtok == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: first argument has NULL data"); CU(1); } cfgargtoka[0] = cfgargtok; cfgnume = 0; if (strcmp(cfgargtoka[0], "ident") == 0) cfgnume = 3; if (strcmp(cfgargtoka[0], "default") == 0) cfgnume = 3; if (strcmp(cfgargtoka[0], "map") == 0) cfgnume = 3; if (cfgnume == 0) { fsldebug(L2_LEVEL_ERROR, "openlog: syntax error, invalid argument \"%s\"", cfgargtoka[0]); CU(1); } if (cfgnume != cfgnumc) { fsldebug(L2_LEVEL_ERROR, "openlog: directive missing arguments, expected %d, got %d", cfgnume, cfgnumc); CU(1); } for (i = 1; i < cfgnume; i++) { /* process right brother of argument, check if it is an argument and has a valid token attached */ if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_RBROTH, &cfgarg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgarg == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: argument %d is NULL", i); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgtype != CFG_NODE_TYPE_ARG) { fsldebug(L2_LEVEL_ERROR, "openlog: expected argument %d", i); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)", cp, cfgrv); CU(1); } if (cfgargtok == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: argument %d has NULL data", i); CU(1); } cfgargtoka[i] = cfgargtok; } if ((strcmp(cfgargtoka[0], "ident") == 0) || (strcmp(cfgargtoka[0], "default") == 0)) { /*FIXME currently default and ident are identical*/ argident = cfgargtoka[0]; argmatch = cfgargtoka[1]; argl2spec = cfgargtoka[2]; /* process the directive using the three arguments found */ fsldebug(L2_LEVEL_DEBUG, "openlog: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec); { pcre *pcreRegex; pcre_extra *pcreExtra; const char *cpError; int iError; int nMatch; /* compile regular expression into finite state machine and optimize */ if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: pcre_compile() failed with error %s (%d)", cpError, iError); CU(1); } pcreExtra = pcre_study(pcreRegex, 0, &cpError); if (cpError != NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: pcre_study() failed with error %s", cpError); CU(1); } nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE); if (nMatch < 0) fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" failed.", cpISF, argmatch); else if (nMatch == 0) fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0", cpISF, argmatch); else fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1)); if (nMatch >= 1) { pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch); if (acpMatch != NULL) for (i = 0; i < nMatch; i++) fsldebug(L2_LEVEL_DEBUG, "openlog: regex reference[%d]=\'%s\'", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]); n = substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, NULL); if ((cp = (char *)malloc(n + 1)) == NULL) { fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed"); CU(1); } if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) { fsldebug(L2_LEVEL_ERROR, "openlog: substcapture() failed"); CU(1); } argl2spec = cp; fsldebug(L2_LEVEL_DEBUG, "openlog: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec); /* create L2 channel throuh spec and link into root channel */ if ((l2rv = l2_spec(&ch, ctx.l2_env, "%s", argl2spec)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d)", cp, l2rv); CU(1); } if ((l2rv = l2_channel_link(ctx.l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d)", cp, l2rv); CU(1); } free(argl2spec); } } } else if (strcmp(cfgargtoka[0], "map") == 0) { int mapfrom; int mapto; for (i = 0, mapfrom = -1; (mapfrom == -1) && (sysloglevel2string[i].string != NULL); i++) { if (strcmp(sysloglevel2string[i].string, cfgargtoka[1]) == 0) mapfrom = i; } if (mapfrom == -1) { fsldebug(L2_LEVEL_ERROR, "openlog: trying to map from unknown syslog level \"%s\"", cfgargtoka[1]); CU(1); } for (i = 0, mapto = -1; (mapto == -1) && (l2level2string[i].string != NULL); i++) { if (strcmp(l2level2string[i].string, cfgargtoka[2]) == 0) mapto = i; } if (mapto == -1) { fsldebug(L2_LEVEL_ERROR, "openlog: trying to map to unknown l2 level \"%s\"", cfgargtoka[2]); CU(1); } ctx.levelmap[mapfrom].l2 = l2level2string[mapto].level; fsldebug(L2_LEVEL_DEBUG, "openlog: map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level); } else { fsldebug(L2_LEVEL_ERROR, "openlog: internal, argument \"%s\" not implemented", cfgargtoka[0]); CU(1); } /* get right brother of current directive */ if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_RBROTH, &cfgdir)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)", cp, cfgrv); CU(1); } } d766 1 @ 1.34 log @improve tracing @ text @d220 1 a220 1 fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(buffer, filename=\"%s\")\n", filename); d265 1 a265 1 fsldebug(L2_LEVEL_TRACE, "readfile(buffer, ident=\"%s\")\n", ident); d294 1 a294 1 fsldebug(L2_LEVEL_TRACE, "readallfiles(buffer) globbing \"%s/%s*\"\n", FSL_CFGDIR, FSL_PREFIX); d332 1 a332 1 fsldebug(L2_LEVEL_TRACE, "readfileorallfiles(buffer, ident=\"%s\")\n", ident); d356 1 a356 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed: %s (%d)\n", cp, cfgrv); CU(1); } d358 1 a358 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_TYPE) failed: %s (%d)\n", cp, cfgrv); CU(1); } d360 2 a361 2 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed: %s (%d)\n", cp, cfgrv); CU(1); } fsldebug(L2_LEVEL_DEBUG, "traverse: cfgnode=0x%.8lx[%d], cp=\"%s\", type=%d\n", (unsigned long)cfgnode, cfgchilds, (cp != NULL ? cp : ""), cfgtyp); d363 1 a363 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed: %s (%d)\n", cp, cfgrv); CU(1); } d367 1 a367 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed: %s (%d)\n", cp, cfgrv); CU(1); } d475 1 a475 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create L2 environment (%d) for fsl\n", l2rv); CU(1); } d477 1 a477 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults %s(%d) for fsl\n", cp, l2rv); CU(1); } d479 1 a479 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter %s(%d) for fsl\n", cp, l2rv); CU(1); } d481 1 a481 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter %s(%d) for fsl\n", cp, l2rv); CU(1); } d483 1 a483 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter %s(%d) for fsl\n", cp, l2rv); CU(1); } d485 1 a485 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel; %s(%d)\n for fsl", cp, l2rv); CU(1); } d487 1 a487 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d) for fsl\n", cp, l2rv); CU(1); } d489 1 a489 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d) for fsl\n", cp, l2rv); CU(1); } d491 1 a491 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) for fsl\n", cp, l2rv); CU(1); } d510 1 a510 1 fsldebug(L2_LEVEL_DEBUG, "openlog: create default syslog(3) to OSSP l2 level/priority mapping table\n"); d514 1 a514 1 fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed\n"); CU(1); } d518 1 a518 1 fsldebug(L2_LEVEL_DEBUG, "openlog: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", d524 1 a524 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create OSSP l2 environment: (%d)\n", l2rv); CU(1); } d526 1 a526 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults: %s(%d)\n", cp, l2rv); CU(1); } d528 1 a528 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter: %s(%d)\n", cp, l2rv); CU(1); } d530 1 a530 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter: %s(%d)\n", cp, l2rv); CU(1); } d532 1 a532 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter: %s(%d)\n", cp, l2rv); CU(1); } d534 1 a534 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel: %s(%d)\n", cp, l2rv); CU(1); } d538 1 a538 1 fsldebug(L2_LEVEL_ERROR, "openlog: strdup() failed\n"); CU(1); } d547 1 a547 1 fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed\n"); CU(1); } d555 1 a555 1 fsldebug(L2_LEVEL_ERROR, "openlog: readfileorallfiles(buf, \"%s\") returned %d, system error: %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); } d559 1 a559 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d561 1 a561 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d565 1 a565 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d568 1 a568 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d570 1 a570 1 fsldebug(L2_LEVEL_ERROR, "openlog: expected sequence\n"); CU(1); } d572 1 a572 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d574 1 a574 1 fsldebug(L2_LEVEL_ERROR, "openlog: sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); } d578 1 a578 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d582 1 a582 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d584 1 a584 1 fsldebug(L2_LEVEL_ERROR, "openlog: expected directive\n"); CU(1); } d586 1 a586 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d590 1 a590 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d592 1 a592 1 fsldebug(L2_LEVEL_ERROR, "openlog: first argument is NULL\n"); CU(1); } d594 1 a594 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d596 1 a596 1 fsldebug(L2_LEVEL_ERROR, "openlog: expected first argument, got %d\n", cfgtype); CU(1); } d598 1 a598 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d600 1 a600 1 fsldebug(L2_LEVEL_ERROR, "openlog: first argument has NULL data\n"); CU(1); } d611 1 a611 1 fsldebug(L2_LEVEL_ERROR, "openlog: syntax error, invalid argument \"%s\"\n", cfgargtoka[0]); CU(1); } d613 1 a613 1 fsldebug(L2_LEVEL_ERROR, "openlog: directive missing arguments, expected %d, got %d\n", cfgnume, cfgnumc); CU(1); } d618 1 a618 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d620 1 a620 1 fsldebug(L2_LEVEL_ERROR, "openlog: argument %d is NULL\n", i); CU(1); } d622 1 a622 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d624 1 a624 1 fsldebug(L2_LEVEL_ERROR, "openlog: expected argument %d\n", i); CU(1); } d626 1 a626 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d628 1 a628 1 fsldebug(L2_LEVEL_ERROR, "openlog: argument %d has NULL data\n", i); CU(1); } d638 1 a638 1 fsldebug(L2_LEVEL_DEBUG, "openlog: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); d648 1 a648 1 fsldebug(L2_LEVEL_ERROR, "openlog: pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); } d651 1 a651 1 fsldebug(L2_LEVEL_ERROR, "openlog: pcre_study() failed with error %s\n", cpError); CU(1); } d655 1 a655 1 fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" failed.\n", cpISF, argmatch); d658 1 a658 1 fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0\n", cpISF, argmatch); d660 1 a660 1 fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d\n", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1)); d665 1 a665 1 fsldebug(L2_LEVEL_DEBUG, "openlog: regex reference[%d]=\'%s\'\n", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]); d668 1 a668 1 fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed\n"); CU(1); } d670 1 a670 1 fsldebug(L2_LEVEL_ERROR, "openlog: substcapture() failed\n"); CU(1); } d672 1 a672 1 fsldebug(L2_LEVEL_DEBUG, "openlog: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); d676 1 a676 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d)\n", cp, l2rv); CU(1); } d678 1 a678 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d)\n", cp, l2rv); CU(1); } d694 1 a694 1 fsldebug(L2_LEVEL_ERROR, "openlog: trying to map from unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); } d701 1 a701 1 fsldebug(L2_LEVEL_ERROR, "openlog: trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); } d704 1 a704 1 fsldebug(L2_LEVEL_DEBUG, "openlog: map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx\n", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level); d707 1 a707 1 fsldebug(L2_LEVEL_ERROR, "openlog: internal, argument \"%s\" not implemented\n", cfgargtoka[0]); CU(1); } d711 1 a711 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d720 1 a720 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) immediately\n", cp, l2rv); CU(1); } d733 1 a733 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d822 1 a822 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "vsyslog: logging failed to open channel stream %s(%d) delayed\n", cp, l2rv); d835 1 a835 1 fsldebug(L2_LEVEL_DEBUG, "vsyslog: short circuit maskpri\n"); d841 1 a841 1 fsldebug(L2_LEVEL_DEBUG, "vsyslog: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d847 1 a847 1 fsldebug(L2_LEVEL_DEBUG, "vsyslog: levelmask=0x%.8lx\n", (unsigned long)levelmask); d850 1 a850 1 fsldebug(L2_LEVEL_PANIC, "vsyslog: application logging failed: %s (%d)\n", cp, l2rv); @ 1.33 log @removed double closedir() @ text @d338 1 @ 1.32 log @add Flexible to the official name @ text @a315 1 closedir(dp); @ 1.31 log @Code Review Results: - add more code comments - more safety on logging null pointers, etc. - more statics on internal functions - add missing closedir in readallfiles on CUS @ text @d2 1 a2 1 ** OSSP fsl - Faking Syslog Library @ 1.30 log @fix default log mask @ text @d53 3 d59 1 d61 2 a62 1 #define LOG_PRIMASK (LOG_EMERG|LOG_ALERT|LOG_CRIT|LOG_ERR|LOG_WARNING|LOG_NOTICE|LOG_INFO|LOG_DEBUG) d68 1 a68 3 #include "config.h" #define FSL_PREFIX "fsl." d73 2 a74 5 typedef struct { char *base; size_t used; size_t size; } buf_t; a82 5 #if 0 FSL_ERR_FMT, /* formatting error */ FSL_ERR_INT, /* internal error */ FSL_ERR_SYN, /* syntax error */ #endif d85 6 a90 4 fsl_rc_t readfileorallfiles(buf_t *, const char *); fsl_rc_t readfile (buf_t *, const char *); fsl_rc_t readallfiles (buf_t *); fsl_rc_t appendfiletobuffer(buf_t *, const char *); d92 1 d133 1 d150 1 d166 2 d173 1 a173 1 /* internal context structure */ d194 1 d197 1 a197 1 va_list args; d199 1 a199 1 va_start(args, message); d201 1 a201 1 l2_channel_vlog(ctx.l2_fslnch, level, message, args); d203 2 a204 2 vfprintf(stderr, message, args); va_end(args); d208 137 d356 1 a356 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d358 1 a358 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d360 2 a361 2 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } fsldebug(L2_LEVEL_DEBUG, "cfgnode=0x%.8lx[%d], *cp=\"%s\", type=%d\n", (unsigned long)cfgnode, cfgchilds, cp, cfgtyp); d363 1 a363 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d367 1 a367 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d374 1 a374 1 /* Substitutes $[0-9] in inbuf[inlen] with captured strings passed through capary[nary]. d394 1 a394 1 i+=2; d403 2 a404 2 i+=2; n+= ((m < nary) && (capary[m] != NULL)) ? strlen(capary[m]) : 0; d429 1 d459 1 d470 2 a471 3 /* create L2 environment for fsl itself */ argl2spec = getenv("FSL_DEBUG"); if (argl2spec == NULL) d473 1 a473 1 if (strlen(argl2spec) != 0) { d475 1 a475 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to create L2 environment (%d) for fsl\n", l2rv); CU(1); } d477 1 a477 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to set global logging level defaults %s(%d) for fsl\n", cp, l2rv); CU(1); } d479 1 a479 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register dump formatter %s(%d) for fsl\n", cp, l2rv); CU(1); } d481 1 a481 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register string formatter %s(%d) for fsl\n", cp, l2rv); CU(1); } d483 1 a483 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register errno formatter %s(%d) for fsl\n", cp, l2rv); CU(1); } d485 1 a485 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create noop channel; %s(%d)\n for fsl", cp, l2rv); CU(1); } d487 1 a487 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create stream from spec %s(%d) for fsl\n", cp, l2rv); CU(1); } d489 1 a489 1 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to link child channel %s(%d) for fsl\n", cp, l2rv); CU(1); } d491 1 a491 2 cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to open channel stream %s(%d) for fsl\n", cp, l2rv); CU(1); } fsldebug(L2_LEVEL_TRACE, "captured openlog(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility); d494 4 d501 1 a501 1 fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt LOG_CONS"); d504 1 a504 1 fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt LOG_PERROR, use l2spec channel \"fd(filedescriptor=2)\" to emulate"); d507 1 a507 1 fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt PID, use l2spec formatter %%P in prefix channel to emulate"); d510 3 a512 2 fsldebug(L2_LEVEL_DEBUG, "create default sysloglevel to l2_level mapping\n"); for (i = 0; sysloglevel2string[i].string != NULL; i++); d514 1 a514 1 fsldebug(L2_LEVEL_ERROR, "Error: malloc() failed\n"); CU(1); } d518 2 a519 1 fsldebug(L2_LEVEL_DEBUG, "ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d522 1 a522 1 /* create L2 environment for main application */ d524 1 a524 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to create L2 environment: (%d)\n", l2rv); CU(1); } d526 1 a526 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to set global logging level defaults: %s(%d)\n", cp, l2rv); CU(1); } d528 1 a528 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register dump formatter: %s(%d)\n", cp, l2rv); CU(1); } d530 1 a530 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register string formatter: %s(%d)\n", cp, l2rv); CU(1); } d532 1 a532 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register errno formatter: %s(%d)\n", cp, l2rv); CU(1); } d534 1 a534 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create noop channel: %s(%d)\n", cp, l2rv); CU(1); } d538 1 a538 1 fsldebug(L2_LEVEL_ERROR, "strdup() failed\n"); CU(1); } d547 1 a547 1 fsldebug(L2_LEVEL_ERROR, "malloc() failed\n"); CU(1); } d553 1 d555 1 a555 1 fsldebug(L2_LEVEL_ERROR, "readfileorallfiles(buf, \"%s\") returned %d, system error: %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); } d557 1 d559 1 a559 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d561 1 a561 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d563 1 a563 1 /* find root and check if it is a sequence and has one or more directives below it */ d565 1 a565 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d568 1 a568 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d570 1 a570 1 fsldebug(L2_LEVEL_ERROR, "expected sequence\n"); CU(1); } d572 1 a572 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d574 1 a574 1 fsldebug(L2_LEVEL_ERROR, "sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); } d578 1 a578 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d582 1 a582 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d584 1 a584 1 fsldebug(L2_LEVEL_ERROR, "expected directive\n"); CU(1); } d586 1 a586 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d590 1 a590 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d592 1 a592 1 fsldebug(L2_LEVEL_ERROR, "first argument is NULL\n"); CU(1); } d594 1 a594 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d596 1 a596 1 fsldebug(L2_LEVEL_ERROR, "expected first argument, got %d\n", cfgtype); CU(1); } d598 1 a598 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d600 1 a600 1 fsldebug(L2_LEVEL_ERROR, "first argument has NULL data\n"); CU(1); } d611 1 a611 1 fsldebug(L2_LEVEL_ERROR, "syntax error, invalid argument \"%s\"\n", cfgargtoka[0]); CU(1); } d613 1 a613 1 fsldebug(L2_LEVEL_ERROR, "directive missing arguments, expected %d, got %d\n", cfgnume, cfgnumc); CU(1); } a615 1 d618 1 a618 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d620 1 a620 1 fsldebug(L2_LEVEL_ERROR, "argument %d is NULL\n", i); CU(1); } d622 1 a622 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d624 1 a624 1 fsldebug(L2_LEVEL_ERROR, "expected argument %d\n", i); CU(1); } d626 1 a626 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d628 1 a628 1 fsldebug(L2_LEVEL_ERROR, "argument %d has NULL data\n", i); CU(1); } a632 1 d638 1 a638 1 fsldebug(L2_LEVEL_DEBUG, "argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); d648 1 a648 1 fsldebug(L2_LEVEL_ERROR, "pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); } d651 1 a651 1 fsldebug(L2_LEVEL_ERROR, "pcre_study() failed with error %s\n", cpError); CU(1); } d655 1 a655 1 fsldebug(L2_LEVEL_TRACE, "matching ident/facility \"%s\" against section \"%s\" failed.\n", cpISF, argmatch); d658 1 a658 1 fsldebug(L2_LEVEL_TRACE, "matching ident/facility \"%s\" against section \"%s\" succeeded, found $0\n", cpISF, argmatch); d660 1 a660 1 fsldebug(L2_LEVEL_TRACE, "matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d\n", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1)); d665 1 a665 1 fsldebug(L2_LEVEL_DEBUG, "regex reference[%d]=\'%s\'\n", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]); d668 1 a668 1 fsldebug(L2_LEVEL_ERROR, "malloc() failed\n"); CU(1); } d670 1 a670 1 fsldebug(L2_LEVEL_ERROR, "substcapture() failed\n"); CU(1); } d672 1 a672 1 fsldebug(L2_LEVEL_DEBUG, "argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); d676 1 a676 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create stream from spec %s(%d)\n", cp, l2rv); CU(1); } d678 1 a678 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to link child channel %s(%d)\n", cp, l2rv); CU(1); } d694 1 a694 1 fsldebug(L2_LEVEL_ERROR, "trying to map from unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); } d701 1 a701 1 fsldebug(L2_LEVEL_ERROR, "trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); } d704 1 a704 1 fsldebug(L2_LEVEL_DEBUG, "map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx\n", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level); d707 1 a707 1 fsldebug(L2_LEVEL_ERROR, "internal, argument \"%s\" not implemented\n", cfgargtoka[0]); CU(1); } d713 1 d716 1 a716 1 fsldebug(L2_LEVEL_TRACE, "logopt LOG_NDELAY delays open of L2 channel tree until first message is being logged"); d720 2 a721 2 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to open channel stream %s(%d) immediately\n", cp, l2rv); CU(1); } fsldebug(L2_LEVEL_TRACE, "logging succeeded to open channel stream immediately"); d730 1 a730 1 #if 0 d733 1 a733 1 (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d742 1 d746 1 a746 1 l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured closelog()"); d772 1 d778 1 a778 2 l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured setlogmask(maskpri=0x%.8lx)", maskpri); a779 1 d785 1 d797 1 d813 6 d822 1 a822 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to open channel stream %s(%d) delayed\n", cp, l2rv); d825 1 a825 1 fsldebug(L2_LEVEL_TRACE, "logging succeeded to open channel stream delayed"); d831 1 a831 1 fsldebug(L2_LEVEL_DEBUG, "priority =0x%.8lx, ctx.maskpri=0x%.8lx ", (unsigned long)priority, (unsigned long)ctx.maskpri); d835 1 a835 1 fsldebug(L2_LEVEL_DEBUG, "short circuit maskpri\n"); d841 1 a841 1 fsldebug(L2_LEVEL_DEBUG, "ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d847 1 a847 1 fsldebug(L2_LEVEL_DEBUG, "levelmask=0x%.8lx\n", (unsigned long)levelmask); d850 1 a850 1 fsldebug(L2_LEVEL_PANIC, "applicaion logging failed %s(%d)\n", cp, l2rv); a854 134 fsl_rc_t readfileorallfiles(buf_t *buffer, const char *ident) { fsl_rc_t rv; if (ident == NULL) return FSL_ERR_ARG; fsldebug(L2_LEVEL_TRACE, "readfileorallfiles(buffer, ident=\"%s\")\n", ident); if ((rv = readfile(buffer, ident)) == FSL_OK) return FSL_OK; if (rv != FSL_ERR_SYS || errno != ENOENT) return rv; if ((rv = readallfiles(buffer)) != FSL_OK) return rv; return FSL_OK; } fsl_rc_t readfile(buf_t *buffer, const char *ident) { fsl_rc_t rc; char *filename = NULL; if (ident == NULL || buffer == NULL) CU(FSL_ERR_ARG); fsldebug(L2_LEVEL_TRACE, "readfile(buffer, ident=\"%s\")\n", ident); if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + strlen(FSL_PREFIX) + strlen(ident) + 1)) == NULL) CU(FSL_ERR_MEM); filename[0] = '\0'; strcat(filename, FSL_CFGDIR); strcat(filename, "/"); strcat(filename, FSL_PREFIX); strcat(filename, ident); CU(appendfiletobuffer(buffer, filename)); CUS: if (filename != NULL) free(filename); return rc; } fsl_rc_t readallfiles(buf_t *buffer) { fsl_rc_t rc; DIR *dp; struct dirent *de; char *filename = NULL; int n; if (buffer == NULL) CU(FSL_ERR_ARG); fsldebug(L2_LEVEL_TRACE, "readallfiles(buffer) globbing \"%s/%s*\"\n", FSL_CFGDIR, FSL_PREFIX); if ((dp = opendir(FSL_CFGDIR)) == NULL) CU(FSL_ERR_SYS); rc = FSL_ERR_ARG; while ((de = readdir(dp)) != NULL) { n = strlen(de->d_name); if ( (n >= strlen(FSL_PREFIX)) && (strncmp(de->d_name, FSL_PREFIX, strlen(FSL_PREFIX)) == 0) ) { if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + n + 1)) == NULL) CU(FSL_ERR_MEM); filename[0] = '\0'; strcat(filename, FSL_CFGDIR); strcat(filename, "/"); strcat(filename, de->d_name); if (appendfiletobuffer(buffer, filename) == FSL_OK) rc = FSL_OK; free(filename); filename = NULL; } } (void)closedir(dp); CU(rc); CUS: if (filename != NULL) free(filename); return rc; } fsl_rc_t appendfiletobuffer(buf_t *buffer, const char *filename) { fsl_rc_t rc; int fd = -1; int filesize; int fileread; int bufferneed; if (filename == NULL || buffer == NULL) CU(FSL_ERR_ARG); fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(buffer, filename=\"%s\")\n", filename); if ((fd = open(filename, O_RDONLY)) == -1) CU(FSL_ERR_SYS); if ((filesize = (int)lseek(fd, 0, SEEK_END)) == -1) CU(FSL_ERR_SYS); bufferneed = buffer->used + filesize; if (bufferneed > buffer->size) { if (buffer->base == NULL) { if ((buffer->base = (char *)malloc(bufferneed)) == NULL) CU(FSL_ERR_MEM); buffer->size = bufferneed; buffer->used = 0; } else { if ((buffer->base = (char *)realloc(buffer->base, bufferneed)) == NULL) CU(FSL_ERR_MEM); buffer->size = bufferneed; } } if (lseek(fd, 0, SEEK_SET) == -1) CU(FSL_ERR_SYS); if ((fileread = (int)read(fd, buffer->base + buffer->used, (size_t)filesize)) == -1) CU(FSL_ERR_SYS); if (fileread != filesize) CU(FSL_ERR_USE); buffer->used += filesize; CU(FSL_OK); CUS: if (fd != -1) close(fd); return rc; } @ 1.29 log @FIXME removed; solaris does not have LOG_PERROR @ text @d187 1 a187 1 LOG_PRIMASK, d618 1 a618 1 ctx.maskpri = LOG_PRIMASK; d621 1 d676 1 a676 1 fsldebug(L2_LEVEL_DEBUG, "prioriy =0x%.8lx, ctx.maskpri=0x%.8lx ", (unsigned long)priority, (unsigned long)ctx.maskpri); @ 1.28 log @fix, fix, fix @ text @d358 1 d361 1 a386 4 #if 0 if ((l2rv = l2_env_settimer(ctx.l2_env, 20)) != L2_OK) { /*FIXME do we need this? -- RSE: no! */ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to configure timer: %s(%d)\n", cp, l2rv); CU(1); } #endif @ 1.27 log @we do not need this but it might break the timer function of the buffer channel @ text @d376 1 a376 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to create L2 environment (%d)\n", l2rv); CU(1); } d378 1 a378 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to set global logging level defaults %s(%d)\n", cp, l2rv); CU(1); } d380 1 a380 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register dump formatter %s(%d)\n", cp, l2rv); CU(1); } d382 1 a382 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register string formatter %s(%d)\n", cp, l2rv); CU(1); } d384 5 a388 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register errno formatter %s(%d)\n", cp, l2rv); CU(1); } d390 1 a390 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create noop channel; %s(%d)\n", cp, l2rv); CU(1); } @ 1.26 log @handle logopt; implement LOG_NDELAY @ text @a384 2 if ((l2rv = l2_env_settimer(ctx.l2_env, 20)) != L2_OK) { /*FIXME do we need this?*/ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to configure timer %s(%d)\n", cp, l2rv); CU(1); } @ 1.25 log @currently there are no extension planned which would require a greater or dynamic number @ text @d179 2 d187 3 a189 1 LOG_PRIMASK a327 2 /* info: ident, facility; trace: configmatching; debug: traversal */ d354 8 a361 2 /*FIXME currently we completely ignore logopt LOG_CONS, LOG_NDELAY, LOG_PERROR, LOG_PID */ d567 9 a575 4 if ((l2rv = l2_channel_open(ctx.l2_nch)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to open channel stream %s(%d)\n", cp, l2rv); CU(1); } ctx.maskpri = LOG_UPTO(LOG_DEBUG); d618 3 d658 1 a658 1 d662 10 @ 1.24 log @relocate pcre static vector size definition @ text @d298 1 a298 1 char *cfgargtoka[3]; /*FIXME hardcoded maximum number of arguments */ @ 1.23 log @improve tracing message when hunting for sections @ text @d53 3 a308 1 #define OVECSIZE 30 /*FIXME find a good place for this*/ @ 1.22 log @Fix a big security hole: the l2_spec() is a varargs function which gets a format string and variable arguments. In case only a fixed string is used we have to use "%s" as the format string or else "%x" in the string is treated like a formatter (and hence cause a segfault or whatever else if it tries to fetch args from the stack). This especially also no longer requires the formatters to be written %%X... @ text @d498 7 a504 1 fsldebug(L2_LEVEL_TRACE, "found %2d matches when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF); @ 1.21 log @added solaris and linux compatiblity; improved readability of traces @ text @d341 1 a341 1 if ((l2rv = l2_spec(&ch, ctx.l2_fslenv, argl2spec)) != L2_OK) { d513 1 a513 1 if ((l2rv = l2_spec(&ch, ctx.l2_env, argl2spec)) != L2_OK) { @ 1.20 log @corrected strlen comparison; improved debug/trace output @ text @a43 1 #include a52 5 /* default for the dedicated logfile */ #ifndef LOGFILE #define LOGFILE "/tmp/syslog" #endif d97 1 d99 2 d102 1 d105 1 d107 1 a108 7 { LOG_LPR, "lpr" }, { LOG_MAIL, "mail" }, { LOG_NEWS, "news" }, { LOG_SECURITY, "security" }, { LOG_SYSLOG, "syslog" }, { LOG_USER, "user" }, { LOG_UUCP, "uucp" }, d117 13 a129 1 { 0, NULL } d145 1 a145 1 { NULL, 0, 0 } d161 1 a161 1 { NULL, 0 } d192 2 d347 1 a347 1 fsldebug(L2_LEVEL_TRACE, "captured openlog(%s, 0x%.8lx, 0x%.8lx)", ident, logopt, facility); d398 1 a398 1 fsldebug(L2_LEVEL_ERROR, "readfileorallfiles(buf, %s) returned %d, system %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); } d498 1 a498 1 fsldebug(L2_LEVEL_TRACE, "nMatch=%d when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF); d604 1 a604 1 l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured setlogmask(0x%.8lx)", maskpri); d669 4 d692 1 d715 1 d719 1 d724 1 d726 2 a727 2 if ( (de->d_type == DT_REG) && (de->d_namlen >= strlen(FSL_PREFIX)) d730 1 a730 1 if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + de->d_namlen + 1)) == NULL) d735 3 a737 2 strncat(filename, de->d_name, de->d_namlen); (void /*FIXME*/)appendfiletobuffer(buffer, filename); d743 1 a743 1 CU(FSL_OK); d760 1 a760 1 fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(), filename=%s)\n", filename); @ 1.19 log @change prefix from l2. to fsl. @ text @d321 1 a321 1 if (strlen(argl2spec) != NULL) { d347 1 a414 2 fsldebug(L2_LEVEL_DEBUG, "cfgdir=0x%.8lx\n", (unsigned long)cfgdir); d491 1 a491 1 fsldebug(L2_LEVEL_DEBUG, "nMatch=%d when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF); d744 1 a744 1 fsldebug(L2_LEVEL_DEBUG, "appendfiletobuffer(..., %s)\n", filename); @ 1.18 log @added userlevel debugging through FSL_DEBUG environment variable @ text @d67 1 a67 1 #define FSL_PREFIX "l2." @ 1.17 log @improve cleanup; support maskpri @ text @d44 1 d165 2 d175 2 d180 11 a199 1 /*fprintf(stderr, "DEBUG: diving\n");*/ d202 1 a202 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d204 1 a204 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d206 2 a207 2 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } /*fprintf(stderr, "DEBUG: cfgnode=0x%.8lx[%d], *cp=\"%s\", type=%d\n", (unsigned long)cfgnode, cfgchilds, cp, cfgtyp);*/ d209 1 a209 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d213 1 a213 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } a214 1 /*fprintf(stderr, "DEBUG: climbing\n");*/ d315 30 a344 7 /*FIXME this should be available to the user to help him finding out what the application passes along * fprintf(stderr, "DEBUG: BEGIN ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx\n", ident, (unsigned long)logopt, (unsigned long)facility); */ /*FIXME this should be available to the user to help him finding out what the application passes along * currently we completely ignore logopt LOG_CONS, LOG_NDELAY, LOG_PERROR, LOG_PID */ d349 1 a349 1 fprintf(stderr, "Error: malloc() failed\n"); CU(1); } d353 1 a353 1 /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/ d356 1 a356 1 /* create L2 environment */ d358 1 a358 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: failed to create L2 environment (%d)\n", l2rv); CU(1); } d360 1 a360 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to set global logging level defaults %s(%d)\n", cp, l2rv); CU(1); } d362 1 a362 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to register dump formatter %s(%d)\n", cp, l2rv); CU(1); } d364 1 a364 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to register string formatter %s(%d)\n", cp, l2rv); CU(1); } d366 1 a366 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to register errno formatter %s(%d)\n", cp, l2rv); CU(1); } d368 1 a368 3 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: failed to configure timer %s(%d)\n", cp, l2rv); CU(1); } /* create L2 noop channel */ d370 1 a370 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to create noop channel; %s(%d)\n", cp, l2rv); CU(1); } d374 1 a374 1 fprintf(stderr, "Error: strdup() failed\n"); CU(1); } d383 1 a383 1 fprintf(stderr, "Error: malloc() failed\n"); CU(1); } d390 1 a390 1 fprintf(stderr, "DEBUG: error %d, system %s(%d)\n", rv, strerror(errno), errno); CU(1); } d393 1 a393 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d395 1 a395 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d399 2 a400 2 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); } /*FIXME traverse(cfg, cfgseq); DEBUG */ d402 1 a402 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d404 1 a404 1 fprintf(stderr, "Error: expected sequence\n"); CU(1); } d406 1 a406 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d408 1 a408 1 fprintf(stderr, "Error: sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); } d412 1 a412 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d414 1 a414 1 /*FIXME fprintf(stderr, "DEBUG: cfgdir=0x%.8lx\n", (unsigned long)cfgdir); */ d418 1 a418 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d420 1 a420 1 fprintf(stderr, "Error: expected directive\n"); CU(1); } d422 1 a422 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d426 1 a426 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d428 1 a428 1 fprintf(stderr, "Error: first argument is NULL\n"); CU(1); } d430 1 a430 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d432 1 a432 1 fprintf(stderr, "Error: expected first argument, got %d\n", cfgtype); CU(1); } d434 1 a434 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d436 1 a436 1 fprintf(stderr, "Error: first argument has NULL data\n"); CU(1); } d447 1 a447 1 fprintf(stderr, "Error: syntax error, invalid argument \"%s\"\n", cfgargtoka[0]); CU(1); } d449 1 a449 1 fprintf(stderr, "Error: directive missing arguments, expected %d, got %d\n", cfgnume, cfgnumc); CU(1); } d455 1 a455 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d457 1 a457 1 fprintf(stderr, "Error: argument %d is NULL\n", i); CU(1); } d459 1 a459 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d461 1 a461 1 fprintf(stderr, "Error: expected argument %d\n", i); CU(1); } d463 1 a463 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d465 1 a465 1 fprintf(stderr, "Error: argument %d has NULL data\n", i); CU(1); } d476 1 a476 1 /*fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);*/ d486 1 a486 1 fprintf(stderr, "Error: pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); } d489 1 a489 1 fprintf(stderr, "Error: pcre_study() failed with error %s\n", cpError); CU(1); } d492 1 a492 1 /*fprintf(stderr, "DEBUG: nMatch=%d when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF);*/ a494 1 /* d497 1 a497 2 fprintf(stderr, "DEBUG: regex reference[%d]=\'%s\'\n", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]); */ d500 1 a500 1 fprintf(stderr, "Error: malloc() failed\n"); CU(1); } d502 1 a502 1 fprintf(stderr, "Error: substcapture() failed\n"); CU(1); } d504 1 a504 1 /*fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);*/ d508 1 a508 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to create stream from spec %s(%d)\n", cp, l2rv); CU(1); } d510 1 a510 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to link child channel %s(%d)\n", cp, l2rv); CU(1); } d526 1 a526 1 fprintf(stderr, "Error: trying to map from unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); } d533 1 a533 1 fprintf(stderr, "Error: trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); } d536 1 a536 1 /*fprintf(stderr, "DEBUG: map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx\n", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level);*/ d539 1 a539 1 fprintf(stderr, "Error: internal, argument \"%s\" not implemented\n", cfgargtoka[0]); CU(1); } d543 1 a543 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d546 1 a546 1 cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to open channel stream %s(%d)\n", cp, l2rv); CU(1); } d559 1 a559 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); } a564 1 /*fprintf(stderr, "DEBUG: ------------------------------------------------------------\n");*/ d570 9 d597 3 d601 1 d626 2 d635 1 a635 1 /*fprintf(stderr, "DEBUG: prioriy =0x%.8lx, ctx.maskpri=0x%.8lx ", (unsigned long)priority, (unsigned long)ctx.maskpri);*/ d639 1 a639 1 /*fprintf(stderr, "DEBUG: short circuit maskpri\n");*/ d645 1 a645 1 /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/ d651 5 a655 2 /*fprintf(stderr, "DEBUG: levelmask=0x%.8lx\n", (unsigned long)levelmask);*/ l2_channel_vlog(ctx.l2_nch, levelmask, fmt, args); d745 1 a745 1 /*fprintf(stderr, "DEBUG: appendfiletobuffer(..., %s)\n", filename);*/ @ 1.16 log @cleanup code @ text @d298 3 a304 14 /* check for repeated execution */ if (ctx.l2_nch != NULL) { l2_channel_destroy(ctx.l2_nch); ctx.l2_nch = NULL; } if (ctx.l2_env != NULL) { l2_env_destroy(ctx.l2_env); ctx.l2_env = NULL; } if (ctx.levelmap != NULL) { free(ctx.levelmap); ctx.levelmap = NULL; } d531 1 a531 1 exit(rc); d546 4 a549 1 return; a555 2 /*FIXME this is currently a no-op. Should we care about maskpri, set l2 global mask or continue to ignore?*/ /* remember the logging mask */ d582 1 d586 9 a594 2 priority &= LOG_PRIMASK; /* strip off facility */ /*fprintf(stderr, "DEBUG: prioriy =0x%.8lx ", (unsigned long)priority);*/ @ 1.15 log @cleanup code @ text @d327 1 a327 1 //fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d514 1 a514 1 //fprintf(stderr, "DEBUG: map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx\n", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level); d596 1 a596 1 //fprintf(stderr, "DEBUG: prioriy =0x%.8lx ", (unsigned long)priority); d600 1 a600 1 //fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d606 1 a606 1 //fprintf(stderr, "DEBUG: levelmask=0x%.8lx\n", (unsigned long)levelmask); @ 1.14 log @mapping completed @ text @d85 5 a89 3 //FSL_ERR_FMT, /* formatting error */ //FSL_ERR_INT, /* internal error */ //FSL_ERR_SYN, /* syntax error */ d175 1 a175 1 void traverse(cfg_t *cfg, cfg_node_t *cfgnode) d210 1 a210 1 int substcapture(const char *inbuf, int inlen, const char **capary, int nary, char *outbuf) d274 1 a274 1 char *cfgargtoka[3]; //FIXME hardcoded maximum number of arguments d285 1 a285 1 #define OVECSIZE 30 //FIXME find a good place for this d341 1 a341 1 if ((l2rv = l2_env_settimer(ctx.l2_env, 20)) != L2_OK) { //FIXME do we need this? d376 1 a376 1 //FIXME traverse(cfg, cfgseq); /* DEBUG */ d390 1 a390 1 //FIXME fprintf(stderr, "DEBUG: cfgdir=0x%.8lx\n", (unsigned long)cfgdir); d445 1 a445 1 if ((strcmp(cfgargtoka[0], "ident") == 0) || (strcmp(cfgargtoka[0], "default") == 0)) { //FIXME currently default and ident are identical d564 1 a564 1 //FIXME this is currently a no-op. Should we care about maskpri, set l2 global mask or continue to ignore? @ 1.13 log @flush with lots of debugging stuff @ text @d125 1 a126 1 char *string; d129 9 a137 9 { LOG_EMERG, "emerg", L2_LEVEL_PANIC }, { LOG_ALERT, "alert", L2_LEVEL_PANIC }, { LOG_CRIT, "crit", L2_LEVEL_CRITICAL }, { LOG_ERR, "err", L2_LEVEL_ERROR }, { LOG_WARNING, "warning", L2_LEVEL_WARNING }, { LOG_NOTICE, "notice", L2_LEVEL_NOTICE }, { LOG_INFO, "info", L2_LEVEL_INFO }, { LOG_DEBUG, "debug", L2_LEVEL_DEBUG }, { 0, NULL, 0 } d140 15 d325 1 a325 1 /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/ d494 2 a495 1 unsigned int levelmask; d497 10 a506 8 for (i = 0; sysloglevel2string[i].string != NULL; i++) { if (strcmp(sysloglevel2string[i].string, cfgargtoka[1]) == 0) { if ((l2rv = l2_util_s2l(cfgargtoka[2], strlen(cfgargtoka[2]), ',', &levelmask)) != L2_OK) {; cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: illegal l2 mask \"%s\" %s(%d)\n", cfgargtoka[2], cp, l2rv); CU(1); } ctx.levelmap[i].l2 = levelmask; /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/ break; } d508 5 a512 2 if (sysloglevel2string[i].string == NULL) { fprintf(stderr, "Error: trying to map unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); } a522 9 if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_PANIC, "testing L2_LEVEL_PANIC 0x%.8x", L2_LEVEL_PANIC )) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#0:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_CRITICAL, "testing L2_LEVEL_CRITICAL 0x%.8x", L2_LEVEL_CRITICAL)) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#1:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_ERROR, "testing L2_LEVEL_ERROR 0x%.8x", L2_LEVEL_ERROR )) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#2:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_WARNING, "testing L2_LEVEL_WARNING 0x%.8x", L2_LEVEL_WARNING )) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#3:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_NOTICE, "testing L2_LEVEL_NOTICE 0x%.8x", L2_LEVEL_NOTICE )) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#4:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_INFO, "testing L2_LEVEL_INFO 0x%.8x", L2_LEVEL_INFO )) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#5:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_TRACE, "testing L2_LEVEL_TRACE 0x%.8x", L2_LEVEL_TRACE )) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#6:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_DEBUG, "testing L2_LEVEL_DEBUG 0x%.8x", L2_LEVEL_DEBUG )) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#7:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_INFO|L2_LEVEL_CRITICAL, "combitest 0x%.8x", L2_LEVEL_INFO|L2_LEVEL_CRITICAL)) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#8:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv); d594 1 a594 1 fprintf(stderr, "DEBUG: prioriy=0x%.8lx\n", (unsigned long)priority); d598 5 a602 3 /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/ if (ctx.levelmap[i].syslog == priority) levelmask |= ctx.levelmap[i].l2; d604 1 a604 1 fprintf(stderr, "DEBUG: levelmask=0x%.8lx\n", (unsigned long)levelmask); @ 1.12 log @disable debug messages for now @ text @d502 9 d582 1 d590 1 a590 1 /*fprintf(stderr, "DEBUG: prioriy=0x%.8lx > levelmask=0x%.8lx\n", (unsigned long)priority, (unsigned long)levelmask);*/ @ 1.11 log @flush with basic syslog level to l2 mask mapping working @ text @d167 1 a167 1 fprintf(stderr, "DEBUG: diving\n"); d175 1 a175 1 fprintf(stderr, "DEBUG: cfgnode=0x%.8lx[%d], *cp=\"%s\", type=%d\n", (unsigned long)cfgnode, cfgchilds, cp, cfgtyp); d183 1 a183 1 fprintf(stderr, "DEBUG: climbing\n"); d310 1 a310 1 fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d435 1 a435 1 fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); d451 1 a451 1 fprintf(stderr, "DEBUG: nMatch=%d when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF); d454 1 d458 1 d465 1 a465 1 fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); d486 1 a486 1 fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d520 1 a520 1 fprintf(stderr, "DEBUG: ------------------------------------------------------------\n"); d576 1 a576 1 fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2); d580 1 a580 1 fprintf(stderr, "DEBUG: prioriy=0x%.8lx > levelmask=0x%.8lx\n", (unsigned long)priority, (unsigned long)levelmask); d671 1 a671 1 fprintf(stderr, "DEBUG: appendfiletobuffer(..., %s)\n", filename); @ 1.10 log @basic syslog calls work @ text @a94 16 /* log level to string mapping */ static struct { int level; char *string; } level2string[] = { { LOG_EMERG, "emerg" }, { LOG_ALERT, "alert" }, { LOG_CRIT, "crit" }, { LOG_ERR, "err" }, { LOG_WARNING, "warning" }, { LOG_NOTICE, "notice" }, { LOG_INFO, "info" }, { LOG_DEBUG, "debug" }, { 0, NULL } }; d98 1 a98 1 } facility2string[] = { d124 21 d149 2 d154 2 d256 3 d294 4 d303 10 d335 3 a337 3 for (i = 0; facility2string[i].string != NULL; i++) { if (facility == facility2string[i].facility) { cpFacility = facility2string[i].string; d347 3 a349 1 fprintf(stderr, "DEBUG: ISF=\"%s\"\n", cpISF); a352 4 if ((rv = readfileorallfiles(&buf, "config.log")) != FSL_OK) { fprintf(stderr, "DEBUG: error %d, system %s(%d)\n", rv, strerror(errno), errno); CU(1); } d375 1 a375 1 /* check if operating on a directive which has exactly three arguments */ a381 2 if (cfgnumc != 3) { fprintf(stderr, "Error: directive missing arguments, expected 3, got %d\n", cfgnumc); CU(1); } d387 1 a387 1 fprintf(stderr, "Error: argument \"argident\" is NULL\n"); CU(1); } d391 2 a392 2 fprintf(stderr, "Error: expected argument\n"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &argident)) != CFG_OK) { d394 35 a428 2 if (argident == NULL) { fprintf(stderr, "Error: argument \"argident\" has NULL data\n"); CU(1); } d430 40 a469 13 /* process right brother of argument, check if it is an argument and has a valid token attached */ if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_RBROTH, &cfgarg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } if (cfgarg == NULL) { fprintf(stderr, "Error: argument \"argmatch\" is NULL\n"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } if (cfgtype != CFG_NODE_TYPE_ARG) { fprintf(stderr, "Error: expected argument\n"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &argmatch)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } if (argmatch == NULL) { fprintf(stderr, "Error: argument \"argmatch\" has NULL data\n"); CU(1); } d471 5 a475 13 /* process right brother of argument, check if it is an argument and has a valid token attached */ if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_RBROTH, &cfgarg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } if (cfgarg == NULL) { fprintf(stderr, "Error: argument \"argl2spec\" is NULL\n"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } if (cfgtype != CFG_NODE_TYPE_ARG) { fprintf(stderr, "Error: expected argument\n"); CU(1); } if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &argl2spec)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } if (argl2spec == NULL) { fprintf(stderr, "Error: argument \"argl2spec\" has NULL data\n"); CU(1); } d477 1 a477 36 /* process the directive using the three arguments found */ fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); { pcre *pcreRegex; pcre_extra *pcreExtra; const char *cpError; int iError; int nMatch; /* compile regular expression into finite state machine and optimize */ if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) { fprintf(stderr, "Error: pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); } pcreExtra = pcre_study(pcreRegex, 0, &cpError); if (cpError != NULL) { fprintf(stderr, "Error: pcre_study() failed with error %s\n", cpError); CU(1); } nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE); fprintf(stderr, "DEBUG: nMatch=%d when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF); if (nMatch >= 1) { pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch); if (acpMatch != NULL) for (i = 0; i < nMatch; i++) fprintf(stderr, "DEBUG: regex reference[%d]=\'%s\'\n", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]); n = substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, NULL); if ((cp = (char *)malloc(n + 1)) == NULL) { fprintf(stderr, "Error: malloc() failed\n"); CU(1); } if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) { fprintf(stderr, "Error: substcapture() failed\n"); CU(1); } argl2spec = cp; fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec); /* create L2 channel throuh spec and link into root channel */ if ((l2rv = l2_spec(&ch, ctx.l2_env, argl2spec)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to create stream from spec %s(%d)\n", cp, l2rv); CU(1); } if ((l2rv = l2_channel_link(ctx.l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to link child channel %s(%d)\n", cp, l2rv); CU(1); } d479 8 a486 1 free(argl2spec); d488 2 d491 2 d501 2 d516 3 d537 1 a537 2 #if 0 int omask; d539 1 d541 1 a541 1 omask = ctx.maskpri; d544 1 a544 3 return omask; #endif return maskpri; //FIXME d564 3 d570 10 a579 1 l2_channel_vlog(ctx.l2_nch, L2_LEVEL_DEBUG, fmt, args); @ 1.9 log @unify error messages; integrate lib_l2 @ text @d142 2 a143 6 FILE *log; char *logfile; const char *ident; int logopt; int facility; int maskpri; d145 2 a146 1 NULL, LOGFILE, "unknown", 0, LOG_USER, 0xff a148 20 void FIXMEopenlog(const char *ident, int logopt, int facility) { /* remember parameters */ ctx.ident = ident; ctx.logopt = logopt; ctx.facility = facility; /* close perhaps still open logfile */ if (ctx.log != NULL) { fclose(ctx.log); ctx.log = NULL; } /* (re-)open new logfile */ if (!(ctx.logopt & LOG_NDELAY) && ctx.log == NULL) if ((ctx.log = fopen(ctx.logfile, "a")) == NULL) return; return; } a258 2 l2_env_t *l2_env; l2_channel_t *l2_nch; /* noop channel */ a267 2 l2_env = NULL; l2_nch = NULL; d269 17 a285 1 fprintf(stderr, "DEBUG: BEGIN ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx\n", ident, (unsigned long)logopt, (unsigned long)facility); d288 12 a299 12 if ((l2rv = l2_env_create(&l2_env)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: failed to create L2 environment (%d)\n", l2rv); CU(1); } if ((l2rv = l2_env_levels(l2_env, L2_LEVEL_ALL, L2_LEVEL_NONE)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to set global logging level defaults %s(%d)\n", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(l2_env, 'D', l2_util_fmt_dump, NULL)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to register dump formatter %s(%d)\n", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(l2_env, 'S', l2_util_fmt_string, NULL)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to register string formatter %s(%d)\n", cp, l2rv); CU(1); } if ((l2rv = l2_env_formatter(l2_env, 'm', l2_util_fmt_errno, NULL)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to register errno formatter %s(%d)\n", cp, l2rv); CU(1); } if ((l2rv = l2_env_settimer(l2_env, 20)) != L2_OK) { //FIXME do we need this? cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: failed to configure timer %s(%d)\n", cp, l2rv); CU(1); } d302 2 a303 2 if ((l2rv = l2_channel_create(&l2_nch, l2_env, "noop")) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to create noop channel; %s(%d)\n", cp, l2rv); CU(1); } d435 4 a438 4 if ((l2rv = l2_spec(&ch, l2_env, argl2spec)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to create stream from spec %s(%d)\n", cp, l2rv); CU(1); } if ((l2rv = l2_channel_link(l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to link child channel %s(%d)\n", cp, l2rv); CU(1); } d448 2 a449 3 if ((l2rv = l2_channel_open(l2_nch)) != L2_OK) { cp = l2_env_strerror(l2_env, l2rv); fprintf(stderr, "Error: logging failed to open channel stream %s(%d)\n", cp, l2rv); CU(1); } l2_channel_log(l2_nch, L2_LEVEL_DEBUG, "Hello, World!"); //FIXME DEBUG a450 1 fprintf(stderr, "DEBUG: *END*, buf.base=0x%.8lx, buf.used=%d, buf.size=%d\n", (unsigned long)buf.base, (int)buf.used, (int)buf.size); a451 1 FIXMEopenlog(ident, logopt, facility); a456 4 if (l2_nch != NULL) l2_channel_destroy(l2_nch); if (l2_env != NULL) l2_env_destroy(l2_env); d462 2 d469 7 a475 4 /* close open logfile*/ if (ctx.log != NULL) { fclose(ctx.log); ctx.log = NULL; d482 1 d490 2 d511 1 a511 18 time_t now; int saved_errno; char buf[2048]; char *cpBuf; int nBuf; char caMsg[2048]; char *cpMsg; char *cpFmt; int i; char *cpTime; char *cpLevel; /* Check for invalid bits */ if (priority & ~(LOG_PRIMASK|LOG_FACMASK)) priority &= (LOG_PRIMASK|LOG_FACMASK); /* stop processing if mask disabled this call */ if (!(LOG_MASK(LOG_PRI(priority)) & ctx.maskpri)) d514 1 a514 77 /* make sure we have a reasonable default for facility */ if ((priority & LOG_FACMASK) == 0) priority |= ctx.facility; /* remember errno for optional %m processing below */ saved_errno = errno; /* open logfile now (if it was delayed) */ if (ctx.log == NULL) if ((ctx.log = fopen(ctx.logfile, "a")) == NULL) return; /* determine current time */ time(&now); cpTime = ctime(&now) + 4; /* determine logging level name */ cpLevel = "unknown"; for (i = 0; level2string[i].string != NULL; i++) { if (LOG_PRI(priority) == level2string[i].level) { cpLevel = level2string[i].string; break; } } /* start output generation */ cpBuf = buf; sprintf(cpBuf, "%.15s <%s> %s", cpTime, cpLevel, ctx.ident); nBuf = strlen(cpBuf); /* optionally add process id */ if (ctx.logopt & LOG_PID) { sprintf(cpBuf+nBuf, "[%d]", getpid()); nBuf += strlen(cpBuf+nBuf); } /* end prefix */ strcpy(cpBuf+nBuf, ": "); nBuf += 2; /* optionally expand %m in format string */ cpFmt = (char *)fmt; if (strstr(cpFmt, "%m")) { cpMsg = caMsg; while (cpFmt[0] != '\0') { if (cpFmt[0] == '%' && cpFmt[1] == 'm') { strcpy(cpMsg, strerror(saved_errno)); cpMsg += strlen(cpMsg); cpFmt += 2; } else { *cpMsg++ = *cpFmt++; *cpMsg = '\0'; } } cpFmt = caMsg; } /* append message to output buffer */ vsprintf(cpBuf+nBuf, cpFmt, args); nBuf += strlen(cpBuf+nBuf); /* append newline if still not present */ if (cpBuf[nBuf-1] != '\n') { cpBuf[nBuf++] = '\n'; cpBuf[nBuf] = '\0'; } /* now finally write output buffer to logfile */ fwrite(cpBuf, nBuf, 1, ctx.log); fflush(ctx.log); #ifdef LOG_PERROR /* optionally also write output buffer to stderr */ if (ctx.logopt & LOG_PERROR) fwrite(cpBuf, nBuf, 1, stderr); #endif @ 1.8 log @substituting the $0 ... $9 variables @ text @d184 1 a184 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(T) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d186 1 a186 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(t) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d188 1 a188 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(c) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d191 1 a191 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(C) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d195 1 a195 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(R) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d282 4 d293 2 d298 18 d318 1 a318 1 fprintf(stderr, "ERROR: strdup() failed\n"); CU(1); } d327 1 a327 1 fprintf(stderr, "ERROR: malloc() failed\n"); CU(1); } d335 1 a335 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d337 2 a338 2 if ((rv = readfileorallfiles(&buf, "config.log")) != FSL_OK) fprintf(stderr, "DEBUG: error#%d, system#%s(%d)\n", rv, strerror(errno), errno); d341 1 a341 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d345 1 a345 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); } d348 1 a348 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d350 1 a350 1 fprintf(stderr, "ERROR: expected sequence\n"); CU(1); } d352 1 a352 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d354 1 a354 1 fprintf(stderr, "ERROR: sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); } d358 1 a358 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d364 1 a364 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d366 1 a366 1 fprintf(stderr, "ERROR: expected directive\n"); CU(1); } d368 1 a368 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d370 1 a370 1 fprintf(stderr, "ERROR: directive missing arguments, expected 3, got %d\n", cfgnumc); CU(1); } d374 1 a374 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d376 1 a376 1 fprintf(stderr, "ERROR: argument \"argident\" is NULL\n"); CU(1); } d378 1 a378 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d380 1 a380 1 fprintf(stderr, "ERROR: expected argument\n"); CU(1); } d382 1 a382 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d384 1 a384 1 fprintf(stderr, "ERROR: argument \"argident\" has NULL data\n"); CU(1); } d388 1 a388 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d390 1 a390 1 fprintf(stderr, "ERROR: argument \"argmatch\" is NULL\n"); CU(1); } d392 1 a392 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d394 1 a394 1 fprintf(stderr, "ERROR: expected argument\n"); CU(1); } d396 1 a396 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d398 1 a398 1 fprintf(stderr, "ERROR: argument \"argmatch\" has NULL data\n"); CU(1); } d402 1 a402 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d404 1 a404 1 fprintf(stderr, "ERROR: argument \"argl2spec\" is NULL\n"); CU(1); } d406 1 a406 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d408 1 a408 1 fprintf(stderr, "ERROR: expected argument\n"); CU(1); } d410 1 a410 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d412 1 a412 1 fprintf(stderr, "ERROR: argument \"argl2spec\" has NULL data\n"); CU(1); } a415 1 d425 1 a425 1 fprintf(stderr, "ERROR: pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); } d428 1 a428 1 fprintf(stderr, "ERROR: pcre_study() failed with error %s\n", cpError); CU(1); } d439 1 a439 1 fprintf(stderr, "ERROR: malloc() failed\n"); CU(1); } d441 11 a451 3 fprintf(stderr, "ERROR: substcapture() failed\n"); CU(1); } fprintf(stderr, "DEBUG: cp=\"%s\"\n", cp); free(cp); d457 1 a457 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); } d459 3 d471 4 d478 1 a478 1 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); } @ 1.7 log @integrated lib_pcre @ text @d203 55 d273 3 a275 2 char *cp; int i; d287 1 d293 2 a294 1 cpIdent = ident != NULL ? ident : "unknown"; a409 2 int i; char *cp; d414 7 d435 2 @ 1.6 log @now read and check syntax, no recursion required @ text @d111 29 d208 2 a209 2 cfg_t *cfg = NULL; cfg_rc_t cfgrv = CFG_OK; d219 7 d227 1 a227 1 fprintf(stderr, "DEBUG: BEGIN ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx\n", ident, (unsigned long)logopt, (unsigned long)facility); d231 20 d335 26 a365 6 #if 0 if ((cfgrv = cfg_destroy(cfg)) != CFG_OK) { (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); } #endif d368 1 d370 7 a376 1 FIXMEopenlog(ident, logopt, facility); @ 1.5 log @dump number of childs also @ text @d179 10 a188 3 cfg_t *cfg = NULL; cfg_rc_t cfgrv = CFG_OK; cfg_node_t *cfgroot; d191 1 a191 1 fprintf(stderr, "DEBUG: main(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)\n", ident, (unsigned long)logopt, (unsigned long)facility); d205 2 a206 1 if ((cfgrv = cfg_node_root(cfg, &cfgroot)) != CFG_OK) { d208 77 a284 1 traverse(cfg, cfgroot); d290 1 a290 1 fprintf(stderr, "DEBUG: main() OK, buf.base=0x%.8lx, buf.used=%d, buf.size=%d\n", (unsigned long)buf.base, (int)buf.used, (int)buf.size); @ 1.4 log @dump types also @ text @d51 1 d150 1 d157 4 a160 2 (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(y) failed with error %s (%d)\n", cp, cfgrv); CU(1); } fprintf(stderr, "DEBUG: cfgnode=0x%.8lx, *cp=\"%s\", type=%d\n", (unsigned long)cfgnode, cp, cfgtyp); @ 1.3 log @integration of lib_cfg including tree dump through traverse() @ text @d147 1 d154 3 a156 1 fprintf(stderr, "DEBUG: cfgnode=0x%.8lx, *cp=\"%s\"\n", (unsigned long)cfgnode, cp); @ 1.2 log @read file or all files and append to buffer @ text @d38 1 d41 3 d48 4 d64 30 d122 1 a122 1 void openlog(const char *ident, int logopt, int facility) d142 64 a343 54 /* ------------------------------------------------------------------ */ #include #include #include #include #include /* strerror() */ #include #include "config.h" #define FSL_PREFIX "l2." #define STMT(stuff) do { stuff } while (0) #define CU(returncode) STMT( rc = returncode; goto CUS; ) #define VCU STMT( goto CUS; ) typedef struct { char *base; int used; int size; } buf_t; /* general return codes */ typedef enum { FSL_OK = 0, /* everything ok */ FSL_ERR_ARG, /* invalid argument */ FSL_ERR_USE, /* invalid use */ FSL_ERR_MEM, /* no more memory available */ FSL_ERR_SYS /* operating system error, see errno */ //FSL_ERR_FMT, /* formatting error */ //FSL_ERR_INT, /* internal error */ //FSL_ERR_SYN, /* syntax error */ } fsl_rc_t; fsl_rc_t readfileorallfiles(buf_t *, const char *); fsl_rc_t readfile (buf_t *, const char *); fsl_rc_t readallfiles (buf_t *); fsl_rc_t appendfiletobuffer(buf_t *, const char *); int main(int argc, char **argv) { buf_t buf; fsl_rc_t rv; buf.base = NULL; buf.used = 0; buf.size = 0; if ((rv = readfileorallfiles(&buf, "config.log")) != FSL_OK) fprintf(stderr, "DEBUG: error#%d, system#%s(%d)\n", rv, strerror(errno), errno); return 0; } d430 1 @ 1.1 log @First cut for new-born OSSP fsl, a faking syslog(3) API library. It is internally based (and contains) OSSP l2 and OSSP cfg. @ text @d242 178 @