OSSP CVS Repository

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

ossp-pkg/rc/rc_proc.c 1.5 -> 1.6

--- rc_proc.c    2002/06/26 14:42:53     1.5
+++ rc_proc.c    2002/06/27 15:35:58     1.6
@@ -75,53 +75,60 @@
     int nFdrc     = 0;
     int nFdfunc   = 0;
     int nRet      = 0;
+    int nIter     = 0;
     char *szBuf   = NULL;
+    char *szLocex = NULL;
 
-    char *szFucka = NULL;
-
-    /* FIXME: Do not hardcode location or prefix! */
-    szFucka = (char *)malloc(strlen(pRc->m_pAnal->m_szRcs) + 8);
-    strcpy(szFucka, "rcfiles/rc.");
-    strcat(szFucka, pRc->m_pAnal->m_szRcs);
-
+    assert(*pRc->m_pAnal->m_szRcs);
     szBuf = (char *)calloc(0, RC_READ_BUFSIZE);
 
-    /* Open the rc file unconditionally */
-    if ((nFdrc = open(szFucka, O_RDONLY)) == -1) {
-/*        RC_THROW(RC_ERR_IO);*/
-        TRACE("Problem with procPopulate open(2)");
-    }
-
-    /* Open the func file if it belongs to the configuration */
+    /* 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);*/
-        TRACE("Problem with procPopulate open(2)");
+            fprintf(stderr, "Problem with procPopulate open(2) of %s\n", pRc->m_pAnal->m_szFuncs);
+        }
+    }
+
+    /* Keep reading possibly globbed rc files until there are none left */
+    for (nIter = 0; pRc->m_pAnal->m_szRcs[nIter]; nIter++)
+    {
+        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);
+        }
+
+        /* 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, szBuf, RC_READ_BUFSIZE)) > 0)
+                scriptAppend(pRc->m_pScript, szBuf, nRet);
+            if (nRet == -1) /* Handle read errors */
+                TRACE("Problem with procPopulate read(2)");
+        /*        RC_THROW(RC_ERR_IO);*/
         }
-        /* Read data from the func file */
-        while ((nRet = read(nFdfunc, szBuf, RC_READ_BUFSIZE)) > 0)
+
+        /* Read data from the rc file */
+        while ((nRet = read(nFdrc, szBuf, RC_READ_BUFSIZE)) > 0)
             scriptAppend(pRc->m_pScript, szBuf, nRet);
         if (nRet == -1) /* Handle read errors */
             TRACE("Problem with procPopulate read(2)");
     /*        RC_THROW(RC_ERR_IO);*/
+
+        free(szLocex);  /* Free our temporarily constructed Location + Rcfile */
+        szLocex = NULL;
+        close(nFdrc);   /* Close Rc file handle */
     }
 
-    /* Read data from the rc file */
-    while ((nRet = read(nFdrc, szBuf, RC_READ_BUFSIZE)) > 0)
-        scriptAppend(pRc->m_pScript, szBuf, nRet);
-    if (nRet == -1) /* Handle read errors */
-        TRACE("Problem with procPopulate read(2)");
-/*        RC_THROW(RC_ERR_IO);*/
-
-    /* Filehandle cleanups */
-    close(nFdrc);
-    close(nFdfunc);
+    close(nFdfunc);     /* Close Func file handle */
 
     /* Memory cleanups */
-    if (szFucka) {
-        free(szFucka);
-        szFucka = NULL;
-    }
     if (szBuf) {
         free(szBuf);
         szBuf = NULL;
@@ -136,10 +143,10 @@
 ************************************************/
 rc_return_t procRun(rc_proc_t *pRc)
 {
-    
     if (configGetval(RC_DBG_VAL)) /* Dump the running config table */
         configDebug();            /* if debug switch is turned on  */
 
+    /* This will print the script to a hardcoded dump device, probably stderr */
     scriptDump(pRc->m_pScript);
 
     return(RC_THROW(RC_OK));

CVSTrac 2.0.1