Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.30' '-r1.31' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2002/06/26 14:42:53 1.30 +++ rc.h 2002/06/27 15:35:58 1.31 @@ -103,6 +103,7 @@ rc_return_t analFuncs(rc_anal_t **, const char *); rc_return_t analLocs(rc_anal_t **, const char *); rc_return_t analSecs(rc_anal_t **, const char **); +rc_return_t analGloblocs(rc_anal_t **); rc_return_t analParse(rc_anal_t *); /* Script function prototypes */ Index: ossp-pkg/rc/rc_anal.c RCS File: /v/ossp/cvs/ossp-pkg/rc/Attic/rc_anal.c,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/rc/Attic/rc_anal.c,v' 2>/dev/null --- rc_anal.c 2002/06/26 14:11:16 1.5 +++ rc_anal.c 2002/06/27 15:35:58 1.6 @@ -31,7 +31,9 @@ #include #include "rc.h" /* Public interfaces */ +#include "rc_const.h" /* String constants */ #include "rc_config.h" /* Configuration interface */ +#include "rc_anal.h" /* Anal specific headers */ /************************************************ @@ -58,7 +60,14 @@ /* RC_THROW(RC_WRN_NUL);*/ } else { /* Only enter block with valid string, strdup can't handle NULL */ - (*ppInst)->m_szRcs = strdup(kszName); + (*ppInst)->m_szRcs = malloc(sizeof(char **)); + if (strcmp(kszName, RC_GLOB_WILD)) { + *(*ppInst)->m_szRcs = strdup("rc."); + strcat(*(*ppInst)->m_szRcs, kszName); + *((*ppInst)->m_szRcs + sizeof(char **)) = NULL; /* Terminate list */ + } + else /* Wildcard rcfile indicates we must glob the locs directories */ + analGloblocs(ppInst); } return(RC_THROW(RC_OK)); @@ -106,6 +115,7 @@ { if (!kszPathexpr) { (*ppInst)->m_szLocs = NULL; + (*ppInst)->m_szLocs = strdup("./"); /* FIXME: Relocate default val */ /* RC_THROW(RC_WRN_NUL);*/ } else { /* Only enter block with valid string, strdup can't handle NULL */ @@ -138,6 +148,50 @@ return(RC_THROW(RC_OK)); } +/*************************************************************** +* int analFileselect(struct dirent *Direntry) * +* Calculate whether a directory entry belongs to a defined set * +***************************************************************/ +int analFileselect(struct dirent *Direntry) +{ + if ((Direntry->d_name != NULL) && (strncmp(Direntry->d_name, "rc.", 3) == 0)) + return (TRUE); + else if ((strcmp(Direntry->d_name, ".") == 0) || (strcmp(Direntry->d_name, "..") == 0)) + return (FALSE); + else /* Catchall returns false for all not met set conditions */ + return (FALSE); +} + +/************************************************ +* analGloblocs(rc_anal_t **ppInst) * +* Glob all files of the location directories * +************************************************/ +rc_return_t analGloblocs(rc_anal_t **ppInst) +{ + struct dirent ***pppFiles = NULL; + int nIter = 0; + int nCount = 0; + + assert(*ppInst); /* Verify sanity */ + + /* Write the globbed filenames to our anal object */ + pppFiles = malloc(sizeof(struct dirent)); + nCount = scandir((*ppInst)->m_szLocs, pppFiles, analFileselect, alphasort); + + /* 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); + (*ppInst)->m_szRcs[nIter] = NULL; + + /* Cleanup our Dirent object */ + if (pppFiles) { + free(pppFiles); + pppFiles = NULL; + } + + return(RC_THROW(RC_OK)); +} + /************************************************ * analParse(rc_anal_t *) * * Parse the analyzed configuration data * @@ -148,10 +202,10 @@ assert(pInst); /* Verify sanity */ ex_try { /* Read in data from the main configuration */ + analLocs (&pInst, configGetval(RC_LOC_VAL)); analRcs (&pInst, configGetrcfile()); analTmp (&pInst, configGetval(RC_TMP_VAL)); analFuncs(&pInst, configGetval(RC_FNC_VAL)); - analLocs (&pInst, configGetval(RC_LOC_VAL)); analSecs (&pInst, configGetsecs()); } ex_catch(Except) { @@ -168,15 +222,19 @@ ************************************************/ rc_return_t analDelete(rc_anal_t *pInst) { - if (pInst->m_szRcs) /* Rc file names */ + int nIter = 0; + + while (pInst->m_szRcs[nIter]) /* Rc file names */ + free(pInst->m_szRcs[nIter++]); + if (pInst->m_szRcs) /* Rc file name index */ free(pInst->m_szRcs); - if (pInst->m_szTmp) /* Temp file name */ + if (pInst->m_szTmp) /* Temp file name */ free(pInst->m_szTmp); - if (pInst->m_szFuncs) /* Function file names */ + if (pInst->m_szFuncs) /* Function file names */ free(pInst->m_szFuncs); - if (pInst->m_szLocs) /* Location path names */ + if (pInst->m_szLocs) /* Location path names */ free(pInst->m_szLocs); - if (pInst->m_pszSecs) /* Section names */ + if (pInst->m_pszSecs) /* Section names */ vectorDel(pInst->m_pszSecs); free(pInst); Index: ossp-pkg/rc/rc_config.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_config.c,v rcsdiff -q -kk '-r1.18' '-r1.19' -u '/v/ossp/cvs/ossp-pkg/rc/rc_config.c,v' 2>/dev/null --- rc_config.c 2002/06/26 14:42:53 1.18 +++ rc_config.c 2002/06/27 15:35:58 1.19 @@ -191,14 +191,20 @@ int i = 0; char *szTemp = NULL; - m_szSummary = malloc(NULL); + /* Make sure we start with a blank slate */ + if (m_szSummary) { + free(m_szSummary); + m_szSummary = NULL; + } + for (i = 0; i < RC_NUMOPTS; i++) { try { /* FIXME Not threadsafe, wrap with crit section */ if (configGetval(i) == NULL); /* NOP */ else if (!(strcmp(configGetval(i), "1"))) { - szTemp = malloc(strlen(m_szSummary) + strlen(configGetval(i))); - strcpy(szTemp, m_szSummary); + szTemp = calloc(1, (m_szSummary ? strlen(m_szSummary) : 0) + strlen(configGetval(i))); + if (m_szSummary) + strcpy(szTemp, m_szSummary); strcat(szTemp, "Option "); strcat(szTemp, configGetname(i)); strcat(szTemp, " is on.\n"); Index: ossp-pkg/rc/rc_const.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_const.h,v rcsdiff -q -kk '-r1.7' '-r1.8' -u '/v/ossp/cvs/ossp-pkg/rc/rc_const.h,v' 2>/dev/null --- rc_const.h 2002/06/26 14:11:16 1.7 +++ rc_const.h 2002/06/27 15:35:58 1.8 @@ -108,6 +108,6 @@ #define RC_ERRSTR_INT "Internal" #define RC_ERRSTR_UNK "Unrecognized" -#define RC_CONF_WILD "all" +#define RC_GLOB_WILD "all" #endif /* __OSSPRC_CONST_H__ */ Index: ossp-pkg/rc/rc_private.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_private.h,v rcsdiff -q -kk '-r1.15' '-r1.16' -u '/v/ossp/cvs/ossp-pkg/rc/rc_private.h,v' 2>/dev/null --- rc_private.h 2002/06/26 14:11:16 1.15 +++ rc_private.h 2002/06/27 15:35:58 1.16 @@ -71,7 +71,7 @@ /* Analyser type */ typedef struct { - char *m_szRcs; /* Rc file names */ + char **m_szRcs; /* Rc file names */ char *m_szTmp; /* Temp file name */ char *m_szFuncs; /* Function file names */ char *m_szLocs; /* Location path names */ Index: ossp-pkg/rc/rc_proc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v' 2>/dev/null --- rc_proc.c 2002/06/26 14:42:53 1.5 +++ rc_proc.c 2002/06/27 15:35:58 1.6 @@ -75,53 +75,60 @@ int nFdrc = 0; int nFdfunc = 0; int nRet = 0; + int nIter = 0; char *szBuf = NULL; + char *szLocex = NULL; - char *szFucka = NULL; - - /* FIXME: Do not hardcode location or prefix! */ - szFucka = (char *)malloc(strlen(pRc->m_pAnal->m_szRcs) + 8); - strcpy(szFucka, "rcfiles/rc."); - strcat(szFucka, pRc->m_pAnal->m_szRcs); - + assert(*pRc->m_pAnal->m_szRcs); szBuf = (char *)calloc(0, RC_READ_BUFSIZE); - /* Open the rc file unconditionally */ - if ((nFdrc = open(szFucka, O_RDONLY)) == -1) { -/* RC_THROW(RC_ERR_IO);*/ - TRACE("Problem with procPopulate open(2)"); - } - - /* Open the func file if it belongs to the configuration */ + /* 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);*/ - TRACE("Problem with procPopulate open(2)"); + fprintf(stderr, "Problem with procPopulate open(2) of %s\n", pRc->m_pAnal->m_szFuncs); + } + } + + /* Keep reading possibly globbed rc files until there are none left */ + for (nIter = 0; pRc->m_pAnal->m_szRcs[nIter]; nIter++) + { + 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); + } + + /* Read the func file if it was opened successfully */ + /* We unfortunately make the assumption that 0 is an invalid filedesc */ + if (nFdfunc) { + /* Read data from the func file */ + while ((nRet = read(nFdfunc, szBuf, RC_READ_BUFSIZE)) > 0) + scriptAppend(pRc->m_pScript, szBuf, nRet); + if (nRet == -1) /* Handle read errors */ + TRACE("Problem with procPopulate read(2)"); + /* RC_THROW(RC_ERR_IO);*/ } - /* Read data from the func file */ - while ((nRet = read(nFdfunc, szBuf, RC_READ_BUFSIZE)) > 0) + + /* Read data from the rc file */ + while ((nRet = read(nFdrc, szBuf, RC_READ_BUFSIZE)) > 0) scriptAppend(pRc->m_pScript, szBuf, nRet); if (nRet == -1) /* Handle read errors */ TRACE("Problem with procPopulate read(2)"); /* RC_THROW(RC_ERR_IO);*/ + + free(szLocex); /* Free our temporarily constructed Location + Rcfile */ + szLocex = NULL; + close(nFdrc); /* Close Rc file handle */ } - /* Read data from the rc file */ - while ((nRet = read(nFdrc, szBuf, RC_READ_BUFSIZE)) > 0) - scriptAppend(pRc->m_pScript, szBuf, nRet); - if (nRet == -1) /* Handle read errors */ - TRACE("Problem with procPopulate read(2)"); -/* RC_THROW(RC_ERR_IO);*/ - - /* Filehandle cleanups */ - close(nFdrc); - close(nFdfunc); + close(nFdfunc); /* Close Func file handle */ /* Memory cleanups */ - if (szFucka) { - free(szFucka); - szFucka = NULL; - } if (szBuf) { free(szBuf); szBuf = NULL; @@ -136,10 +143,10 @@ ************************************************/ rc_return_t procRun(rc_proc_t *pRc) { - if (configGetval(RC_DBG_VAL)) /* Dump the running config table */ configDebug(); /* if debug switch is turned on */ + /* This will print the script to a hardcoded dump device, probably stderr */ scriptDump(pRc->m_pScript); return(RC_THROW(RC_OK)); Index: ossp-pkg/rc/rc_test.sh RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v rcsdiff -q -kk '-r1.11' '-r1.12' -u '/v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v' 2>/dev/null --- rc_test.sh 2002/06/26 14:11:16 1.11 +++ rc_test.sh 2002/06/27 15:35:58 1.12 @@ -46,8 +46,8 @@ # Test minimal set of long options, should succeed echo; echo "./rc --debug --version rsyncd nothing matters but the version" ./rc --debug --version rsyncd nothing matters but the version -echo; echo "./rc --conf /sfw/rc.conf --locate /cw/etc/rc.d:/u/ms/ossp/rc/rcdings/rcfiles:/etc/rc --query this barf test" -./rc --conf /sfw/rc.conf --locate /cw/etc/rc.d:/u/ms/ossp/rc/rcdings/rcfiles:/etc/rc --query this barf test +echo; echo "./rc --conf /sfw/rc.conf --locate /cw/etc/rc.d:/u/ms/ossp/rc/rcdings/rcfiles:/etc/rc --query all barf test" +./rc --conf /sfw/rc.conf --locate /cw/etc/rc.d:/u/ms/ossp/rc/rcdings/rcfiles:/etc/rc --query all barf test # FIXME these cases are not handled yet by our configuration FIXME # #echo; echo "./rc --debug --version" @@ -72,6 +72,8 @@ ./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 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 # Next milestone #RequireOwner