OSSP CVS Repository

ossp - Difference in ossp-pkg/fsl/fsl.c versions 1.17 and 1.18
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/fsl/fsl.c 1.17 -> 1.18

--- fsl.c        2002/07/23 12:21:57     1.17
+++ fsl.c        2002/07/23 14:37:50     1.18
@@ -41,6 +41,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <syslimits.h>
 
 /* standard include we re-implement */
 #include <syslog.h>
@@ -161,6 +162,8 @@
 
 /* internal context structure */
 static struct {
+    l2_env_t     *l2_fslenv;
+    l2_channel_t *l2_fslnch;
     l2_env_t     *l2_env;
     l2_channel_t *l2_nch;
     levelmap_t   *levelmap;
@@ -169,9 +172,22 @@
     NULL,
     NULL,
     NULL,
+    NULL,
+    NULL,
     LOG_PRIMASK
 };
 
+static void fsldebug(l2_level_t level, const char *message, ...)
+{
+    va_list args;
+
+    va_start(args, message);
+    if (ctx.l2_fslnch != NULL)
+        l2_channel_vlog(ctx.l2_fslnch, level, message, args);
+    va_end(args);
+    return;
+}
+
 static void traverse(cfg_t *cfg, cfg_node_t *cfgnode)
 {
     int rc;
@@ -181,23 +197,21 @@
     char *cp;
     int cfgchilds;
 
-    /*fprintf(stderr, "DEBUG: diving\n");*/
     while (cfgnode != NULL) {
         if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_TOKEN, &cp)) != 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); }
+            (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); }
         if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_TYPE, &cfgtyp)) != 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); }
+            (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); }
         if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_CHILDS, &cfgchilds)) != CFG_OK) {
-            (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);*/
+            (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);
         if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_CHILD1, &cfgchld)) != CFG_OK) {
-            (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); }
+            (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); }
         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); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(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); }
     }
-    /*fprintf(stderr, "DEBUG: climbing\n");*/
     CU(0);
 CUS:
     return;
@@ -298,45 +312,66 @@
     /* properly handle repeated execution */
     closelog();
 
-    /*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
-     */
+    /* info: ident, facility; trace: configmatching; debug: traversal */
+
+    /* create L2 environment for fsl itself */
+    argl2spec = getenv("FSL_DEBUG");
+    if (argl2spec == NULL)
+        argl2spec = FSL_DEBUG;
+    if (strlen(argl2spec) != NULL) {
+        if ((l2rv = l2_env_create(&ctx.l2_fslenv)) != L2_OK) {
+            cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to create L2 environment (%d) for fsl\n", 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, "logging failed to set global logging level defaults %s(%d) for fsl\n", 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, "logging failed to register dump formatter %s(%d) for fsl\n", 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, "logging failed to register string formatter %s(%d) for fsl\n", 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, "logging failed to register errno formatter %s(%d) for fsl\n", 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, "logging failed to create noop channel; %s(%d)\n for fsl", cp, l2rv); CU(1); }
+        if ((l2rv = l2_spec(&ch, ctx.l2_fslenv, argl2spec)) != L2_OK) {
+            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); }
+        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, "logging failed to link child channel %s(%d) for fsl\n", 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, "logging failed to open channel stream %s(%d) for fsl\n", cp, l2rv); CU(1); }
+        fsldebug(L2_LEVEL_TRACE, "captured openlog(%s, 0x%.8lx, 0x%.8lx)", ident, logopt, facility);
+    }
+
+    /*FIXME currently we completely ignore logopt LOG_CONS, LOG_NDELAY, LOG_PERROR, LOG_PID
+    */
 
     /* create default sysloglevel to l2_level mapping */
     for (i = 0; sysloglevel2string[i].string != NULL; i++);
     if ((ctx.levelmap = (levelmap_t *)malloc(i * sizeof(levelmap_t))) == NULL) {
-        fprintf(stderr, "Error: malloc() failed\n"); CU(1); }
+        fsldebug(L2_LEVEL_ERROR, "Error: malloc() failed\n"); CU(1); }
     for (i = 0; sysloglevel2string[i].string != NULL; i++) {
         ctx.levelmap[i].syslog = sysloglevel2string[i].level;
         ctx.levelmap[i].l2     = sysloglevel2string[i].deflevelmap;
-        /*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);*/
+        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);
     }
 
