--- rc_proc.c 2003/05/20 17:14:17 1.28
+++ rc_proc.c 2003/05/21 12:49:21 1.29
@@ -91,7 +91,7 @@
/* 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) {
+ if ((nFdfunc = open(pRc->m_pAnal->m_szFuncs, O_RDONLY)) < 0) {
RC_THROW(RC_ERR_FNC);
}
}
@@ -99,17 +99,13 @@
/* Stick on the starting shell id line */
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_pScriptcom, sBuf, nRet);
- }
- scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
- if (nRet == -1) /* Handle read errors */
- RC_THROW(RC_ERR_IO);
+ /* Read data from the func file */
+ while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
+ scriptAppend(pRc->m_pScriptcom, sBuf, nRet);
}
+ 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++)
@@ -194,13 +190,16 @@
************************************************/
rc_return_t procRun(rc_proc_t *pRc)
{
- int nTmp = 0; /* Generic index */
- int nRcs = 0; /* Rc index */
- int nSecs = 0; /* Section index */
- char *szTmp = NULL; /* Generic temporary string */
- char *szExec = NULL; /* Used only during exec mode */
- char *pszVec[RC_EXEC_MAXARGS]; /* For passing in to execv(3) */
- rc_section_t **ppSectmp = NULL; /* Used with priority scheduling */
+ int nTmp = 0; /* Generic index */
+ int nTmpname = 0; /* Temp file name size */
+ int nRcs = 0; /* Rc index */
+ int nSecs = 0; /* Section index */
+ char *szTmpfile = NULL; /* Path of temporary file */
+ char *szTmp = NULL; /* Generic temporary string */
+ char *szExec = NULL; /* Used only during exec mode */
+ char *pszVec[RC_EXEC_MAXARGS]; /* For passing in to execv(3) */
+ rc_script_t *pFatscript = NULL; /* To build a comprehensive script */
+ rc_section_t **ppSectmp = NULL; /* Used with priority scheduling */
/****************************************************/
/* This will execute, evaluate, or print the script */
@@ -208,10 +207,51 @@
/* Eval - Print machine evaluatable format */
/* Print - Print human readable format */
/****************************************************/
- if (configGetval(RC_EVL_VAL)) /* Evaluate */
- fprintf(stderr, "Error: Evaluate is not implemented yet.\n"); /* FIX */
+ if (configGetval(RC_EVL_VAL)) { /* Evaluate */
+ /* Allocate a block of section pointers to use temporarily */
+ ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
+ /* Allocate the command chain string to execute with execv(3) */
+ pFatscript = scriptCopy(pRc->m_pScriptcom);
+ for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
+ for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
+ nTmp = 0;
+ while (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs && \
+ strcmp(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]->m_szName, \
+ pRc->m_pAnal->m_pszSecs[nSecs]))
+ nTmp++;
+ if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs)
+ ppSectmp[nRcs] = pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp];
+ else
+ ppSectmp[nRcs] = NULL;
+ }
+ qsort((void *)ppSectmp, (size_t)pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *), priCompare);
+ nTmp = 0;
+ while (nTmp < pRc->m_pAnal->m_nRcs && ppSectmp[nTmp]) {
+ szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
+ scriptAppend(pFatscript, szTmp, strlen(szTmp) + 1);
+ nTmp++;
+ }
+ }
+ free(ppSectmp);
+ ppSectmp = NULL;
+
+ szTmpfile = (char *)configGetval(RC_TMP_VAL);
+ nTmpname = (strlen(szTmpfile) + strlen(RC_EVL_TMP) + \
+ strlen(RC_EVL_SUF) + 1) * sizeof(char);
+ szTmpfile = malloc(nTmpname);
+ strcpy(szTmpfile, configGetval(RC_TMP_VAL));
+ strcat(szTmpfile, RC_EVL_TMP);
+ mktemp(szTmpfile);
+ strcat(szTmpfile, RC_EVL_SUF);
+ scriptWrite(pFatscript, szTmpfile); /* Write the whole script out */
+ fprintf(stdout, RC_EVL_OUT, szTmpfile, szTmpfile);
+ free(szTmpfile);
+ szTmpfile = NULL;
+ scriptDelete(pFatscript);
+ pFatscript = NULL;
+ }
else if (configGetval(RC_EXC_VAL)) { /* Execute */
- /* Allocate a block of section pointers to use as a temporary */
+ /* Allocate a block of section pointers to use temporarily */
ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
/* Allocate the command chain string to execute with execv(3) */
szTmp = (char *)scriptTostring(pRc->m_pScriptcom);
|