OSSP CVS Repository

ossp - Difference in ossp-pkg/rc/rc_proc.c versions 1.7 and 1.8
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/rc/rc_proc.c 1.7 -> 1.8

--- rc_proc.c    2002/06/28 14:20:23     1.7
+++ rc_proc.c    2002/06/28 17:43:23     1.8
@@ -72,6 +72,7 @@
 ************************************************/
 rc_return_t procPopulate(rc_proc_t *pRc)
 {
+    int i         = 0;
     int nFdrc     = 0;
     int nFdfunc   = 0;
     int nRet      = 0;
@@ -83,13 +84,11 @@
 
     assert(*pRc->m_pAnal->m_szRcs);
     sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
-    pTempscript = scriptNew();
 
     /* Open the func file if it exists in the configuration */
     if (pRc->m_pAnal->m_szFuncs) {
         if ((nFdfunc = open(pRc->m_pAnal->m_szFuncs, O_RDONLY)) == -1) {
-    /*        RC_THROW(RC_ERR_IO);*/
-            fprintf(stderr, "Problem with procPopulate open(2) of %s\n", pRc->m_pAnal->m_szFuncs);
+            RC_THROW(RC_ERR_FNC);
         }
     }
 
@@ -101,35 +100,51 @@
             scriptAppend(pRc->m_pScript, sBuf, nRet);
         }
         if (nRet == -1) /* Handle read errors */
-            TRACE("Problem with procPopulate read(2)");
-    /*        RC_THROW(RC_ERR_IO);*/
+            RC_THROW(RC_ERR_IO);
     }
 
     /* Iteratively read possibly globbed rc files */
     for (nIter = 0; pRc->m_pAnal->m_szRcs[nIter]; nIter++)
     {
+        assert(*pRc->m_pAnal->m_szRcs); /* If one of these assertions fail, */
+        assert(pRc->m_pAnal->m_szLocs); /* you've probably seen the ex_ bug */
+
+        /* Build the path name */
         szLocex = (char *)malloc(strlen(pRc->m_pAnal->m_szLocs) + strlen(pRc->m_pAnal->m_szRcs[nIter]) + 2);
         strcpy(szLocex, pRc->m_pAnal->m_szLocs);
         strcat(szLocex, pRc->m_pAnal->m_szRcs[nIter]);
 
         /* Open the rc file unconditionally */
-        if ((nFdrc = open(szLocex, O_RDONLY)) == -1) {
-    /*        RC_THROW(RC_ERR_IO);*/
-            fprintf(stderr, "Problem with procPopulate open(2) of %s\n", szLocex);
-        }
+        if ((nFdrc = open(szLocex, O_RDONLY)) == -1)
+            RC_THROW(RC_ERR_RCF);
 
         /* Read data from the rc file into a temporary script */
+        pTempscript = scriptNew();
         while ((nRet = read(nFdrc, sBuf, RC_READ_BUFSIZE)) > 0)
             scriptAppend(pTempscript, sBuf, nRet);
+
         if (nRet == -1) /* Handle read errors */
-            TRACE("Problem with procPopulate read(2)");
-    /*        RC_THROW(RC_ERR_IO);*/
+            RC_THROW(RC_ERR_IO);
 
-        /* Extract a section from the temp script, and append it to other one */
-        szSec = scriptSection(pTempscript, "start");       /* Extract section */
-        scriptAppend(pRc->m_pScript, szSec, strlen(szSec)); /* Append section */
+        for (i = 0; pRc->m_pAnal->m_pszSecs[i]; i++) { /* Iterate over secvec */
+            /* Extract a section from the temp script, and append it */
+            szSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[i]);
+
+            if (szSec) /* Only call append if the section lookup succeeded */
+                scriptAppend(pRc->m_pScript, szSec, strlen(szSec));
+            else
+                fprintf(stderr, "#Warning: Missing section '%s' in %s!\n", pRc->m_pAnal->m_pszSecs[i], pRc->m_pAnal->m_szRcs[nIter]);
+
+            if (szSec) { /* Cleanup section string */
+                free(szSec);
+                szSec = NULL;
+            }
+        }
 
-        free(szLocex);  /* Free our temporarily constructed Location + Rcfile */
+        /* Clean up our crap */
+        scriptDelete(pTempscript); /* Temp script */
+        pTempscript = NULL;
+        free(szLocex);  /* Temp Location + Rcfile */
         szLocex = NULL;
         close(nFdrc);   /* Close Rc file handle */
     }
@@ -137,15 +152,10 @@
     close(nFdfunc);     /* Close Func file handle */
 
     /* Memory cleanups */
-    scriptDelete(pTempscript);
     if (sBuf) {
         free(sBuf);
         sBuf = NULL;
     }
-    if (szSec) {
-        free(szSec);
-        szSec = NULL;
-    }
 
     return(RC_THROW(RC_OK));
 }

CVSTrac 2.0.1