-    /* create L2 environment */
+    /* create L2 environment for main application */
     if ((l2rv = l2_env_create(&ctx.l2_env)) != L2_OK) {
-        cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: failed to create L2 environment (%d)\n", l2rv); CU(1); }
+        cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to create L2 environment (%d)\n", 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); fprintf(stderr, "Error: logging failed to set global logging level defaults %s(%d)\n", cp, l2rv); CU(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); }
     if ((l2rv = l2_env_formatter(ctx.l2_env, 'D', l2_util_fmt_dump, NULL)) != L2_OK) {
-        cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to register dump formatter %s(%d)\n", cp, l2rv); CU(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); }
     if ((l2rv = l2_env_formatter(ctx.l2_env, 'S', l2_util_fmt_string, NULL)) != L2_OK) {
-        cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to register string formatter %s(%d)\n", cp, l2rv); CU(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); }
     if ((l2rv = l2_env_formatter(ctx.l2_env, 'm', l2_util_fmt_errno, NULL)) != L2_OK) {
-        cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to register errno formatter %s(%d)\n", cp, l2rv); CU(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); }
     if ((l2rv = l2_env_settimer(ctx.l2_env, 20)) != L2_OK) { /*FIXME do we need this?*/
-        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 */
+        cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to configure timer %s(%d)\n", 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); fprintf(stderr, "Error: logging failed to create noop channel; %s(%d)\n", cp, l2rv); CU(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); }
 
     /* create IdentSlashFacility */
     if ((cpIdent = strdup((ident != NULL) ? ident : "unknown")) == NULL) {
-        fprintf(stderr, "Error: strdup() failed\n"); CU(1); }
+        fsldebug(L2_LEVEL_ERROR, "strdup() failed\n"); CU(1); }
     cpFacility = "unknown";
     for (i = 0; syslogfacility2string[i].string != NULL; i++) {
         if (facility == syslogfacility2string[i].facility) {
@@ -345,60 +380,60 @@
         }
     }
     if ((cpISF = (char *)malloc(strlen(cpIdent) + 1 + strlen(cpFacility) + 1)) == NULL) {
-        fprintf(stderr, "Error: malloc() failed\n"); CU(1); }
+        fsldebug(L2_LEVEL_ERROR, "malloc() failed\n"); CU(1); }
     cpISF[0] = '\0';
     strcat(cpISF, cpIdent);
     strcat(cpISF, "/");
     strcat(cpISF, cpFacility);
 
     if ((rv = readfileorallfiles(&buf, ident)) != FSL_OK) {
-        fprintf(stderr, "DEBUG: error %d, system %s(%d)\n", rv, strerror(errno), errno); CU(1); }
+        fsldebug(L2_LEVEL_ERROR, "readfileorallfiles(buf, %s) returned %d, system %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); }
 
     if ((cfgrv = cfg_create(&cfg)) != CFG_OK) {
-        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "Error: cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_create() failed with error %s (%d)\n", 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); fprintf(stderr, "Error: cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
 
     /*  find root 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); fprintf(stderr, "Error: cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
-    /*FIXME traverse(cfg, cfgseq); DEBUG */
+        (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_root() failed with error %s (%d)\n", 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); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(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); }
     if (cfgtype != CFG_NODE_TYPE_SEQ) {
-        fprintf(stderr, "Error: expected sequence\n"); CU(1); }
+        fsldebug(L2_LEVEL_ERROR, "expected sequence\n"); CU(1); }
     if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) {
-        (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); }
+        (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); }
     if (cfgnumc < 1) {
-        fprintf(stderr, "Error: sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); }
+        fsldebug(L2_LEVEL_ERROR, "sequence is missing directives, expected 1, got %d\n", 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); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(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); }
     while (cfgdir != NULL) {
-        /*FIXME fprintf(stderr, "DEBUG: cfgdir=0x%.8lx\n", (unsigned long)cfgdir); */
+        fsldebug(L2_LEVEL_DEBUG, "cfgdir=0x%.8lx\n", (unsigned long)cfgdir);
 
         /*  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); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(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); }
         if (cfgtype != CFG_NODE_TYPE_DIR) {
-            fprintf(stderr, "Error: expected directive\n"); CU(1); }
+            fsldebug(L2_LEVEL_ERROR, "expected directive\n"); CU(1); }
         if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) {
-            (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); }
+            (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); }
 
         /*  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); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(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); }
         if (cfgarg == NULL) {
-            fprintf(stderr, "Error: first argument is NULL\n"); CU(1); }
+            fsldebug(L2_LEVEL_ERROR, "first argument 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); }
+            (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); }
         if (cfgtype != CFG_NODE_TYPE_ARG) {
-            fprintf(stderr, "Error: expected first argument, got %d\n", cfgtype); CU(1); }
+            fsldebug(L2_LEVEL_ERROR, "expected first argument, got %d\n", cfgtype); CU(1); }
         if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != 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); }
+            (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); }
         if (cfgargtok == NULL) {
-            fprintf(stderr, "Error: first argument has NULL data\n"); CU(1); }
+            fsldebug(L2_LEVEL_ERROR, "first argument has NULL data\n"); CU(1); }
         cfgargtoka[0] = cfgargtok;
 
         cfgnume = 0;
@@ -409,25 +444,25 @@
         if (strcmp(cfgargtoka[0], "map") == 0)
             cfgnume = 3;
         if (cfgnume == 0) {
-            fprintf(stderr, "Error: syntax error, invalid argument \"%s\"\n", cfgargtoka[0]); CU(1); }
+            fsldebug(L2_LEVEL_ERROR, "syntax error, invalid argument \"%s\"\n", cfgargtoka[0]); CU(1); }
         if (cfgnume != cfgnumc) {
-            fprintf(stderr, "Error: directive missing arguments, expected %d, got %d\n", cfgnume, cfgnumc); CU(1); }
+            fsldebug(L2_LEVEL_ERROR, "directive missing arguments, expected %d, got %d\n", 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); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(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); }
             if (cfgarg == NULL) {
-                fprintf(stderr, "Error: argument %d is NULL\n", i); CU(1); }
+                fsldebug(L2_LEVEL_ERROR, "argument %d is NULL\n", i); 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); }
+                (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); }
             if (cfgtype != CFG_NODE_TYPE_ARG) {
-                fprintf(stderr, "Error: expected argument %d\n", i); CU(1); }
+                fsldebug(L2_LEVEL_ERROR, "expected argument %d\n", i); CU(1); }
             if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != 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); }
+                (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); }
             if (cfgargtok == NULL) {
-                fprintf(stderr, "Error: argument %d has NULL data\n", i); CU(1); }
+                fsldebug(L2_LEVEL_ERROR, "argument %d has NULL data\n", i); CU(1); }
             cfgargtoka[i] = cfgargtok;
         }
 
@@ -438,7 +473,7 @@
             argl2spec = cfgargtoka[2];
 
             /*  process the directive using the three arguments found */
-            /*fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);*/
+            fsldebug(L2_LEVEL_DEBUG, "argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);
             {
                 pcre       *pcreRegex;
                 pcre_extra *pcreExtra;
@@ -448,33 +483,31 @@
 
                 /* 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); }
+                    fsldebug(L2_LEVEL_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); }
+                    fsldebug(L2_LEVEL_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);*/
+                fsldebug(L2_LEVEL_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]);
-                    */
+                            fsldebug(L2_LEVEL_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); }
+                        fsldebug(L2_LEVEL_ERROR, "malloc() failed\n"); CU(1); }
                     if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) {
-                        fprintf(stderr, "Error: substcapture() failed\n"); CU(1); }
+                        fsldebug(L2_LEVEL_ERROR, "substcapture() failed\n"); CU(1); }
                     argl2spec = cp;
-            /*fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);*/
+                    fsldebug(L2_LEVEL_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); }
+                        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); }
                     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); }
