OSSP CVS Repository

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

ossp-pkg/rc/rc_proc.c 1.20 -> 1.21

--- rc_proc.c    2003/05/12 16:17:47     1.20
+++ rc_proc.c    2003/05/14 16:36:28     1.21
@@ -45,12 +45,18 @@
 ************************************************/
 rc_proc_t *procNew(void)
 {
+    int nIter = 0;
     rc_proc_t *pNewrc = NULL;
 
     pNewrc = malloc(sizeof(rc_proc_t));
     pNewrc->m_pAnal = analNew();        /* Construct a configuration analyser */
-    pNewrc->m_pScript = scriptNew();    /* Construct a run-command script     */
     analParse(pNewrc->m_pAnal);         /* Preprocess the anal configuration  */
+    pNewrc->m_pScriptcom = scriptNew(); /* Construct a run-command script     */
+
+    /* Logic needed for multiple run-command section combination with priorities */
+    pNewrc->m_ppScriptvec = malloc(sizeof(rc_script_t *) * pNewrc->m_pAnal->m_nRcs);
+    for (nIter = 0; nIter < pNewrc->m_pAnal->m_nRcs; nIter++)
+        pNewrc->m_ppScriptvec[nIter] = scriptNew();
 
     return(pNewrc);
 }
@@ -72,19 +78,17 @@
 ************************************************/
 rc_return_t procPopulate(rc_proc_t *pRc)
 {
-    int i         = 0;
-    int nFdrc     = 0;
-    int nFdfunc   = 0;
-    int nRet      = 0;
-    int nRept     = 0;
-    int nIter     = 0;
+    int i       = 0;
+    int nFdrc   = 0;
+    int nFdfunc = 0;
+    int nRet    = 0;
+    int nIter   = 0;
     ex_t Except;
 
     char         *sBuf        = NULL;
     rc_section_t *pSec        = NULL;
     char         *szLocex     = NULL;
     rc_script_t  *pTempscript = NULL;
-    rc_script_t  **ppParts    = NULL;
 
     assert(*pRc->m_pAnal->m_szRcs);
     sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
@@ -97,25 +101,20 @@
     }
 
     /* Stick on the starting shell id line */
-    scriptAppend(pRc->m_pScript, "#! /bin/sh\n", strlen("#! /bin/sh\n"));
+    scriptAppend(pRc->m_pScriptcom, "#! /bin/sh\n", strlen("#! /bin/sh\n"));
 
     /* Read the func file if it was opened successfully */
     /* We unfortunately make the assumption that 0 is an invalid filedesc */
     if (nFdfunc) {
         /* Read data from the func file */
         while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
-            scriptAppend(pRc->m_pScript, sBuf, nRet);
+            scriptAppend(pRc->m_pScriptcom, sBuf, nRet);
         }
-        scriptAppend(pRc->m_pScript, "\n", sizeof(char));
+        scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
         if (nRet == -1) /* Handle read errors */
             RC_THROW(RC_ERR_IO);
     }
 
