OSSP CVS Repository

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

ossp-pkg/fsl/fsl.c 1.41 -> 1.42

--- fsl.c        2002/07/30 12:03:36     1.41
+++ fsl.c        2002/07/31 11:39:13     1.42
@@ -81,7 +81,8 @@
     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_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 */
@@ -182,7 +183,9 @@
     int           maskpri;
     int           logopt;
     int           delayopen;
-    int           openlog;
+    int           triedopenlog;
+    int           triedopenfsldebug;
+    int           openfsldebugpermanenterror;
 } ctx = { 
     NULL,
     NULL,
@@ -192,6 +195,8 @@
     LOG_UPTO(LOG_DEBUG),
     0,
     FALSE,
+    FALSE,
+    FALSE,
     FALSE
 };
 
@@ -595,6 +600,68 @@
     return rc;
 }
 
+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;
+}
+
 /* POSIX API function openlog(3) */
 void openlog(const char *ident, int logopt, int facility)
 {
@@ -603,13 +670,11 @@
     fsl_rc_t rv;
     cfg_t           *cfg;
     cfg_rc_t         cfgrv;
-    char *argl2spec;
     char *cp; /* scratch variable */
     int   i;  /* scratch variable */
     char *cpIdent;
     char *cpFacility;
     char *cpISF;
-    l2_channel_t *ch; /* scratch variable */
     l2_result_t   l2rv;
 
     /* initialization */
@@ -620,36 +685,14 @@
     cpIdent = NULL;
     cpISF = NULL;
 
-    /* properly handle repeated execution */
+    /* properly prepare for repeated execution */
     closelog();
-    ctx.openlog = TRUE;
+    ctx.triedopenlog = 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(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); }
-    }
+    openfsldebug();
 
     /* tracing */
-    
     fsldebug(L2_LEVEL_TRACE, "openlog() ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility);
 
     /* remember logopt and handle unsupported values */
@@ -758,14 +801,7 @@
 void closelog(void)
 {
     fsldebug(L2_LEVEL_TRACE, "closelog()");
-    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;
-    }
+    closefsllog();
     if (ctx.l2_nch != NULL) {
         l2_channel_destroy(ctx.l2_nch);
         ctx.l2_nch = NULL;
@@ -781,7 +817,7 @@
     ctx.maskpri = LOG_UPTO(LOG_DEBUG);
     ctx.logopt = 0;
     ctx.delayopen = FALSE;
-    ctx.openlog = FALSE;
+    ctx.triedopenlog = FALSE;
     return;
 }
 
@@ -822,7 +858,7 @@
     char *cp;
     
     /* check for previous omitted attempt of initialization */
-    if (ctx.l2_nch == NULL && !ctx.openlog)
+    if (ctx.l2_nch == NULL && !ctx.triedopenlog)
         openlog("fsl", 0, LOG_SYSLOG);
 
     /* check for previous proper initialization */

CVSTrac 2.0.1