Index: ossp-pkg/rc/00TODO RCS File: /v/ossp/cvs/ossp-pkg/rc/00TODO,v rcsdiff -q -kk '-r1.46' '-r1.47' -u '/v/ossp/cvs/ossp-pkg/rc/00TODO,v' 2>/dev/null --- 00TODO 2003/06/04 10:48:15 1.46 +++ 00TODO 2003/06/12 13:27:44 1.47 @@ -63,6 +63,7 @@ Use OSSP cfg library for dotconf parsing, ask Ralf to help. Make rc_section_t correspond to rc_section.c with own operators. Make consistent, sectionGetdata and scriptTostring should have same names + Add printVerbal() to section class, removing 'if (configGetval(RC_VRB_VAL))' Implementation Correct assertion, sanity check, and if () checks according to one standard. Index: ossp-pkg/rc/rc_const.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_const.h,v rcsdiff -q -kk '-r1.21' '-r1.22' -u '/v/ossp/cvs/ossp-pkg/rc/rc_const.h,v' 2>/dev/null --- rc_const.h 2003/06/11 16:18:48 1.21 +++ rc_const.h 2003/06/12 13:27:44 1.22 @@ -41,6 +41,9 @@ #define RC_EXN_TEXT "# Executing section %s of script %s.\n" #define RC_PRN_TEXT "# Printing section %s of script %s.\n" +/* Single word user text, should not include termination */ +#define RC_CMN_TEXT "common" + /* Option descriptions used with popt, should not include termination */ #define RC_USE_DESC "Print a short usage summary, then exit." #define RC_DBG_DESC "Don't remove temporary files, and write debug messages to stderr." @@ -124,6 +127,9 @@ #define RC_GLOB_WILD "all" +/* Nontranslatable machine strings, do not translate */ +#define RC_ECHO_STR "echo " + /* Default values, do not include newlines and special chars must be escaped */ #define RC_DEF_ON "1" /* Digital switch */ #define RC_DEF_OFF "0" /* Digital switch */ Index: ossp-pkg/rc/rc_proc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v rcsdiff -q -kk '-r1.42' '-r1.43' -u '/v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v' 2>/dev/null --- 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++; }