OSSP CVS Repository

ossp - Check-in [1927]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1927
Date: 2002-Feb-28 19:24:04 (local)
2002-Feb-28 18:24:04 (UTC)
User:ms
Branch:
Comment: Configuration improvements.

PR: Submitted by: Reviewed by: Approved by: Obtained from:

Tickets:
Inspections:
Files:
ossp-pkg/rc/00TODO      1.20 -> 1.21     2 inserted, 0 deleted
ossp-pkg/rc/rc.c      1.14 -> 1.15     9 inserted, 8 deleted
ossp-pkg/rc/rc.h      1.11 -> 1.12     6 inserted, 3 deleted
ossp-pkg/rc/rc_config.c      1.3 -> 1.4     66 inserted, 33 deleted
ossp-pkg/rc/rc_optimpl.c      1.1 -> 1.2     0 inserted, 1 deleted
ossp-pkg/rc/rc_private.h      1.4 -> 1.5     10 inserted, 7 deleted

ossp-pkg/rc/00TODO 1.20 -> 1.21

--- 00TODO       2002/02/08 18:35:03     1.20
+++ 00TODO       2002/02/28 18:24:04     1.21
@@ -25,6 +25,8 @@
   Translate rc bourne shell script to ISO C.
   Finish man page. Start latex or Docbook guide.
   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.
 
 Detailed ;-) project plan
 -------------------------


ossp-pkg/rc/rc.c 1.14 -> 1.15

--- rc.c 2002/02/28 15:30:04     1.14
+++ rc.c 2002/02/28 18:24:04     1.15
@@ -30,22 +30,24 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <string.h>
+
 #include "rc.h"
 #include "rc_private.h"
 
