Index: ossp-pkg/rc/00TODO RCS File: /v/ossp/cvs/ossp-pkg/rc/00TODO,v rcsdiff -q -kk '-r1.21' '-r1.22' -u '/v/ossp/cvs/ossp-pkg/rc/00TODO,v' 2>/dev/null --- 00TODO 2002/02/28 18:24:04 1.21 +++ 00TODO 2002/04/11 16:52:45 1.22 @@ -27,6 +27,8 @@ If a variable is defined for which no default exists, warn user (Scholli.) Make own config, get rid of val because it doesn't hold strings. Write interlocking increment for thread-safe increments. + Convert some normal assert() to real runtime checks. + Use str_hash von ossp str or static RC_XXX_VAL array from rc_option.h. Detailed ;-) project plan ------------------------- Index: ossp-pkg/rc/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/rc/Makefile.in,v rcsdiff -q -kk '-r1.20' '-r1.21' -u '/v/ossp/cvs/ossp-pkg/rc/Makefile.in,v' 2>/dev/null --- Makefile.in 2002/04/09 17:06:17 1.20 +++ Makefile.in 2002/04/11 16:52:45 1.21 @@ -59,11 +59,11 @@ TARGET_PROGS = rc TARGET_MANS = rc.1 rc-sample.5 -SRCS = rc.c rc_config.c rc_optimpl.c rc_option.c\ - rc_cliopt.c rc_opt.c rc_version.c rc_pcre.c rc_util.c +SRCS = rc.c rc_config.c rc_cliopt.c \ + rc_version.c rc_pcre.c rc_util.c -OBJS = rc.o rc_config.o rc_optimpl.o rc_option.o\ - rc_cliopt.o rc_opt.o rc_version.o rc_pcre.o rc_util.o +OBJS = rc.o rc_config.o rc_cliopt.o \ + rc_version.o rc_pcre.o rc_util.o SUBDIRS = @SUBDIR_EX@ @SUBDIR_POPT@ #SUBDIRS = @SUBDIR_EX@ @SUBDIR_VAR@ @SUBDIR_VAL@ @SUBDIR_STR@ @SUBDIR_POPT@ Index: ossp-pkg/rc/rc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.c,v rcsdiff -q -kk '-r1.17' '-r1.18' -u '/v/ossp/cvs/ossp-pkg/rc/rc.c,v' 2>/dev/null --- rc.c 2002/03/26 17:11:06 1.17 +++ rc.c 2002/04/11 16:52:45 1.18 @@ -30,36 +30,36 @@ #include #include -#include - #include "rc.h" +#include "rc_const.h" #include "rc_private.h" -/*TRACE("Vor configLoad."); -TRACEL((long)configGetvers()); -TRACE("Nach configLoad."); -TRACEL((long)configGetvers());*/ - int main(int argc, char *argv[]) { ex_t Except; - int bCaught = 0; ex_try { configConstruct(); configLoad(argc, argv); + /* Processing the runcommands */ +/* procOpen(szRcfilist, szFuncfilist, szTmpfile); + procConf(szEnvass, szSecdef, szSecref, szSecparm); + procParse(); + procSec(szUmask, szUser, szGroup); + procEval(szSection1, szSection2, ...);*/ + configDestruct(); } ex_catch(Except) { - bCaught = 1; + if ((int)Except.ex_value == RC_CNF_VRS) + fprintf(stdout, "This is OSSP rc, version %s\n", RC_VERSION); + 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); exit(1); /* Failure */ } - if (!bCaught) - fprintf(stderr, "main: No exceptions caught.\n"); - configDestruct(); /* Possibly destruct the configuration */ +TRACE("No exceptions caught"); exit(0); /* Success */ } Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.16' '-r1.17' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2002/04/09 17:06:17 1.16 +++ rc.h 2002/04/11 16:52:45 1.17 @@ -48,6 +48,7 @@ /* RC return codes */ typedef enum { RC_OK, /* Success */ + RC_CNF_VRS, /* User requested version */ RC_ERR_USE, /* Usage error */ RC_ERR_MEM, /* Memory error */ RC_ERR_SYS, /* System error (see errno) */ @@ -59,35 +60,37 @@ rc_return_t optionProcess(void); rc_return_t optionProcess(void); -/* File option function prototypes */ -rc_return_t foptParse(void); -rc_return_t foptProcess(void); - -/* Environment option function prototypes */ -rc_return_t eoptParse(void); -rc_return_t eoptProcess(void); - -/* Command line option function prototypes */ -rc_return_t coptParse(int, char **); -rc_return_t coptProcess(int); - /* Config function prototypes */ rc_return_t configConstruct(void); rc_return_t configLoad(int, char **); rc_return_t configDestruct(void); /* Config accessor prototypes */ -short configGetvers(void); +const char *configGetoptval(rc_opt_t); /* Command line function prototypes */ rc_return_t clioptConstruct(void); +/*FIXME rc_return_t clioptRemnode(rc_bintup_t **); + rc_return_t clioptRemallimp(rc_bintup_t **); + rc_return_t clioptRemall(void); + rc_return_t clioptAppnode(const char *, const char *);*/ +rc_return_t clioptProcess(int); +rc_return_t clioptParse(int, char **); rc_return_t clioptDestruct(void); /* Command line accessor prototypes */ -short clioptGetvers(void); +const char *clioptGetval(rc_opt_t); +const char *clioptSummarize(void); -/* Option accessor prototypes */ -short optGetvers(void); + /* Option function prototypes */ + /*FIXME rc_return_t optConstruct(rc_opt_t **); + rc_return_t optDestruct(rc_opt_t **);*/ + + /* Option accessor prototypes */ + /*FIXME rc_return_t optGetname(rc_opt_t *, char **); + rc_return_t optGetval(rc_opt_t *, char **); + rc_return_t optSetname(rc_opt_t *, const char *); + rc_return_t optSetval(rc_opt_t *, const char *);*/ /* Utility (nonbounded) function prototypes */ char *strErr(rc_return_t); Index: ossp-pkg/rc/rc.pod RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.pod,v rcsdiff -q -kk '-r1.29' '-r1.30' -u '/v/ossp/cvs/ossp-pkg/rc/rc.pod,v' 2>/dev/null --- rc.pod 2002/03/01 22:48:23 1.29 +++ rc.pod 2002/04/11 16:52:45 1.30 @@ -1,5 +1,5 @@ ## -## rc.pod -- OSSP Run-command processor (manual page) +## rc.pod -- OSSP Run-command Processor (manual page) ## Copyright (c) 2000-2002 Cable & Wireless Deutschland GmbH ## Copyright (c) 2000-2002 The OSSP Project ## Copyright (c) 2000-2002 Ralf S. Engelschall @@ -27,7 +27,7 @@ =head1 NAME -B - OSSP Runcommand Processor +B - OSSP Run-command Processor =head1 SYNOPSIS @@ -68,10 +68,10 @@ =head1 DESCRIPTION -OSSP rc is a runcommand processor. Its primary function is to scan F +OSSP rc is a run-command processor. Its primary function is to scan F script files for B
(s) and run the commands listed in the section(s). -The runcommand processor can alternatively C the commands in human +The run-command processor can alternatively C the commands in human readable format or reformat them for shell C input without executing them. The F files contain variables and the command processor has functionality to query their default, set and effective values. @@ -325,7 +325,7 @@ =head1 SEE ALSO -OSSP rc integrates concepts taken from other runcommand architectures. For +OSSP rc integrates concepts taken from other run-command architectures. For more information, inspect the /etc/rc structures provided by the FreeBSD, Solaris, and Red Hat distributions. @@ -339,7 +339,7 @@ =head1 HISTORY -B is a drop-in replacement for the prototype runcommand facility used +B is a drop-in replacement for the prototype run-command facility used in OpenPKG (http://www.openpkg.org/). The prototype was a slow and less robust Bourne shell script. B is comparitively faster, more robust, and more flexible. This flexibility allows for wider range of use, and B can Index: ossp-pkg/rc/rc_cliopt.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_cliopt.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/rc/rc_cliopt.c,v' 2>/dev/null --- rc_cliopt.c 2002/04/09 17:01:28 1.1 +++ rc_cliopt.c 2002/04/11 16:52:45 1.2 @@ -29,11 +29,53 @@ #include #include +#include #include "rc.h" -#include "rc_cliopt.h" - -static rc_cliopt_t *s_pInst = NULL; /* Singleton cliopt instance */ +#include "rc_const.h" +#include "rc_config.h" +#include "popt.h" /* OSSP popt options library */ + +static char *s_szOptuples[RC_NUMOPTS]; /* Option name value tuples */ +static struct popt_option optionsTable[] = { + /* Long options with short keys but no arguments */ + { RC_USE_NAME, '?', POPT_ARG_NONE, 0, RC_USE_VAL, RC_USE_DESC, NULL }, + { RC_DBG_NAME, 'd', POPT_ARG_NONE, 0, RC_DBG_VAL, RC_DBG_DESC, NULL }, + { RC_VER_NAME, 'V', POPT_ARG_NONE, 0, RC_VER_VAL, RC_VER_DESC, NULL }, + { RC_EVL_NAME, 'e', POPT_ARG_NONE, 0, RC_EVL_VAL, RC_EVL_DESC, NULL }, + { RC_HLP_NAME, 'h', POPT_ARG_NONE, 0, RC_HLP_VAL, RC_HLP_DESC, NULL }, + { RC_INF_NAME, 'i', POPT_ARG_NONE, 0, RC_INF_VAL, RC_INF_DESC, NULL }, + { RC_LBL_NAME, 'l', POPT_ARG_NONE, 0, RC_LBL_VAL, RC_LBL_DESC, NULL }, + { RC_PRN_NAME, 'p', POPT_ARG_NONE, 0, RC_PRN_VAL, RC_PRN_DESC, NULL }, + { RC_SIL_NAME, 's', POPT_ARG_NONE, 0, RC_SIL_VAL, RC_SIL_DESC, NULL }, + { RC_RAW_NAME, 'r', POPT_ARG_NONE, 0, RC_RAW_VAL, RC_RAW_DESC, NULL }, + { RC_VRB_NAME, 'v', POPT_ARG_NONE, 0, RC_VRB_VAL, RC_VRB_DESC, NULL }, + { RC_EXC_NAME, 'x', POPT_ARG_NONE, 0, RC_EXC_VAL, RC_EXC_DESC, NULL }, + + /* Single argument long options with short keys */ + {RC_LOC_NAME, 'L', POPT_ARG_STRING, 0, RC_LOC_VAL, RC_LOC_DESC, "regx"}, + {RC_CNF_NAME, 'c', POPT_ARG_STRING, 0, RC_CNF_VAL, RC_CNF_DESC, "path"}, + {RC_FNC_NAME, 'f', POPT_ARG_STRING, 0, RC_FNC_VAL, RC_FNC_DESC, "path"}, + {RC_QRY_NAME, 'q', POPT_ARG_STRING, 0, RC_QRY_VAL, RC_QRY_DESC, "varx"}, + {RC_TMP_NAME, 't', POPT_ARG_STRING, 0, RC_TMP_VAL, RC_TMP_DESC, "path"}, + + /* Single argument long options without short keys */ + { RC_OWN_NAME, 0, POPT_ARG_STRING, 0, RC_OWN_VAL, RC_OWN_DESC, "user" }, + { RC_GRP_NAME, 0, POPT_ARG_STRING, 0, RC_GRP_VAL, RC_GRP_DESC, "group"}, + { RC_MSK_NAME, 0, POPT_ARG_INT, 0, RC_MSK_VAL, RC_MSK_DESC, "umask"}, + { RC_ASS_NAME, 0, POPT_ARG_STRING, 0, RC_ASS_VAL, RC_ASS_DESC, "regx" }, + { RC_DEF_NAME, 0, POPT_ARG_STRING, 0, RC_DEF_VAL, RC_DEF_DESC, "regx" }, + { RC_REF_NAME, 0, POPT_ARG_STRING, 0, RC_REF_VAL, RC_REF_DESC, "regx" }, + { RC_PRM_NAME, 0, POPT_ARG_STRING, 0, RC_PRM_VAL, RC_PRM_DESC, "regx" }, + { RC_TRM_NAME, 0, POPT_ARG_STRING, 0, RC_TRM_VAL, RC_TRM_DESC, "regx" }, + { RC_NCF_NAME, 0, POPT_ARG_STRING, 0, RC_NCF_VAL, RC_NCF_DESC, "name" }, + { RC_CMN_NAME, 0, POPT_ARG_STRING, 0, RC_CMN_VAL, RC_CMN_DESC, "name" }, + { RC_DFL_NAME, 0, POPT_ARG_STRING, 0, RC_DFL_VAL, RC_DFL_DESC, "name" }, + { RC_ERR_NAME, 0, POPT_ARG_STRING, 0, RC_ERR_VAL, RC_ERR_DESC, "name" }, + + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0 } +}; /*************************************** @@ -42,43 +84,239 @@ ***************************************/ rc_return_t clioptConstruct(void) { - assert(s_pInst == NULL); - s_pInst = malloc(sizeof(s_pInst)); /* Allocate a cliopt instance */ - if (!s_pInst) +/* assert(s_pBintab == NULL); */ /* Error if constructed already */ +/* s_pBintab = malloc(sizeof(*s_pBintab));*/ /* Allocate a cliopt instance */ +/* if (!s_pBintab) return(RC_THROW(RC_ERR_MEM)); + s_pBintab->pOptlist = malloc(sizeof(*s_pBintab->pOptlist));*/ +/*FIXME optConstruct((rc_opt_t **)&s_pBintab->pOptlist->pvData);FIXME*/ +/* s_pBintab->pOptlist->pvData = NULL; + s_pBintab->pOptlist->pvNext = NULL;*/ + + memset(s_szOptuples, NULL, sizeof(s_szOptuples)); + +TRACE("cliopt constructed."); return(RC_THROW(RC_OK)); } /*************************************** -* clioptGetXXXX(void) * -* Command line option accessors * +* clioptGetval(rc_opt_t) * +* Command line option accessor * ***************************************/ -short clioptGetvers(void) +const char *clioptGetval(rc_opt_t Optname) { ex_t Except; - short nVer = 0; - assert(s_pInst); + assert(Optname < RC_NUMOPTS); /* Invalidate if nonexistent option */ ex_try { - + return((const char *)s_szOptuples[Optname]); } ex_catch(Except) { rethrow; } + return (NULL); /* Not reached */ +} + +/*************************************** +* clioptSummarize(void) * +* Command line option summary * +***************************************/ +const char *clioptSummarize(void) +{ + return (NULL); +} + +/*************************************** +* clioptProcess(int) * +* Switch through available options * +* processing the corresponding option * +* and update option table accordingly * +***************************************/ +rc_return_t clioptProcess(int cliOption) +{ + switch (cliOption) { + case RC_USE_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_DBG_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_VER_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_EVL_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_HLP_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_INF_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_LBL_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_PRN_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_SIL_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_RAW_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_VRB_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_EXC_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_LOC_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_CNF_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_FNC_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_QRY_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_TMP_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_OWN_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_GRP_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_MSK_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_ASS_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_DEF_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_REF_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_PRM_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_TRM_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_NCF_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_CMN_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_DFL_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + case RC_ERR_VAL: + s_szOptuples[cliOption] = strdup("1"); + break; + default : + break; + } - return(nVer); + return(RC_THROW(RC_OK)); } /*************************************** +* clioptParse(int, char **) * +* Parse command line options * +***************************************/ +rc_return_t clioptParse(int argc, char *argv[]) +{ + ex_t Except; + char cliOpt = 0; /* For argument parsing */ + char *szCLIBuf = NULL; + popt_context optCon; /* Context for parsing options */ + + optCon = popt_getcontext(NULL, argc, (const char **)argv, optionsTable, 0); + popt_setotheroptionhelp(optCon, "[options] "); + + if (argc < 3) { + popt_printusage(optCon, stderr, 0); + return(RC_THROW(RC_ERR_USE)); + } + + /* Now do options processing */ + while ((cliOpt = popt_getnextopt(optCon)) >= 0) + ex_try { + clioptProcess(cliOpt); + } + ex_catch(Except) { + if ((rc_return_t)Except.ex_value != RC_ERR_USE) + fprintf(stderr, "Nonusage exception: %d\n",\ + (rc_return_t)Except.ex_value); + + 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); + } + + szCLIBuf = (char *)popt_getarg(optCon); + if ((szCLIBuf == NULL)) { + fprintf(stderr, "Please specify at least one rcfile and section.\n"); + popt_printusage(optCon, stderr, 0); + return(RC_THROW(RC_ERR_USE)); + } + + if (cliOpt < -1) { + /* An error occurred during option processing */ + fprintf(stderr, "%s: %s\n", + popt_badoption(optCon, POPT_BADOPTION_NOALIAS), + popt_strerror(cliOpt)); + return(RC_THROW(RC_ERR_INT)); + } + + fprintf(stderr, "Run these commands: %s\n", szCLIBuf); + popt_freecontext(optCon); + return(RC_THROW(RC_OK)); +} +/*************************************** * clioptDestruct(void) * * Destruct a command line option * ***************************************/ rc_return_t clioptDestruct(void) { - assert(s_pInst); - free(s_pInst); /* Deallocate cliopt and */ - s_pInst = NULL; /* clear its reference */ + int i = 0; +/* ex_t Except; + + assert(s_pBintab);*/ /* Error if not constructed */ +/* ex_try { + clioptRemall();*/ /* Removes ALL list nodes */ +/*FIXME optDestruct((rc_opt_t **)&s_pBintab->pOptlist->pvData);FIXME*/ +/* free(s_pBintab->pOptlist);*/ /* Deallocate option list */ +/* free(s_pBintab);*/ /* Deallocate cliopt and */ +/* s_pBintab = NULL;*/ /* clear its reference */ +/* } + ex_catch(Except) { + rethrow; + }*/ + +for (i = 0; i < RC_NUMOPTS; i++) + if (s_szOptuples[i]) + TRACEL(i); + + for (i = 0; i < RC_NUMOPTS; i++) /* Free the tuple */ + s_szOptuples[i] ? free(s_szOptuples[i]) : RC_NOP; /* or do nothing */ + + memset(s_szOptuples, NULL, sizeof(s_szOptuples)); /* Clear tuples */ + +for (i = 0; i < RC_NUMOPTS; i++) + if (s_szOptuples[i]) + TRACE("Problem! Destructor failed!"); +TRACE("cliopt destructed."); return(RC_THROW(RC_OK)); } Index: ossp-pkg/rc/rc_config.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_config.c,v rcsdiff -q -kk '-r1.8' '-r1.9' -u '/v/ossp/cvs/ossp-pkg/rc/rc_config.c,v' 2>/dev/null --- rc_config.c 2002/04/09 17:01:54 1.8 +++ rc_config.c 2002/04/11 16:52:45 1.9 @@ -31,12 +31,9 @@ #include #include "rc.h" -#include "rc_private.h" #include "rc_const.h" /* String constants */ -#include "rc_config.h" /* Config types and constants */ -#include "rc_option.h" /* Option operations rely on popt */ -static rc_config_t *s_pInst = NULL; /* Singleton config instance */ +static int s_nLocks = 0; /* Server locks, not thread-safe FIXME */ /*************************************** @@ -47,36 +44,38 @@ { ex_t Except; - if (s_pInst == NULL) { /* If we don't have one */ - s_pInst = malloc(sizeof(s_pInst)); /* yet, then allocate */ - if (!s_pInst) /* a config instance */ - return(RC_THROW(RC_ERR_MEM)); - s_pInst->m_nLocks = 0; - - ex_try { - clioptConstruct(); /* Make a config instance */ + if (s_nLocks == 0) { /* If we don't have one yet */ + ex_try { /* then construct a new one */ + clioptConstruct(); /* Member cliopt instance */ } ex_catch(Except) { rethrow; } } - s_pInst->m_nLocks++; /* FIXME not threadsafe */ + s_nLocks++; /* FIXME not threadsafe */ return(RC_THROW(RC_OK)); } /*************************************** -* configGetXXXX(void) * +* configGetoptval(rc_opt_t) * * Configuration accessors * ***************************************/ -short configGetvers(void) +const char *configGetoptval(rc_opt_t Optname) { ex_t Except; - short nVer = 0; + char *szTemp = NULL; - if (s_pInst != NULL) { + if (s_nLocks) { /* Make sure config exists */ ex_try { - + if ((szTemp = (char *)clioptGetval(Optname))) + return((const char *)szTemp); +/* else if (szTemp = envoptGetval(Optname)) + return((const char *)szTemp); + else if (szTemp = cnfoptGetval(Optname)) + return((const char *)szTemp);*/ + else + return(NULL); /* Special case when not found */ } ex_catch(Except) { rethrow; @@ -84,10 +83,8 @@ } else { RC_THROW(RC_ERR_USE); - return(NULL); } - - return(nVer); + return(NULL); /* Not reached */ } /************************************************ @@ -98,13 +95,10 @@ { ex_t Except; - ex_try { /* Parse through each type of option */ -/* FIXME s_pInst->pOpt will hold a copy of the command line */ -// coptParse(s_pInst->pOpt); /* First priority options */ -// eoptParse(s_pInst->pOpt); /* Medium priority options */ -// foptParse(s_pInst->pOpt); /* Low priority options */ - coptParse(argc, argv); /* FIXME Patch for now */ -/* FIXME s_pInst->pOpt will hold a copy of the command line */ + ex_try { /* Parse option groups in order of priority */ + clioptParse(argc, argv); /* Command line options */ +/* envoptParse(s_nLocks->pOpt);*/ /* Environment options */ +/* cnfoptParse(s_nLocks->pOpt);*/ /* Configfile options */ } ex_catch(Except) { rethrow; @@ -127,17 +121,12 @@ { ex_t Except; - if (s_pInst) { - if (--s_pInst->m_nLocks == 0) { /* If m_nLocks is 0, dealloc */ - ex_try { /* FIXME, not thread-safe */ - clioptDestruct(); - } - ex_catch(Except) { - rethrow; - } - - free(s_pInst); /* Deallocate config and */ - s_pInst = NULL; /* clear its reference */ + if (--s_nLocks == 0) { /* If m_nLocks is 0, deallocate */ + ex_try { /* FIXME, not thread-safe */ + clioptDestruct(); + } + ex_catch(Except) { + rethrow; } } else Index: ossp-pkg/rc/rc_config.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_config.h,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/rc/rc_config.h,v' 2>/dev/null --- rc_config.h 2002/04/09 17:01:29 1.1 +++ rc_config.h 2002/04/11 16:52:45 1.2 @@ -24,17 +24,43 @@ ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** -** rc_config.h: Run-command processor ISO C public API header file +** rc_config.h: Run-command processor ISO C public header file */ #ifndef __OSSPRC_CONFIG_H__ #define __OSSPRC_CONFIG_H__ -#include "rc_cliopt.h" /* Command line option */ +/* Available options and their values */ +#define RC_USE_VAL 0 +#define RC_DBG_VAL 1 +#define RC_VER_VAL 2 +#define RC_EVL_VAL 3 +#define RC_HLP_VAL 4 +#define RC_INF_VAL 5 +#define RC_LBL_VAL 6 +#define RC_PRN_VAL 7 +#define RC_SIL_VAL 8 +#define RC_RAW_VAL 9 +#define RC_VRB_VAL 10 +#define RC_EXC_VAL 11 +#define RC_LOC_VAL 12 +#define RC_CNF_VAL 13 +#define RC_FNC_VAL 14 +#define RC_QRY_VAL 15 +#define RC_TMP_VAL 16 +#define RC_OWN_VAL 17 +#define RC_GRP_VAL 18 +#define RC_MSK_VAL 19 +#define RC_ASS_VAL 20 +#define RC_DEF_VAL 21 +#define RC_REF_VAL 22 +#define RC_PRM_VAL 23 +#define RC_TRM_VAL 24 +#define RC_NCF_VAL 25 +#define RC_CMN_VAL 26 +#define RC_DFL_VAL 27 +#define RC_ERR_VAL 28 -typedef struct { /* Main rc configuration storage */ - rc_cliopt_t *pCliopt; /* Aggregate command line option */ - int m_nLocks; /* Server locks, not thread-safe FIXME */ -} rc_config_t; +#define RC_NUMOPTS 29 /* Increment with each option addition */ #endif /* __OSSPRC_CONFIG_H__ */ Index: ossp-pkg/rc/rc_const.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_const.h,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/rc/rc_const.h,v' 2>/dev/null --- rc_const.h 2002/03/26 17:11:06 1.3 +++ rc_const.h 2002/04/11 16:52:45 1.4 @@ -103,4 +103,7 @@ #define RC_ERRSTR_INT "Internal" #define RC_ERRSTR_UNK "Unrecognized" +/* FIXME Tie to shtool generation */ +#define RC_VERSION "77.77" + #endif /* __OSSPRC_CONST_H__ */ Index: ossp-pkg/rc/rc_opt.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_opt.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/rc/rc_opt.c,v' 2>/dev/null --- rc_opt.c 2002/04/09 17:06:17 1.2 +++ rc_opt.c 2002/04/11 16:52:45 1.3 @@ -29,18 +29,95 @@ #include #include +#include #include "rc.h" #include "rc_opt.h" /*************************************** -* optGetXXXX(void) * +* optConstruct(rc_opt_t **) * +* Construct an option * +***************************************/ +rc_return_t optConstruct(rc_opt_t **ppOption) +{ + assert(*ppOption == NULL); /* Error if constructed already */ + *ppOption = malloc(sizeof(**ppOption)); /* Allocate an option instance */ + if (!*ppOption) + return(RC_THROW(RC_ERR_MEM)); + + (*ppOption)->szName = NULL; /* We don't know how much to */ + (*ppOption)->szVal = NULL; /* allocate, so do it later */ + + return(RC_THROW(RC_OK)); +} + +/*************************************** +* optGetXXXX(rc_opt_t *, char **) * * Option accessors * ***************************************/ -short optGetvers(void) +rc_return_t optGetname(rc_opt_t *pOption, char **pszName) { - short nVer = 0; + assert(pOption && pOption->szName); + if (!(*pszName = strdup(pOption->szName))) /* Get name from option */ + return(RC_THROW(RC_ERR_MEM)); + else + return(RC_THROW(RC_OK)); +} + +rc_return_t optGetval(rc_opt_t *pOption, char **pszVal) +{ + assert(pOption && pOption->szVal); + if (!(*pszVal = strdup(pOption->szVal))) /* Get value from option */ + return(RC_THROW(RC_ERR_MEM)); + else + return(RC_THROW(RC_OK)); +} + +/*************************************** +* optSetXXXX(rc_opt_t *, const char *) * +* Option accessors * +***************************************/ +rc_return_t optSetname(rc_opt_t *pOption, const char *cszName) +{ + if (pOption->szName) /* Guard against leaks */ + free(pOption->szName); /* if resetting name */ + if (!(pOption->szName = strdup(cszName))) /* Set name of option */ + return(RC_THROW(RC_ERR_MEM)); + else + return(RC_THROW(RC_OK)); +} + +rc_return_t optSetval(rc_opt_t *pOption, const char *cszVal) +{ + if (pOption->szVal) /* Guard against leaks */ + free(pOption->szVal); /* if resetting value */ + if (!(pOption->szVal = strdup(cszVal))) /* Set value of option */ + return(RC_THROW(RC_ERR_MEM)); + else + return(RC_THROW(RC_OK)); +} + +/*************************************** +* optDestruct(rc_opt_t **) * +* Destruct a command line option * +***************************************/ +rc_return_t optDestruct(rc_opt_t **ppOption) +{ + ex_t Except; + + assert(*ppOption); /* Error if not constructed */ + ex_try { + if ((*ppOption)->szName) /* Might not be mallocd yet */ + free((*ppOption)->szName); + if ((*ppOption)->szVal) /* Might not be mallocd yet */ + free((*ppOption)->szVal); + free(*ppOption); /* Deallocate option and */ + *ppOption = NULL; /* clear its reference */ + } + ex_catch(Except) { + rethrow; + } - return(nVer); + return(RC_THROW(RC_OK)); } Index: ossp-pkg/rc/rc_private.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_private.h,v rcsdiff -q -kk '-r1.9' '-r1.10' -u '/v/ossp/cvs/ossp-pkg/rc/rc_private.h,v' 2>/dev/null --- rc_private.h 2002/04/09 17:01:54 1.9 +++ rc_private.h 2002/04/11 16:52:45 1.10 @@ -38,16 +38,18 @@ #include #ifndef DEBUG #define NDEBUG -#define TRACE(str) ((void)0) -#define TRACEL(long) ((void)0) +#define TRACE(str) ((void)0) +#define TRACEL(num) ((void)0) #else #define TRACE(str) fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, str) -#define TRACEL(long) fprintf(stderr, "%s:%d: %ld\n", __FILE__, __LINE__, long) +#define TRACEL(num) fprintf(stderr, "%s:%d: %ld\n", __FILE__, __LINE__, (long int)num) #endif /* The GUID for OSSP rc */ #define RC_STR_ID "OSSP rc" +/* Intentional no operation */ +#define RC_NOP ((void)0) /* Memory debugging support */ #if defined(HAVE_DMALLOC_H) && defined(WITH_DMALLOC) @@ -60,9 +62,6 @@ ((rv) != RC_OK && (ex_catching && !ex_shielding) \ ? (ex_throw(RC_STR_ID, NULL, (rv)), (rv)) : (rv)) -typedef struct { /* Simple linked list definition */ - void *pvData; - void *pvNext; -} rc_list_t; +typedef int rc_opt_t; /* For use with RC_XXX_VAL definitions */ #endif /* __OSSPRC_PRIVATE_H__ */ Index: ossp-pkg/rc/rc_test.sh RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v' 2>/dev/null --- rc_test.sh 2002/03/26 17:11:06 1.6 +++ rc_test.sh 2002/04/11 16:52:45 1.7 @@ -29,23 +29,17 @@ # Test short options, should fail for false combination usage ./rc -dVehilpsrvxLcfqt samba start sleep=2 restart -echo # Test short options, should succeed ./rc -derv -L /sfw/etc/rc.d/rc.%{RCFILE:s/^all$/*/} -c /sfw/etc/rc.conf -f /sfw/etc/rc.func -t /tmp openssh stop sleep=4 start daily minsize=2097152 -echo # Test some long options, should fail for false combination usage ./rc --verbose --silent uucp stop sleep=6 start -echo ./rc --query --silent zebra bing bang -echo ./rc --conf /sfw/rc.conf --locate /sfw/etc/rc.d --query what to enter here -echo # Test minimal set of long options, should succeed ./rc --debug --version rsyncd nothing matters but the version -echo # FIXME these cases are not handled yet by our configuration FIXME # #./rc --debug --version @@ -61,9 +55,7 @@ # FIXME these cases are not handled yet by our configuration FIXME # ./rc --func /sfw/etc/rc.func --print --verbose openssh stop sleep=4 start -echo ./rc --func /sfw/etc/rc.func --debug --eval uucp restart -echo ./rc --conf ./myrc --func /sfw/etc/rc.func --tmp /tmp --debug --silent --exec uucp start # Next milestone