--- rc_proc.c 2003/06/11 16:18:48 1.42
+++ rc_proc.c 2003/06/12 13:27:44 1.43
@@ -191,6 +191,7 @@
rc_return_t procRun(rc_proc_t *pRc)
{
int nTmp = 0; /* Generic index */
+ size_t nBytes = 0; /* Size in bytes */
int nTmpname = 0; /* Temp file name size */
int nRcs = 0; /* Rc index */
int nSecs = 0; /* Section index */
@@ -201,6 +202,7 @@
char *szTmp = NULL; /* Generic temporary string */
char *szCom = NULL; /* Stores common script text */
char *szExec = NULL; /* Used only during exec mode */
+ char *szVerbose = NULL; /* Used when handling verbose 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 */
@@ -214,8 +216,17 @@
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);
+ pFatscript = scriptNew();
+ /* Conditionally print common section notice in verbal mode */
+ if (configGetval(RC_VRB_VAL)) {
+ nBytes = (strlen(RC_PRN_TEXT) + strlen(RC_CMN_TEXT) * 2 + 1) * sizeof (char);
+ szVerbose = malloc(nBytes);
+ sprintf(szVerbose, RC_PRN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
+ scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
+ free(szVerbose);
+ }
+ scriptAppend(pFatscript, scriptTostring(pRc->m_pScriptcom), \
+ strlen(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;
@@ -232,12 +243,11 @@
sizeof(rc_section_t *), priCompare);
nTmp = 0;
while (nTmp < pRc->m_pAnal->m_nRcs && ppSectmp[nTmp]) {
+ /* Conditionally print each section notice in verbal mode */
if (configGetval(RC_VRB_VAL)) {
- size_t nBytes = 0;
- char *szVerbose = NULL;
szTmp = (char *)sectionGetname(ppSectmp[nTmp]);
nBytes = (strlen(RC_EVN_TEXT) + strlen(szTmp) + 1) * sizeof (char);
- szVerbose = malloc (nBytes);
+ szVerbose = malloc(nBytes);
sprintf(szVerbose, RC_EVN_TEXT, szTmp, szTmp);
scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
free(szVerbose);
@@ -313,34 +323,90 @@
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 = 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 */
+ /* Conditionally print common and other section notices in verbal mode */
+ if (configGetval(RC_VRB_VAL)) {
+ size_t nComverb = 0;
+ size_t nCommon = 0;
+ size_t nSecverb = 0;
+ size_t nSection = 0;
+ nComverb = (strlen(RC_EXN_TEXT) + strlen(RC_CMN_TEXT) * 2 \
+ + strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
+ szVerbose = malloc(nComverb);
+ sprintf(szVerbose, RC_EXN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
+ nCommon = (strlen(szCom) + 1) * sizeof (char);
+ szExec = malloc(nComverb + nCommon);
+ strcpy(szExec, RC_ECHO_STR); /* Start out with the echo string */
+ strcat(szExec, "\""); /* Append a quote next to the echo */
+ strcat(szExec, szVerbose); /* Continue with the verboseity text */
+ strcat(szExec, "\""); /* Finalize the verbosity notice */
+ strcat(szExec, szCom); /* Then with the common script code */
+ szTmp = (char *)sectionGetname(ppSectmp[nTmp]);
+ nSecverb = (strlen(RC_EXN_TEXT) + strlen(szTmp) * 2 \
+ + strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
+ realloc(szVerbose, nSecverb);
+ sprintf(szVerbose, RC_EXN_TEXT, szTmp, szTmp);
+ szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
+ nSection = (strlen(szTmp) + 1) * sizeof (char);
+ realloc(szExec, nComverb + nCommon + nSecverb + nSection);
+ strcat(szExec, RC_ECHO_STR); /* Start out with the echo string */
+ strcat(szExec, "\""); /* Append a quote next to the echo */
+ strcat(szExec, szVerbose); /* Continue with the verboseity text */
+ strcat(szExec, "\""); /* Finalize the verbosity notice */
+ strcat(szExec, szTmp); /* Then with the new script code */
+ pszVec[2] = szExec; /* Launch the new process image now */
+ free(szVerbose);
+ szVerbose = NULL;
- /* Spawn the section shell code */
- switch (Pidexec = fork()){
- case -1: /* Broken */
- return(RC_THROW(RC_ERR_INT));
- break; /* Huh? */
- case 0: /* Child, runs script code through bourne shell */
- nSectuid = sectionGetuid(ppSectmp[nTmp]);
- if (nSectuid >= 0 && getuid() != nSectuid)
- if (setuid(nSectuid) != 0)
- return(RC_THROW(RC_ERR_INT));
- if (execvp(*pszVec, pszVec) == -1)
+ /* Spawn the section shell code */
+ switch (Pidexec = fork()){
+ case -1: /* Broken */
return(RC_THROW(RC_ERR_INT));
- break;
- default: /* Parent, blocks until child returns */
- waitpid(Pidexec, NULL, WUNTRACED);
- break;
+ break; /* Huh? */
+ case 0: /* Child, runs script code through bourne shell */
+ nSectuid = sectionGetuid(ppSectmp[nTmp]);
+ if (nSectuid >= 0 && getuid() != nSectuid)
+ if (setuid(nSectuid) != 0)
+ return(RC_THROW(RC_ERR_INT));
+ if (execvp(*pszVec, pszVec) == -1)
+ return(RC_THROW(RC_ERR_INT));
+ break;
+ default: /* Parent, blocks until child returns */
+ waitpid(Pidexec, NULL, WUNTRACED);
+ break;
+ }
+ if (szExec) {
+ free(szExec); /* Cleanup after exec */
+ szExec = NULL;
+ }
}
+ else {
+ szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
+ szExec = malloc((strlen(szCom) + 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 */
- free(szExec); /* Cleanup after exec */
- szExec = NULL;
- nTmp++;
+ /* Spawn the section shell code */
+ switch (Pidexec = fork()){
+ case -1: /* Broken */
+ return(RC_THROW(RC_ERR_INT));
+ break; /* Huh? */
+ case 0: /* Child, runs script code through bourne shell */
+ nSectuid = sectionGetuid(ppSectmp[nTmp]);
+ if (nSectuid >= 0 && getuid() != nSectuid)
+ if (setuid(nSectuid) != 0)
+ return(RC_THROW(RC_ERR_INT));
+ if (execvp(*pszVec, pszVec) == -1)
+ return(RC_THROW(RC_ERR_INT));
+ break;
+ default: /* Parent, blocks until child returns */
+ waitpid(Pidexec, NULL, WUNTRACED);
+ break;
+ }
+ free(szExec); /* Cleanup after exec */
+ szExec = NULL;
+ }
+ nTmp++; /* Next rc script */
}
}
free(ppSectmp);
@@ -349,6 +415,14 @@
else if (configGetval(RC_PRN_VAL)) { /* Print */
/* Allocate a block of section pointers to use as a temporary */
ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
+ /* Conditionally print common section notice in verbal mode */
+ if (configGetval(RC_VRB_VAL)) {
+ nBytes = (strlen(RC_PRN_TEXT) + strlen(RC_CMN_TEXT) * 2 + 1) * sizeof (char);
+ szVerbose = malloc(nBytes);
+ sprintf(szVerbose, RC_PRN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
+ fprintf(stderr, "%s", szVerbose);
+ free(szVerbose);
+ }
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++) {
@@ -365,6 +439,15 @@
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]) {
+ /* Conditionally print each section notice in verbal mode */
+ if (configGetval(RC_VRB_VAL)) {
+ szTmp = (char *)sectionGetname(ppSectmp[nTmp]);
+ nBytes = (strlen(RC_PRN_TEXT) + strlen(szTmp) + 1) * sizeof (char);
+ szVerbose = malloc(nBytes);
+ sprintf(szVerbose, RC_PRN_TEXT, szTmp, szTmp);
+ fprintf(stderr, "%s", szVerbose);
+ free(szVerbose);
+ }
sectionDump(ppSectmp[nTmp]);
nTmp++;
}
|