OSSP CVS Repository

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

Check-in Number: 3358
Date: 2003-May-21 17:24:07 (local)
2003-May-21 15:24:07 (UTC)
User:ms
Branch:
Comment: Fix parsing of func file, and do not read if the func file doesn't exist.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc_proc.c      1.30 -> 1.31     15 inserted, 15 deleted

ossp-pkg/rc/rc_proc.c 1.30 -> 1.31

--- rc_proc.c    2003/05/21 15:16:41     1.30
+++ rc_proc.c    2003/05/21 15:24:07     1.31
@@ -75,8 +75,8 @@
 rc_return_t procPopulate(rc_proc_t *pRc)
 {
     int nSect   = 0;
-    int nFdrc   = 0;
-    int nFdfunc = 0;
+    int nFdrc   = -1;
+    int nFdfunc = -1;
     int nRet    = 0;
     int nRc     = 0;
     ex_t Except;
@@ -89,23 +89,23 @@
     assert(*pRc->m_pAnal->m_szRcs);
     sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
 
-    /* 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)) < 0) {
-            RC_THROW(RC_ERR_FNC);
-        }
-    }
-
     /* Stick on the starting shell id line */
     scriptAppend(pRc->m_pScriptcom, "#! /bin/sh\n", strlen("#! /bin/sh\n"));
 
-    /* Read data from the func file */
-    while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
-        scriptAppend(pRc->m_pScriptcom, sBuf, nRet);
+    /* 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)) >= 0) {
+            /* Read data from the func file */
+            while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
+                scriptAppend(pRc->m_pScriptcom, sBuf, nRet);
+            }
+            if (nRet == -1) /* Handle read errors */
+                RC_THROW(RC_ERR_IO);
+            scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
+        }
+        else
+            RC_THROW(RC_ERR_FNC);
     }
-    scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
-    if (nRet == -1) /* Handle read errors */
-        RC_THROW(RC_ERR_IO);
 
     /* Iteratively read possibly globbed rc files */
     for (nRc = 0; nRc < pRc->m_pAnal->m_nRcs; nRc++)

CVSTrac 2.0.1