+                        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); }
 
                     free(argl2spec);
                 }
@@ -490,27 +523,27 @@
                     mapfrom = i;
             }
             if (mapfrom == -1) {
-                fprintf(stderr, "Error: trying to map from unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); }
+                fsldebug(L2_LEVEL_ERROR, "trying to map from unknown syslog level \"%s\"\n", 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) {
-                fprintf(stderr, "Error: trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); }
+                fsldebug(L2_LEVEL_ERROR, "trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); }
             
             ctx.levelmap[mapfrom].l2 = l2level2string[mapto].level;
-            /*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);*/
+            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);
         }
         else {
-            fprintf(stderr, "Error: internal, argument \"%s\" not implemented\n", cfgargtoka[0]); CU(1); }
+            fsldebug(L2_LEVEL_ERROR, "internal, argument \"%s\" not implemented\n", 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); fprintf(stderr, "Error: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(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); }
     }
     if ((l2rv = l2_channel_open(ctx.l2_nch)) != L2_OK) {
-        cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to open channel stream %s(%d)\n", cp, l2rv); CU(1); }
+        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);
 
@@ -523,18 +556,26 @@
 #if 0
     if (cfg != NULL)
         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); }
+            (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
 #endif
     if (buf.base != NULL)
         free(buf.base);
     if (rc != 0)
         closelog();
-    /*fprintf(stderr, "DEBUG: ------------------------------------------------------------\n");*/
     return;
 }
 
 void closelog(void)
 {
+    if (ctx.l2_fslnch != NULL) {
+        l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured closelog()");
+        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;
+    }
     if (ctx.l2_nch != NULL) {
         l2_channel_destroy(ctx.l2_nch);
         ctx.l2_nch = NULL;
@@ -553,7 +594,11 @@
 {
     int oldmask;
 
+    if (ctx.l2_fslnch != NULL)
+        l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured setlogmask(0x%.8lx)", maskpri);
+
     oldmask = ctx.maskpri;
+
     if (maskpri != 0)
         ctx.maskpri = maskpri;
     return oldmask;
@@ -578,6 +623,8 @@
 {
     unsigned int levelmask;
     int i;
+    l2_result_t l2rv;
+    char *cp;
 
     /* check for previous proper initialization */
     if (ctx.l2_nch == NULL)
@@ -585,24 +632,27 @@
 
     /* strip off facility */
     priority &= LOG_PRIMASK;
-    /*fprintf(stderr, "DEBUG: prioriy  =0x%.8lx, ctx.maskpri=0x%.8lx  ", (unsigned long)priority, (unsigned long)ctx.maskpri);*/
+    fsldebug(L2_LEVEL_DEBUG, "prioriy  =0x%.8lx, ctx.maskpri=0x%.8lx  ", (unsigned long)priority, (unsigned long)ctx.maskpri);
 
     /* check against maskpri */
     if ((LOG_MASK(priority) & ctx.maskpri) == 0) {
-        /*fprintf(stderr, "DEBUG: short circuit maskpri\n");*/
+        fsldebug(L2_LEVEL_DEBUG, "short circuit maskpri\n");
         return;
     }
 
     levelmask = 0;
     for (i = 0; sysloglevel2string[i].string != NULL; i++) {
-    /*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);*/
+    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);
         if (ctx.levelmap[i].syslog == priority) {
             levelmask = ctx.levelmap[i].l2;
             break;
         }
     }
-    /*fprintf(stderr, "DEBUG: levelmask=0x%.8lx\n", (unsigned long)levelmask);*/
-    l2_channel_vlog(ctx.l2_nch, levelmask, fmt, args);
+    fsldebug(L2_LEVEL_DEBUG, "levelmask=0x%.8lx\n", (unsigned long)levelmask);
+    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, "applicaion logging failed %s(%d)\n", cp, l2rv);
+    }
     return;
 }
 
@@ -692,7 +742,7 @@
 
     if (filename == NULL || buffer == NULL)
         CU(FSL_ERR_ARG);
-/*fprintf(stderr, "DEBUG: appendfiletobuffer(..., %s)\n", filename);*/
+    fsldebug(L2_LEVEL_DEBUG, "appendfiletobuffer(..., %s)\n", filename);
 
     if ((fd = open(filename, O_RDONLY)) == -1)
         CU(FSL_ERR_SYS);

CVSTrac 2.0.1