OSSP CVS Repository

ossp - Check-in [2359]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2359
Date: 2002-Jul-25 17:00:29 (local)
2002-Jul-25 15:00:29 (UTC)
User:thl
Branch:
Comment: handle logopt; implement LOG_NDELAY
Tickets:
Inspections:
Files:
ossp-pkg/fsl/fsl.c      1.25 -> 1.26     36 inserted, 10 deleted

ossp-pkg/fsl/fsl.c 1.25 -> 1.26

--- fsl.c        2002/07/25 14:15:54     1.25
+++ fsl.c        2002/07/25 15:00:29     1.26
@@ -176,13 +176,17 @@
     l2_channel_t *l2_nch;
     levelmap_t   *levelmap;
     int           maskpri;
+    int           logopt;
+    int           delayopen;
 } ctx = { 
     NULL,
     NULL,
     NULL,
     NULL,
     NULL,
-    LOG_PRIMASK
+    LOG_PRIMASK,
+    0,
+    FALSE
 };
 
 static void fsldebug(l2_level_t level, const char *message, ...)
@@ -321,8 +325,6 @@
     /* properly handle repeated execution */
     closelog();
 
-    /* info: ident, facility; trace: configmatching; debug: traversal */
-
     /* create L2 environment for fsl itself */
     argl2spec = getenv("FSL_DEBUG");
     if (argl2spec == NULL)
@@ -349,8 +351,14 @@
         fsldebug(L2_LEVEL_TRACE, "captured openlog(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility);
     }
 
-    /*FIXME currently we completely ignore logopt LOG_CONS, LOG_NDELAY, LOG_PERROR, LOG_PID
-    */
+    /* remember logopt and handle unsupported values */
+    ctx.logopt = logopt;
+    if (logopt & LOG_CONS)
+        fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt LOG_CONS");
+    if (logopt & LOG_PERROR)
+        fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt LOG_PERROR, use l2spec channel \"fd(filedescriptor=2)\" to emulate");
+    if (logopt & LOG_PID)
+        fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt PID, use l2spec formatter %%P in prefix channel to emulate");
 
     /* create default sysloglevel to l2_level mapping */
     fsldebug(L2_LEVEL_DEBUG, "create default sysloglevel to l2_level mapping\n");
@@ -556,10 +564,15 @@
         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)\n", cp, cfgrv); CU(1); }
     }
-    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);
+    if (logopt & LOG_NDELAY) {
+        ctx.delayopen = TRUE;
+        fsldebug(L2_LEVEL_TRACE, "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, "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");
+    }
 
     CU(0);
 CUS:
@@ -602,6 +615,9 @@
         free(ctx.levelmap);
         ctx.levelmap = NULL;
     }
+    ctx.maskpri = LOG_PRIMASK;
+    ctx.logopt = 0;
+    ctx.delayopen = FALSE;
 }
 
 int setlogmask(int maskpri)
@@ -639,11 +655,21 @@
     int i;
     l2_result_t l2rv;
     char *cp;
-
+    
     /* 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, "logging failed to open channel stream %s(%d) delayed\n", cp, l2rv);
+            closelog();
+        }
+        fsldebug(L2_LEVEL_TRACE, "logging succeeded to open channel stream delayed");
+        ctx.delayopen = FALSE;
+    }
+
     /* strip off facility */
     priority &= LOG_PRIMASK;
     fsldebug(L2_LEVEL_DEBUG, "prioriy  =0x%.8lx, ctx.maskpri=0x%.8lx  ", (unsigned long)priority, (unsigned long)ctx.maskpri);

CVSTrac 2.0.1