--- rc_proc.c 2003/05/21 15:24:07 1.31
+++ rc_proc.c 2003/05/22 14:46:33 1.32
@@ -196,6 +196,7 @@
int nSecs = 0; /* Section index */
char *szTmpfile = NULL; /* Path of temporary file */
char *szTmp = NULL; /* Generic temporary string */
+ char *szCom = NULL; /* Stores common script text */
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 */
@@ -263,10 +264,7 @@
else if (configGetval(RC_EXC_VAL)) { /* Execute */
/* 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);
- szExec = malloc((strlen(szTmp) + 1) * sizeof(char));
- strcpy(szExec, szTmp);
+ szCom = (char *)scriptTostring(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;
@@ -280,27 +278,31 @@
ppSectmp[nRcs] = NULL;
}
qsort((void *)ppSectmp, (size_t)pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *), priCompare);
- nTmp = 0;
+ pszVec[0] = "/bin/sh"; /* Run the bourne shell over the following */
+ pszVec[1] = "-c"; /* Append script code of the sections */
+ pszVec[3] = NULL; /* Add a NULL to mark the end of the chain */
+ nTmp = 0; /* Count from zero until however many sections we have */
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 */
+ szExec = malloc(strlen(szCom) * sizeof(char) + \
+ (strlen(szTmp) + 1) * sizeof(char));
+ strcpy(szExec, szCom); /* Start out with just the common script code */
+ strcat(szExec, szTmp); /* And build a section onto the command chain */
+ pszVec[2] = szExec; /* Actually launch the new process image now */
+
+/* FIXME: Put the fork in here! */
+ if (execvp(*pszVec, pszVec) == -1) { /* launch */
+ TRACE("Bad, execvp for common script in child returned -1");
+ return(RC_THROW(RC_ERR_INT));
+ }
+
+ free(szExec); /* Cleanup after exec */
+ szExec = NULL;
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 */
/* Allocate a block of section pointers to use as a temporary */
|