--- rc_proc.c 2003/05/20 15:06:42 1.27
+++ rc_proc.c 2003/05/20 17:14:17 1.28
@@ -194,15 +194,13 @@
************************************************/
rc_return_t procRun(rc_proc_t *pRc)
{
- int nTmp = 0;
- int nRcs = 0;
- int nSecs = 0;
- char *pszVec[RC_EXEC_MAXARGS];
-
- /* Conditionally sort the section vector according to explicit priority
- if (!strcmp(configGetrcfile(), RC_GLOB_WILD)) {
- qsort((void *)pRc->m_ppSectvec, (size_t)nTotsecs, sizeof (rc_section_t *), priCompare);
- } */
+ 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 */
/****************************************************/
/* This will execute, evaluate, or print the script */
@@ -213,33 +211,52 @@
if (configGetval(RC_EVL_VAL)) /* Evaluate */
fprintf(stderr, "Error: Evaluate is not implemented yet.\n"); /* FIX */
else if (configGetval(RC_EXC_VAL)) { /* Execute */
- pszVec[0] = "/bin/sh";
- pszVec[1] = "-c";
- 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 */
- TRACE("Bad, execvp for common script in child returned -1");
- return(RC_THROW(RC_ERR_INT));
- }
- for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++)
+ /* Allocate a block of section pointers to use as a temporary */
+ 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);
+ szExec = malloc((strlen(szTmp) + 1) * sizeof(char));
+ strcpy(szExec, szTmp);
+ 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) {
- pszVec[2] = (char *)sectionGetdata(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]);
- if (execvp(*pszVec, pszVec) == -1) { /* launch */
- TRACE("Bad, execvp for subsection in child returned -1");
- return(RC_THROW(RC_ERR_INT));
- }
- }
+ 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]);
+ szExec = realloc(szExec, (strlen(szExec) + 1) * sizeof(char) + \
+ (strlen(szTmp) + 1) * sizeof(char));
+ strcat(szExec, szTmp); /* Build onto the command chain */
+ nTmp++;
+ }
+ }
+ free(ppSectmp);
+ ppSectmp = NULL;
+
+ /* Actually launch the new process image now */
+ pszVec[0] = "/bin/sh";
+ pszVec[1] = "-c";
+ pszVec[2] = szExec;
+ pszVec[3] = NULL; /* Add a NULL to mark the end of the chain */
+ if (execvp(*pszVec, pszVec) == -1) { /* launch */
+ TRACE("Bad, execvp for common script in child returned -1");
+ return(RC_THROW(RC_ERR_INT));
+ }
}
else if (configGetval(RC_PRN_VAL)) { /* Print */
- scriptDump(pRc->m_pScriptcom);
- for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++)
+ /* Allocate a block of section pointers to use as a temporary */
+ ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
+ scriptDump(pRc->m_pScriptcom); /* Dump the common script */
+ 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 && \
@@ -247,8 +264,19 @@
pRc->m_pAnal->m_pszSecs[nSecs]))
nTmp++;
if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs)
- sectionDump(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]);
+ 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]) {
+ sectionDump(ppSectmp[nTmp]);
+ nTmp++;
+ }
+ }
+ free(ppSectmp);
+ ppSectmp = NULL;
}
else /* Something is wrong here */
return(RC_THROW(RC_ERR_INT));
|