OSSP CVS Repository

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

Check-in Number: 3353
Date: 2003-May-20 17:06:41 (local)
2003-May-20 15:06:41 (UTC)
User:ms
Branch:
Comment: Implement rc label ordered command printing and execution.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc.h      1.44 -> 1.45     1 inserted, 1 deleted
ossp-pkg/rc/rc_anal.c      1.13 -> 1.14     5 inserted, 4 deleted
ossp-pkg/rc/rc_lab.c      1.1 -> 1.2     27 inserted, 7 deleted
ossp-pkg/rc/rc_private.h      1.26 -> 1.27     1 inserted, 0 deleted
ossp-pkg/rc/rc_proc.c      1.26 -> 1.27     32 inserted, 20 deleted
ossp-pkg/rc/rc_script.c      1.17 -> 1.18     1 inserted, 1 deleted
ossp-pkg/rc/rc_sect.c      1.7 -> 1.8     9 inserted, 3 deleted

ossp-pkg/rc/rc.h 1.44 -> 1.45

--- rc.h 2003/05/20 11:46:25     1.44
+++ rc.h 2003/05/20 15:06:41     1.45
@@ -123,7 +123,7 @@
 rc_return_t labelDelete(rc_label_t *);
 
 /* Section function prototypes */
-rc_section_t *sectionNew(void);
+rc_section_t *sectionNew(const char *);
 rc_section_t *sectionCopy(rc_section_t *);
 const int sectionGetpri(rc_section_t *);
 const int sectionGetuid(rc_section_t *);


ossp-pkg/rc/rc_anal.c 1.13 -> 1.14