-    /* Logic needed for multiple section combination with priorities */
-    ppParts = malloc(sizeof(rc_script_t *) * pRc->m_pAnal->m_nRcs);
-    for (nRept = 0; nRept < pRc->m_pAnal->m_nRcs; nRept++)
-        ppParts[nRept] = scriptNew();
-
     /* Iteratively read possibly globbed rc files */
     for (nIter = 0; nIter < pRc->m_pAnal->m_nRcs; nIter++)
     {
@@ -143,8 +142,8 @@
             /* Append config section if it exists */
             pSec = scriptSection(pTempscript, configGetval(RC_NCF_VAL));
             if (pSec) { /* Only operate if the section lookup succeeds */
-                scriptAppend(pRc->m_pScript, sectionGetdata(pSec), strlen(sectionGetdata(pSec)));
-                scriptAppend(pRc->m_pScript, "\n", sizeof(char));
+                scriptAppend(pRc->m_pScriptcom, sectionGetdata(pSec), strlen(sectionGetdata(pSec)));
+                scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
                 sectionDelete(pSec);    /* Cleanup */
                 pSec = NULL;            /* Cleanup */
             }
@@ -155,9 +154,9 @@
                 pSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[i]);
 
                 if (pSec) { /* Only call if the section lookup succeeds */
-                    scriptAppend(pRc->m_pScript, sectionGetdata(pSec),
+                    scriptAppend(pRc->m_ppScriptvec[nIter], sectionGetdata(pSec),
                         sectionGetlen(pSec) - 1);
-                    scriptAppend(pRc->m_pScript, "\n", sizeof(char));
+                    scriptAppend(pRc->m_ppScriptvec[nIter], "\n", sizeof(char));
                 }
                 else if (configGetval(RC_DBG_VAL)) /* Only show if debug set */
                     fprintf(stderr, "#Warning: Missing section '%s' in %s!\n",\
@@ -182,16 +181,6 @@
     close(nFdfunc);     /* Close Func file handle */
 
     /* Memory cleanups */
-    if (ppParts) {
-        for (nRept = pRc->m_pAnal->m_nRcs - 1; nRept >= 0 ; nRept--) {
-            if (ppParts[nRept]) {
-                free(ppParts[nRept]);
-                ppParts[nRept] = NULL;
-            }
-        }
-        free(ppParts);
-        ppParts = NULL;
-    }
     if (sBuf) {
         free(sBuf);
         sBuf = NULL;
@@ -206,6 +195,7 @@
 ************************************************/
 rc_return_t procRun(rc_proc_t *pRc)
 {
+    int   nIter = 0;
     char *pszVec[RC_EXEC_MAXARGS];
 
     /****************************************************/
@@ -214,19 +204,24 @@
     /* Eval  - Print machine evaluatable format         */
     /* Print - Print human readable format              */
     /****************************************************/
-    if (configGetval(RC_EVL_VAL))        /* Evaluate */
+    if (configGetval(RC_EVL_VAL))                              /* Evaluate */
         fprintf(stderr, "Error: Evaluate is not implemented yet.\n"); /* FIX */
-    else if (configGetval(RC_EXC_VAL)) { /* Execute  */
+    else if (configGetval(RC_EXC_VAL)) {                       /* Execute  */
             pszVec[0] = "/bin/sh";
             pszVec[1] = "-c";
-            pszVec[2] = (char *)scriptTostring(pRc->m_pScript);
+            pszVec[2] = (char *)scriptTostring(pRc->m_pScriptcom);
             pszVec[3] = NULL;   /* Add a NULL to mark the end of the chain */
-        if (execvp(*pszVec, pszVec) == -1)  /* launch                   */
+        if (execvp(*pszVec, pszVec) == -1)                       /* launch */
             TRACE("Bad, execvp in child returned -1");
     }
-    else if (configGetval(RC_PRN_VAL))   /* Print */
-        scriptDump(pRc->m_pScript);
-    else                                        /* Something is wrong here */
+    else if (configGetval(RC_PRN_VAL)) {                         /* Print  */
+        scriptDump(pRc->m_pScriptcom);
+        for (nIter = 0; nIter < pRc->m_pAnal->m_nRcs; nIter++) {
+            if (*pRc->m_ppScriptvec[nIter])
+                scriptDump(pRc->m_ppScriptvec[nIter]);
+        }
+    }
+    else /* Something is wrong here */
         return(RC_THROW(RC_ERR_INT));
 
     return(RC_THROW(RC_OK));
@@ -238,9 +233,20 @@
 ************************************************/
 rc_return_t procDelete(rc_proc_t *pRc)
 {
-    scriptDelete(pRc->m_pScript);   /* Destroy the script        */
-    analDelete(pRc->m_pAnal);       /* Destroy the analyser      */
-    free(pRc);                      /* Free the processor itself */
+    int nIter = 0;
+
+    /* Destroy the script vector */
+    for (nIter = pRc->m_pAnal->m_nRcs - 1; nIter >= 0 ; nIter--) {
+        if (pRc->m_ppScriptvec[nIter]) {
+            scriptDelete(pRc->m_ppScriptvec[nIter]);
+            pRc->m_ppScriptvec[nIter] = NULL;
+        }
+    }
+    free(pRc->m_ppScriptvec);
+    pRc->m_ppScriptvec = NULL;
+    scriptDelete(pRc->m_pScriptcom);    /* Destroy the script        */
+    analDelete(pRc->m_pAnal);           /* Destroy the analyser      */
+    free(pRc);                          /* Free the processor itself */
 
     return(RC_THROW(RC_OK));
 }

CVSTrac 2.0.1