Index: ossp-pkg/rc/00TODO RCS File: /v/ossp/cvs/ossp-pkg/rc/00TODO,v rcsdiff -q -kk '-r1.26' '-r1.27' -u '/v/ossp/cvs/ossp-pkg/rc/00TODO,v' 2>/dev/null --- 00TODO 2002/06/26 14:11:16 1.26 +++ 00TODO 2002/06/28 17:43:23 1.27 @@ -41,6 +41,7 @@ Remove redundant method prototypes in main header file. Relocate rc_anal_t and other to approproate header files rc_anal.h. I think rc_anal is violating the singleton configuration. + Totally remove warnings from the exception logic Detailed ;-) project plan ------------------------- Index: ossp-pkg/rc/rc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.c,v rcsdiff -q -kk '-r1.34' '-r1.35' -u '/v/ossp/cvs/ossp-pkg/rc/rc.c,v' 2>/dev/null --- rc.c 2002/06/28 14:20:23 1.34 +++ rc.c 2002/06/28 17:43:23 1.35 @@ -40,26 +40,31 @@ { ex_t Except; - ex_try { /* Configuration block */ + try { /* Configuration block */ configNew(); /* Construct a new configuration */ configLoad(argc, (const char **)argv); /* Load cli, env, and conf */ configVerify(); /* Test for usage, help, and version options */ } - ex_catch(Except) { /* Exceptions of the configuration block */ + catch(Except) { /* Exceptions of the configuration block */ if ((rc_return_t)Except.ex_value == RC_WRN_TRM) exit(0); else if ((rc_return_t)Except.ex_value == RC_ERR_USE) clioptPrintusage(); - else { - fprintf(stderr, "Class '%s' threw exception %d in %s:%s():%d.\n",\ - (char *)Except.ex_class, (int)Except.ex_value,\ - Except.ex_file, Except.ex_func, Except.ex_line); + else + if (FAILED((rc_return_t)Except.ex_value)) { /* Error condition */ + fprintf(stderr, " Error condition in proc, class '%s',\n exception %d in %s:%s():%d.\n", (char *)Except.ex_class, (int)Except.ex_value, Except.ex_file, Except.ex_func, Except.ex_line); + exit(1); /* Return failure */ } - if (FAILED((rc_return_t)Except.ex_value)) /* NOP on warnings */ - exit(1); /* Report failure and exit the program */ +#ifdef DEBUG + else /* Warning condition */ + fprintf(stderr, " Warning condition in proc, class '%s',\n exception %d in %s:%s():%d.\n", (char *)Except.ex_class, (int)Except.ex_value, Except.ex_file, Except.ex_func, Except.ex_line); +#else + else /* Warning condition */ + RC_NOP; /* No operation on warnings */ +#endif } - ex_try { /* Main processing block, the script is built here */ + try { /* Main processing block, the script is built here */ rc_proc_t *pProc = NULL; pProc = procNew(); /* Construct a new processor, build script */ procPopulate(pProc); /* Populate with run commands */ @@ -67,16 +72,25 @@ procDelete(pProc); /* Destroy the processor */ configDelete(); /* Destroy the configuration */ } - ex_catch(Except) { /* Error exceptions thrown during script processing */ - TRACE("Also, exception dans le processor bloque"); - if (FAILED((rc_return_t)Except.ex_value)) { /* NOP on warnings */ - fprintf(stderr, "Class '%s' threw exception %d in %s:%s():%d.\n",\ - (char *)Except.ex_class, (int)Except.ex_value,\ - Except.ex_file, Except.ex_func, Except.ex_line); + catch(Except) { /* Error exceptions thrown during script processing */ + if (FAILED((rc_return_t)Except.ex_value)) { /* Error condition */ + if ((rc_return_t)Except.ex_value == RC_ERR_FNC) + fprintf(stderr, " Error condition, function file could not be opened.\n"); + else if ((rc_return_t)Except.ex_value == RC_ERR_DIR) + fprintf(stderr, " Error condition, location dir could not be opened.\n"); + else if ((rc_return_t)Except.ex_value == RC_ERR_RCF) + fprintf(stderr, " Error condition, rc file could not be opened.\n"); + else + fprintf(stderr, " Error condition in proc, class '%s',\n exception %d in %s:%s():%d.\n", (char *)Except.ex_class, (int)Except.ex_value, Except.ex_file, Except.ex_func, Except.ex_line); exit(1); /* Return failure */ } - else +#ifdef DEBUG + else /* Warning condition */ + fprintf(stderr, " Warning condition in proc, class '%s',\n exception %d in %s:%s():%d.\n", (char *)Except.ex_class, (int)Except.ex_value, Except.ex_file, Except.ex_func, Except.ex_line); +#else + else /* Warning condition */ RC_NOP; /* No operation on warnings */ +#endif } exit(0); /* Return success */ Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.32' '-r1.33' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2002/06/28 14:20:23 1.32 +++ rc.h 2002/06/28 17:43:23 1.33 @@ -59,10 +59,13 @@ RC_ERR_SYS = 5, /* System error (see errno) */ RC_ERR_IO = 6, /* Input/output error */ RC_ERR_INT = 7, /* Internal error */ - RC_WRN_0 = 8, /* Warning base */ - RC_WRN_OWR = 9, /* Overwrite warning */ - RC_WRN_NUL = 10, /* NULL pointer warning */ - RC_WRN_TRM = 11 /* Request to terminate app */ + RC_ERR_FNC = 8, /* Func file not found */ + RC_ERR_DIR = 9, /* Location dir not found */ + RC_ERR_RCF = 10, /* Rc file not found */ + RC_WRN_0 = 11, /* Warning base */ + RC_WRN_OWR = 12, /* Overwrite warning */ + RC_WRN_NUL = 13, /* NULL pointer warning */ + RC_WRN_TRM = 14 /* Request to terminate app */ } rc_return_t; /* Config function prototypes */ @@ -109,7 +112,7 @@ /* Script function prototypes */ rc_script_t *scriptNew(void); rc_return_t scriptAppend(rc_script_t *, char *, size_t); -const char *scriptSection(rc_script_t *, const char *); +char *scriptSection(rc_script_t *, const char *); rc_return_t scriptDump(rc_script_t *); rc_return_t scriptDelete(rc_script_t *); Index: ossp-pkg/rc/rc_anal.c RCS File: /v/ossp/cvs/ossp-pkg/rc/Attic/rc_anal.c,v rcsdiff -q -kk '-r1.7' '-r1.8' -u '/v/ossp/cvs/ossp-pkg/rc/Attic/rc_anal.c,v' 2>/dev/null --- rc_anal.c 2002/06/28 14:20:23 1.7 +++ rc_anal.c 2002/06/28 17:43:23 1.8 @@ -55,20 +55,27 @@ ************************************************/ rc_return_t analRcs(rc_anal_t **ppInst, const char *kszName) { + ex_t Except; + assert(!(*ppInst)->m_szRcs); /* Rcs should be NULL until we set them */ - if (!kszName) { - (*ppInst)->m_szRcs = NULL; -/* RC_THROW(RC_WRN_NUL);*/ - } + if (!kszName) + return(RC_THROW(RC_ERR_RCF)); else { /* Only enter block with valid string, strdup can't handle NULL */ (*ppInst)->m_szRcs = malloc(sizeof(char **)); if (strcmp(kszName, RC_GLOB_WILD)) { - *(*ppInst)->m_szRcs = strdup("rc."); + *(*ppInst)->m_szRcs = strdup("rc."); /* FIXME: Remove hardcoded */ strcat(*(*ppInst)->m_szRcs, kszName); } - else /* Wildcard rcfile indicates we must glob the locs directories */ - analGloblocs(ppInst); + else { /* Wildcard rcfile indicates we must glob the locs directories */ + try { + analGloblocs(ppInst); + } + catch(Except) { +fprintf(stderr, "Placeholder until ex_ looping bug is fixed.\n"); +/* rethrow;*/ /* FIXME: Ralf! Looping problem with ex_ hier! */ + } + } } return(RC_THROW(RC_OK)); @@ -117,10 +124,16 @@ if (!kszPathexpr) { (*ppInst)->m_szLocs = NULL; (*ppInst)->m_szLocs = strdup("./"); /* FIXME: Relocate default val */ -/* RC_THROW(RC_WRN_NUL);*/ +/* RC_THROW(RC_WRN_NUL);*/ /* FIXME: ex_ Illegal instruction - core dumped */ } else { /* Only enter block with valid string, strdup can't handle NULL */ - (*ppInst)->m_szLocs = strdup(kszPathexpr); + if (*(kszPathexpr + strlen(kszPathexpr)) != '/') { + (*ppInst)->m_szLocs = malloc(strlen(kszPathexpr) + 2 * sizeof(char)); + strcpy((*ppInst)->m_szLocs, kszPathexpr); + strcat((*ppInst)->m_szLocs, "/"); + } + else + (*ppInst)->m_szLocs = strdup(kszPathexpr); } return(RC_THROW(RC_OK)); @@ -179,6 +192,10 @@ pppFiles = malloc(sizeof(struct dirent)); nCount = scandir((*ppInst)->m_szLocs, pppFiles, analFileselect, alphasort); + /* Check out the health of this directory */ + if (nCount == -1) + return(RC_THROW(RC_ERR_DIR)); + /* Loop through file index setting Rf file names according to dirent */ for (nIter = 0; nIter < nCount; ++nIter) (*ppInst)->m_szRcs[nIter] = strdup((*pppFiles)[nIter]->d_name); @@ -209,10 +226,8 @@ analFuncs(&pInst, configGetval(RC_FNC_VAL)); analSecs (&pInst, configGetsecs()); } - ex_catch(Except) { -TRACE("Parsing broke"); -/* rethrow;*/ - } + ex_catch(Except) + rethrow; return(RC_THROW(RC_OK)); } Index: ossp-pkg/rc/rc_proc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v rcsdiff -q -kk '-r1.7' '-r1.8' -u '/v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v' 2>/dev/null --- rc_proc.c 2002/06/28 14:20:23 1.7 +++ rc_proc.c 2002/06/28 17:43:23 1.8 @@ -72,6 +72,7 @@ ************************************************/ rc_return_t procPopulate(rc_proc_t *pRc) { + int i = 0; int nFdrc = 0; int nFdfunc = 0; int nRet = 0; @@ -83,13 +84,11 @@ assert(*pRc->m_pAnal->m_szRcs); sBuf = (char *)calloc(1, RC_READ_BUFSIZE); - pTempscript = scriptNew(); /* 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) { - /* RC_THROW(RC_ERR_IO);*/ - fprintf(stderr, "Problem with procPopulate open(2) of %s\n", pRc->m_pAnal->m_szFuncs); + RC_THROW(RC_ERR_FNC); } } @@ -101,35 +100,51 @@ scriptAppend(pRc->m_pScript, sBuf, nRet); } if (nRet == -1) /* Handle read errors */ - TRACE("Problem with procPopulate read(2)"); - /* RC_THROW(RC_ERR_IO);*/ + RC_THROW(RC_ERR_IO); } /* Iteratively read possibly globbed rc files */ for (nIter = 0; pRc->m_pAnal->m_szRcs[nIter]; nIter++) { + assert(*pRc->m_pAnal->m_szRcs); /* If one of these assertions fail, */ + assert(pRc->m_pAnal->m_szLocs); /* you've probably seen the ex_ bug */ + + /* Build the path name */ szLocex = (char *)malloc(strlen(pRc->m_pAnal->m_szLocs) + strlen(pRc->m_pAnal->m_szRcs[nIter]) + 2); strcpy(szLocex, pRc->m_pAnal->m_szLocs); strcat(szLocex, pRc->m_pAnal->m_szRcs[nIter]); /* Open the rc file unconditionally */ - if ((nFdrc = open(szLocex, O_RDONLY)) == -1) { - /* RC_THROW(RC_ERR_IO);*/ - fprintf(stderr, "Problem with procPopulate open(2) of %s\n", szLocex); - } + if ((nFdrc = open(szLocex, O_RDONLY)) == -1) + RC_THROW(RC_ERR_RCF); /* Read data from the rc file into a temporary script */ + pTempscript = scriptNew(); while ((nRet = read(nFdrc, sBuf, RC_READ_BUFSIZE)) > 0) scriptAppend(pTempscript, sBuf, nRet); + if (nRet == -1) /* Handle read errors */ - TRACE("Problem with procPopulate read(2)"); - /* RC_THROW(RC_ERR_IO);*/ + RC_THROW(RC_ERR_IO); - /* Extract a section from the temp script, and append it to other one */ - szSec = scriptSection(pTempscript, "start"); /* Extract section */ - scriptAppend(pRc->m_pScript, szSec, strlen(szSec)); /* Append section */ + for (i = 0; pRc->m_pAnal->m_pszSecs[i]; i++) { /* Iterate over secvec */ + /* Extract a section from the temp script, and append it */ + szSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[i]); + + if (szSec) /* Only call append if the section lookup succeeded */ + scriptAppend(pRc->m_pScript, szSec, strlen(szSec)); + else + fprintf(stderr, "#Warning: Missing section '%s' in %s!\n", pRc->m_pAnal->m_pszSecs[i], pRc->m_pAnal->m_szRcs[nIter]); + + if (szSec) { /* Cleanup section string */ + free(szSec); + szSec = NULL; + } + } - free(szLocex); /* Free our temporarily constructed Location + Rcfile */ + /* Clean up our crap */ + scriptDelete(pTempscript); /* Temp script */ + pTempscript = NULL; + free(szLocex); /* Temp Location + Rcfile */ szLocex = NULL; close(nFdrc); /* Close Rc file handle */ } @@ -137,15 +152,10 @@ close(nFdfunc); /* Close Func file handle */ /* Memory cleanups */ - scriptDelete(pTempscript); if (sBuf) { free(sBuf); sBuf = NULL; } - if (szSec) { - free(szSec); - szSec = NULL; - } return(RC_THROW(RC_OK)); } Index: ossp-pkg/rc/rc_script.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_script.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/rc/rc_script.c,v' 2>/dev/null --- rc_script.c 2002/06/28 14:20:23 1.2 +++ rc_script.c 2002/06/28 17:43:23 1.3 @@ -98,23 +98,31 @@ * scriptSection(rc_script_t *, const char *) * * Parse a script for a given section * ************************************************/ -const char *scriptSection(rc_script_t *pScript, const char *kszSecname) +char *scriptSection(rc_script_t *pScript, const char *kszSecname) { char *szTempout = NULL; char *szTmpsec = NULL; char *piStart = NULL; char *piEnd = NULL; + assert(pScript); /* Check for a valid incoming script */ szTmpsec = malloc(strlen(kszSecname) + sizeof(char)); strcpy(szTmpsec, "%"); strcat(szTmpsec, kszSecname); piStart = strstr(*pScript, szTmpsec); /* Find start of section */ + if (!piStart) /* Short circuit if the */ + return(NULL); /* section was not found */ + piStart = strstr(piStart, "\n") + sizeof(char); /* Wrap to next line */ piEnd = strstr(piStart + sizeof(char), "%"); /* FIXME: Remove hardcoded */ - szTempout = malloc(piEnd - piStart + sizeof(char)); - strncpy(szTempout, piStart, piEnd - piStart); - *(szTempout + (piEnd - piStart)) = NULL; /* Terminate the outgoing string */ + if (piEnd) { + szTempout = malloc(piEnd - piStart + sizeof(char)); + strncpy(szTempout, piStart, piEnd - piStart); + *(szTempout + (piEnd - piStart)) = NULL; /* Terminate outgoing string */ + } + else /* We are operating on the last section of the file */ + szTempout = strdup(piStart); /* FIXME: Can we assume '\0' at EOF? */ return(szTempout); } Index: ossp-pkg/rc/rc_test.sh RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v rcsdiff -q -kk '-r1.12' '-r1.13' -u '/v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v' 2>/dev/null --- rc_test.sh 2002/06/27 15:35:58 1.12 +++ rc_test.sh 2002/06/28 17:43:23 1.13 @@ -28,12 +28,12 @@ # test_rc.sh: Run-command processor test script # Test short options, should fail for false combination usage -echo "./rc -dvef rcfunc/rc.func -hilpsrvxLcqt samba start sleep=2 restart" -./rc -dVef rcfunc/rc.func -hilpsrvxLcqt samba start sleep=2 restart +#echo "./rc -dvef rcfunc/rc.func -hilpsrvxLcqt samba start sleep=2 restart" +#./rc -dVef rcfunc/rc.func -hilpsrvxLcqt samba start sleep=2 restart # Test short options, should succeed -echo; echo "./rc -derv -L /u/ms/ossp/rc/rcdings/rcfiles/rc.%{RCFILE:s/^all$/*/} -c /u/ms/ossp/rc/rcdings/rc.conf -f /u/ms/ossp/rc/rcfunc/rc.func -t /tmp openssh stop sleep=4 start daily minsize=2097152" -./rc -derv -L /u/ms/ossp/rc/rcdings/rcfiles/rc.d/rc.%{RCFILE:s/^all$/*/} -c /u/ms/ossp/rc/rcdings/rc.conf -f /u/ms/ossp/rc/rcfunc/rc.func -t /tmp openssh stop sleep=4 start daily minsize=2097152 +#echo; echo "./rc -derv -L /u/ms/ossp/rc/rcdings/rcfiles/rc.%{RCFILE:s/^all$/*/} -c /u/ms/ossp/rc/rcdings/rc.conf -f /u/ms/ossp/rc/rcfunc/rc.func -t /tmp openssh stop sleep=4 start daily minsize=2097152" +#./rc -derv -L /u/ms/ossp/rc/rcdings/rcfiles/rc.d/rc.%{RCFILE:s/^all$/*/} -c /u/ms/ossp/rc/rcdings/rc.conf -f /u/ms/ossp/rc/rcfunc/rc.func -t /tmp openssh stop sleep=4 start daily minsize=2097152 # Test some long options, should fail for false combination usage echo; echo "./rc --verbose --silent uucp stop sleep=6 start" @@ -72,8 +72,21 @@ ./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func --tmp /tmp --debug --exec ntp sync echo; echo "./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func --tmp /tmp --debug --silent --exec ralf feed suppe" ./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func --tmp /tmp --debug --silent --exec ralf feed suppe +echo; echo "./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func +-L /u/ms/ossp/rc/rcfiles/ --tmp /tmp --silent --exec samba search finish destroy" +./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /u/ms/ossp/rc/rcfiles/ --tmp /tmp --silent --exec samba search finish destroy + echo; echo "./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /u/ms/ossp/rc/rcfiles/ --tmp /tmp --silent --exec all feed suppe" -./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /u/ms/ossp/rc/rcfiles/ --tmp /tmp --silent --exec all feed suppe +./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /u/ms/ossp/rc/rcfiles/ --tmp /tmp --silent --exec all go feed suppe + +echo; echo "./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /sw/etc/rc.d --tmp /tmp --silent --debug --exec all config barf gag" +./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /sw/etc/rc.d --tmp /tmp --silent --debug --exec all config barf gag + +echo; echo "./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /sw/etc/rc.d --tmp /tmp --silent --debug --exec all config start" +./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /sw/etc/rc.d --tmp /tmp --silent --debug --exec all config start + +echo; echo "./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /sw/etc/rc.d --tmp /tmp --silent --debug --exec pam info" +./rc --conf rcdings/myrc.conf --func /u/ms/ossp/rc/rcfunc/rc.func -L /sw/etc/rc.d --tmp /tmp --silent --debug --exec pam info # Next milestone #RequireOwner