--- rc_anal.c    2003/05/15 12:49:11     1.13
+++ rc_anal.c    2003/05/20 15:06:41     1.14
@@ -65,8 +65,7 @@
         (*ppInst)->m_szRcs = malloc(sizeof(char **));
         if (strcmp(kszName, RC_GLOB_WILD)) {
             (*ppInst)->m_szRcs = malloc(sizeof(*((*ppInst)->m_szRcs)));
-            *(*ppInst)->m_szRcs = strdup("rc."); /* FIXME: Remove hardcoded */
-            strcat(*(*ppInst)->m_szRcs, kszName);
+            *(*ppInst)->m_szRcs = strdup(kszName);
             (*ppInst)->m_nRcs = 1;            /* We handle just one rc file */
         }
         else { /* Wildcard rcfile indicates we must glob the locs directories */
@@ -203,8 +202,10 @@
         (*ppInst)->m_szRcs = malloc(sizeof((*((*ppInst)->m_szRcs))) * (nCount + 1));
 
     /* Loop through file index setting rc file names according to dirent */
-    for (nIter = 0; nIter < nCount; ++nIter)
-        (*ppInst)->m_szRcs[nIter] = strdup((*pppFiles)[nIter]->d_name);
+    for (nIter = 0; nIter < nCount; ++nIter) {
+        (*ppInst)->m_szRcs[nIter] = strdup((*pppFiles)[nIter]->d_name +\
+            strlen("rc.") * sizeof(char));
+    }
     (*ppInst)->m_szRcs[nIter] = NULL; /* Terminate */
     (*ppInst)->m_nRcs = nCount; /* Store how many globbed files there are */
 


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

--- rc_lab.c     2003/05/20 11:45:11     1.1
+++ rc_lab.c     2003/05/20 15:06:41     1.2
@@ -60,15 +60,35 @@
 rc_return_t labelAppendsec(rc_label_t *pLabel, rc_section_t *pInsec)
 {
     assert(pLabel); /* Label parameter must be valid */
+    if (!pInsec)    /* Check sanity */
+        return(RC_THROW(RC_ERR_USE));
 
-    if (pInsec) {
-        pLabel->m_ppSecvec = realloc(pLabel->m_ppSecvec, sizeof(rc_section_t *)\
-            * (pLabel->m_nSecs + 1));
-        pLabel->m_ppSecvec[pLabel->m_nSecs++] = pInsec; /* Just copy pointer */
+    /* First make our vector larger to hold one more section */
+    pLabel->m_ppSecvec = realloc(pLabel->m_ppSecvec, sizeof(rc_section_t *)\
+        * (pLabel->m_nSecs + 1));
+    pLabel->m_ppSecvec[pLabel->m_nSecs] = sectionNew(pInsec->m_szName);
+
+    /* Simple value copy */
+    pLabel->m_ppSecvec[pLabel->m_nSecs]->m_nPri  = pInsec->m_nPri;
+    pLabel->m_ppSecvec[pLabel->m_nSecs]->m_nUid  = pInsec->m_nUid;
+    pLabel->m_ppSecvec[pLabel->m_nSecs]->m_Bytes = pInsec->m_Bytes;
+
+    /* Deep copy of user name */
+    if (pInsec->m_szLogin) {
+        pLabel->m_ppSecvec[pLabel->m_nSecs]->m_szLogin =\
+            malloc((strlen(pInsec->m_szLogin) + sizeof(char)) * sizeof(char));
+        strcpy(pLabel->m_ppSecvec[pLabel->m_nSecs]->m_szLogin, pInsec->m_szLogin);
     }
-    else
-        TRACE("Problem with labelAppendsec");
-/*        return(RC_THROW(RC_ERR_USE));*/
+
+    /* Deep copy of section text */
+    if (pInsec->m_szData) {
+        pLabel->m_ppSecvec[pLabel->m_nSecs]->m_szData =\
+            malloc((strlen(pInsec->m_szData) + sizeof(char)) * sizeof(char));
+        strcpy(pLabel->m_ppSecvec[pLabel->m_nSecs]->m_szData, pInsec->m_szData);
+    }
+
+    /* Finally increment section count */
+    pLabel->m_nSecs++;
 
     return(RC_THROW(RC_OK));
 }


ossp-pkg/rc/rc_private.h 1.26 -> 1.27

--- rc_private.h 2003/05/20 11:46:25     1.26
+++ rc_private.h 2003/05/20 15:06:42     1.27
@@ -90,6 +90,7 @@
 typedef struct {
     int m_nPri;
     int m_nUid;
+    char *m_szName;
     char *m_szLogin;
     char *m_szData;
     size_t m_Bytes;


ossp-pkg/rc/rc_proc.c 1.26 -> 1.27

--- rc_proc.c    2003/05/20 11:47:51     1.26
+++ rc_proc.c    2003/05/20 15:06:42     1.27
@@ -123,6 +123,7 @@
         /* Build the path name */
         szLocex = (char *)malloc(strlen(pRc->m_pAnal->m_szLocs) + strlen(pRc->m_pAnal->m_szRcs[nRc]) + 2);
         strcpy(szLocex, pRc->m_pAnal->m_szLocs);
+        strcat(szLocex, "rc."); /* FIXME: Make the prefix configurable */
         strcat(szLocex, pRc->m_pAnal->m_szRcs[nRc]);
 
         /* Open the rc file unconditionally */
@@ -147,20 +148,22 @@
                 pSec = NULL;            /* Cleanup */
             }
 
-            for (nSect = 0; pRc->m_pAnal->m_pszSecs[nSect]; nSect++) { /* Iterate over */
-
+            for (nSect = 0; nSect < pRc->m_pAnal->m_nSecs; nSect++) { /* Iterate over */
                 /* Extract a section from the temp script, and append it */
                 pSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[nSect]);
 
-                if (pSec) /* Only copy if the section lookup succeeds */
-                    labelAppendsec(pRc->m_ppLabvec[nRc], sectionCopy(pSec));
+                if (pSec) { /* Only copy if the section lookup succeeds */
+                    labelAppendsec(pRc->m_ppLabvec[nRc], pSec);
+                }
                 else if (configGetval(RC_DBG_VAL)) /* Only show if debug set */
                     fprintf(stderr, "#Warning: Missing section '%s' in %s!\n",\
                         pRc->m_pAnal->m_pszSecs[nSect],\
                         pRc->m_pAnal->m_szRcs[nRc]);
 
-                if (pSec)   /* Cleanup iterative section string */
+                if (pSec) { /* Cleanup iterative section string */
                     sectionDelete(pSec);
+                    pSec = NULL;
+                }
             }
         }
         catch(Except)
@@ -191,6 +194,7 @@
 ************************************************/
 rc_return_t procRun(rc_proc_t *pRc)
 {
+    int   nTmp  = 0;
     int   nRcs  = 0;
     int   nSecs = 0;
     char *pszVec[RC_EXEC_MAXARGS];
@@ -206,37 +210,45 @@
     /* Eval  - Print machine evaluatable format         */
     /* Print - Print human readable format              */
     /****************************************************/
-    if (configGetval(RC_EVL_VAL))                              /* Evaluate */
+    if (configGetval(RC_EVL_VAL))                               /* Evaluate */
         fprintf(stderr, "Error: Evaluate is not implemented yet.\n"); /* FIX */
-    else if (configGetval(RC_EXC_VAL)) {                       /* Execute  */
+    else if (configGetval(RC_EXC_VAL)) {                        /* Execute  */
         pszVec[0] = "/bin/sh";
         pszVec[1] = "-c";
         pszVec[2] = (char *)scriptTostring(pRc->m_pScriptcom);
         pszVec[3] = NULL;   /* Add a NULL to mark the end of the chain */
-        if (execvp(*pszVec, pszVec) == -1) {                     /* launch */
+        if (execvp(*pszVec, pszVec) == -1) {                    /* launch */
             TRACE("Bad, execvp for common script in child returned -1");
             return(RC_THROW(RC_ERR_INT));
         }
-        for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
-            for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
-                if (pRc->m_ppLabvec[nRcs]->m_ppSecvec[nSecs]) {
-                    pszVec[2] = (char *)sectionGetdata(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nSecs]);
-                    if (execvp(*pszVec, pszVec) == -1) {             /* launch */
+        for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++)
+            for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
+                nTmp = 0;
+                while (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs && \
+                    strcmp(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]->m_szName, \
+                                pRc->m_pAnal->m_pszSecs[nSecs]))
+                    nTmp++;
+                if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs) {
+                    pszVec[2] = (char *)sectionGetdata(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]);
+                    if (execvp(*pszVec, pszVec) == -1) {        /* launch */
                         TRACE("Bad, execvp for subsection in child returned -1");
                         return(RC_THROW(RC_ERR_INT));
                     }
                 }
             }
-        }
     }