-/* Initialize our global OSSP ex library identifier */
-const char g_szOSSPrc[] = "OSSP rc";
-
 
 int main(int argc, char *argv[])
 {
     ex_t Except;
     int bCaught = 0;
-    rc_config_t *pConf = NULL;
 
     ex_try {
-        configConstruct(&pConf);
-        configLoad(pConf, argc, argv);
+        configConstruct();
+TRACE("Vor configLoad.");
+TRACEL((long)configGetvers());
+        configLoad(argc, argv);
+TRACE("Nach configLoad.");
+TRACEL((long)configGetvers());
     }
     ex_catch(Except) {
         bCaught = 1;
@@ -57,7 +59,6 @@
     if (!bCaught)
         fprintf(stderr, "main: No exceptions caught.\n");
 
-    if (pConf)      /* If a configuration exists, then burn it */
-        configDestruct(pConf);
+    configDestruct(); /* Possibly destruct the configuration */
     exit(0);        /* Success */
 }


ossp-pkg/rc/rc.h 1.11 -> 1.12

--- rc.h 2002/02/28 15:30:04     1.11
+++ rc.h 2002/02/28 18:24:04     1.12
@@ -72,9 +72,12 @@
 rc_return_t coptProcess(char, char *);
 
 /* Config function prototypes */
-rc_return_t configConstruct(rc_config_t **);
-rc_return_t configLoad(rc_config_t *, int, char **);
-rc_return_t configDestruct(rc_config_t *);
+rc_return_t configConstruct(void);
+rc_return_t configLoad(int, char **);
+rc_return_t configDestruct(void);
+
+/* Config accessor prototypes */
+short configGetvers(void);
 
 /* Utility (nonbounded) function prototypes */
 char *strErr(rc_return_t);


ossp-pkg/rc/rc_config.c 1.3 -> 1.4

--- rc_config.c  2002/02/28 15:30:04     1.3
+++ rc_config.c  2002/02/28 18:24:04     1.4
@@ -32,48 +32,76 @@
 
 #include "rc.h"
 #include "rc_private.h"
-#include "rc_const.h"   /* String constants               */
-#include "rc_option.h"  /* Option operations rely on popt */
-#include "val.h"        /* OSSP val library holds config  */
+#include "rc_const.h"               /* String constants                 */
+#include "rc_option.h"              /* Option operations rely on popt   */
+#include "val.h"                    /* OSSP val library holds config    */
+
+static rc_config_t *s_pInst = NULL; /* Singleton configuration instance */
 
 
 /***************************************
-* configConstruct(rc_config_t)         *
+* configConstruct(void)                *
 * Construct a configuration            *
 ***************************************/
-rc_return_t configConstruct(rc_config_t **ppConfig)
+rc_return_t configConstruct(void)
 {
     ex_t Except;
 
-    *ppConfig = malloc(sizeof(rc_config_t));    /* Allocate the    */
-    if (!*ppConfig)                             /* configuration's */
-        return(RC_THROW(RC_ERR_MEM));           /* identity        */
-
-    ex_try {                                    /* Make a val instance  */
-        val_create(&(*ppConfig)->pVal);         /* to hold individual   */
-    }                                           /* configuration values */
-    ex_catch(Except) {
-        rethrow;
+    if (s_pInst == NULL) {                  /* If we don't have one */
+        s_pInst = malloc(sizeof(s_pInst));  /* yet, then allocate   */
+        if (!s_pInst)                       /* a configuration      */
+            return(RC_THROW(RC_ERR_MEM));   /* instance             */
+        s_pInst->nLocks = 0;
+
+        ex_try {                            /* Make a val instance  */
+            val_create(&s_pInst->pVal);     /* to hold individual   */
+        }                                   /* configuration values */
+        ex_catch(Except) {
+            rethrow;
+        }
     }
+    s_pInst->nLocks++;                      /* FIXME not threadsafe */
 
     return(RC_THROW(RC_OK));
 }
 
+/***************************************
+* configGetXXXX(void)                  *
+* Configuration accessors              *
+***************************************/
+short configGetvers(void)
+{
+    ex_t Except;
+    short nVer = 0;
+
+    if (s_pInst != NULL) {
+        ex_try {
+            val_get(s_pInst->pVal, RC_VER_NAME, &nVer);
+        }
+        ex_catch(Except) {
+            rethrow;
+        }
+    }
+    else {
+        RC_THROW(RC_ERR_USE);
+        return(NULL);
+    }
+
+    return(nVer);
+}
+
 /************************************************
-* configLoad(rc_config_t, int, char **)         *
+* configLoad(int, char **)                      *
 * Load a configuration                          *
 ************************************************/
-rc_return_t configLoad(rc_config_t *pConfig, int argc, char *argv[])
+rc_return_t configLoad(int argc, char *argv[])
 {
     ex_t Except;
-    char *pTestopt = NULL;
-    const char *pFuncpath = "/sfw/etc/rc.func";
 
     ex_try {    /* Register and set configuration values */
-        val_reg(pConfig->pVal, RC_FNC_NAME, VAL_TYPE_PTR, RC_FNC_DESC, NULL);
-        val_set(pConfig->pVal, RC_FNC_NAME, pFuncpath);
-        val_get(pConfig->pVal, RC_FNC_NAME, &pTestopt);
-        fprintf(stderr, "Hier!%s!\n", pTestopt);
+        /* FIXME This is real bad, replace with our own  */
+        val_reg(s_pInst->pVal, RC_VER_NAME, VAL_TYPE_SHORT, RC_VER_DESC, NULL);
+        val_set(s_pInst->pVal, RC_VER_NAME, 1);
     }
     ex_catch(Except) {
         rethrow;
@@ -83,23 +111,28 @@
 }
 
 /***************************************
-* configDestruct(rc_config_t)          *
+* configDestruct(void)                 *
 * Destruct a configuration             *
 ***************************************/
-rc_return_t configDestruct(rc_config_t *pConfig)
+rc_return_t configDestruct(void)
 {
     ex_t Except;
 
-    assert(pConfig);
-    free(pConfig);      /* Deallocate configuration */
-    pConfig = NULL;     /* and clear its reference  */
-
-    ex_try {
-        val_destroy(pConfig->pVal); /* Destroy the val instance and assume */
-    }                               /* that its reference is cleared also  */
-    ex_catch(Except) {
-        rethrow;
+    if (s_pInst) {
+        if (!(--s_pInst->nLocks)) {         /* If nLocks is 0, dealloc  */
+            ex_try {                        /* FIXME, not thread-safe   */
+                val_destroy(s_pInst->pVal); /* Destroy val instance and */
+            }                               /* Assume that pVal is NULL */
+            ex_catch(Except) {
+                rethrow;
+            }
+
+            free(s_pInst);                  /* Deallocate configuration */
+            s_pInst = NULL;                 /* and clear its reference  */
+        }
     }
+    else
+        return(RC_THROW(RC_ERR_USE));
 
     return(RC_THROW(RC_OK));
 }


ossp-pkg/rc/rc_optimpl.c 1.1 -> 1.2

--- rc_optimpl.c 2002/02/28 15:31:54     1.1
+++ rc_optimpl.c 2002/02/28 18:24:04     1.2
@@ -148,4 +148,3 @@
     popt_freecontext(optCon);
     return(RC_THROW(RC_OK));
 }
-


ossp-pkg/rc/rc_private.h 1.4 -> 1.5

--- rc_private.h 2002/02/28 15:30:04     1.4
+++ rc_private.h 2002/02/28 18:24:04     1.5
@@ -38,32 +38,35 @@
 #include <assert.h>
 #ifndef DEBUG
 #define NDEBUG
-#define TRACE(expr) ((void)0)
+#define TRACE(str) ((void)0)
+#define TRACEL(long) ((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)
 #endif
 
+/* The GUID for OSSP rc */
+#define RC_STR_ID "OSSP rc"
+
+
 /* Memory debugging support */
 #if defined(HAVE_DMALLOC_H) && defined(WITH_DMALLOC)
 #include "dmalloc.h"
 #endif
 
-/* GUID to use with OSSP ex library */
-const char g_szOSSPrc[];
-
 /* Define the ability to throw OSSP ex exceptions       */
 #include "ex.h" /* OSSP ex exception handling library   */
 #define RC_THROW(rv) \
     ((rv) != RC_OK && (ex_catching && !ex_shielding) \
-     ? (ex_throw(g_szOSSPrc, NULL, (rv)), (rv)) : (rv))
+     ? (ex_throw(RC_STR_ID, NULL, (rv)), (rv)) : (rv))
 
 #include "val.h"
 
 
 /* Main rc configuration storage */
 typedef struct {
-    void *pvCtx;
-    val_t *pVal;
+    val_t *pVal; /* Storage of configuration values         */
+    int nLocks;  /* Server locks, probably not thread-safe  */
 } rc_config_t;
 
 #endif /* __OSSPRC_PRIVATE_H__ */

CVSTrac 2.0.1