-    else if (configGetval(RC_PRN_VAL)) {                         /* Print  */
+    else if (configGetval(RC_PRN_VAL)) {                        /* Print  */
         scriptDump(pRc->m_pScriptcom);
-        for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
-            for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
-                if (pRc->m_ppLabvec[nRcs]->m_ppSecvec && pRc->m_ppLabvec[nRcs]->m_ppSecvec[nSecs])
-                    sectionDump(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nSecs]);
+        for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++)
+            for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
+                nTmp = 0;
+                while (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs && \
+                    strcmp(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]->m_szName, \
+                                pRc->m_pAnal->m_pszSecs[nSecs]))
+                    nTmp++;
+                if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs)
+                    sectionDump(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]);
             }
-        }
     }
     else /* Something is wrong here */
         return(RC_THROW(RC_ERR_INT));


ossp-pkg/rc/rc_script.c 1.17 -> 1.18

--- rc_script.c  2003/05/16 18:43:31     1.17
+++ rc_script.c  2003/05/20 15:06:42     1.18
@@ -183,7 +183,7 @@
             /* Handle the section body */
             piStart   = piBlocend + *(pnVec + 6);
             piEnd     = piBlocend + *(pnVec + 7);
-            pSec = sectionNew();
+            pSec = sectionNew(kszSecname);
             sectionSetndata(pSec, piStart, piEnd - piStart);
 
             /* FIXME: Implement --ParseSectionParam for extra gravy */


ossp-pkg/rc/rc_sect.c 1.7 -> 1.8

--- rc_sect.c    2003/05/19 19:03:06     1.7
+++ rc_sect.c    2003/05/20 15:06:42     1.8
@@ -34,10 +34,10 @@
 
 
 /************************************************
-* sectionNew(void)                              *
+* sectionNew(const char *)                      *
 * Construct a section                           *
 ************************************************/
-rc_section_t *sectionNew(void)
+rc_section_t *sectionNew(const char *szName)
 {
     rc_section_t *pSec = NULL;
 
@@ -45,7 +45,11 @@
     /* This code would probably have more bugs if the coffee was not as good */
     pSec = (rc_section_t *)calloc(1, sizeof(rc_section_t));
 
-    if (!pSec)
+    if (pSec) {
+        pSec->m_szName = malloc((strlen(szName) + 1) * sizeof(char));
+        strcpy(pSec->m_szName, szName);
+    }
+    else
         RC_THROW(RC_ERR_MEM);
 
     return(pSec);
@@ -239,6 +243,8 @@
     if (pSec) {
         if (pSec->m_szData)
             free(pSec->m_szData);
+        if (pSec->m_szName)
+            free(pSec->m_szName);
         if (pSec->m_szLogin)
             free(pSec->m_szLogin);
         free(pSec);

CVSTrac 2.0.1