OSSP CVS Repository

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

Check-in Number: 3340
Date: 2003-May-16 00:22:30 (local)
2003-May-15 22:22:30 (UTC)
User:ms
Branch:
Comment: Implement priority scheduling with qsort(3) and priCompare(), adhere to naming standard, and bugfix.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc.h      1.41 -> 1.42     1 inserted, 0 deleted
ossp-pkg/rc/rc_private.h      1.23 -> 1.24     4 inserted, 4 deleted
ossp-pkg/rc/rc_proc.c      1.22 -> 1.23     5 inserted, 2 deleted
ossp-pkg/rc/rc_script.c      1.14 -> 1.15     1 inserted, 2 deleted
ossp-pkg/rc/rc_sect.c      1.4 -> 1.5     30 inserted, 32 deleted
ossp-pkg/rc/rc_util.c      1.6 -> 1.7     23 inserted, 0 deleted

ossp-pkg/rc/rc.h 1.41 -> 1.42

--- rc.h 2003/05/15 12:49:11     1.41
+++ rc.h 2003/05/15 22:22:30     1.42
@@ -147,6 +147,7 @@
 char **vectorCopy(const char **);
 short vectorCount(const char **);
 rc_return_t vectorDel(char **);
+int priCompare(const void *, const void *);
 
 /* Other function prototypes */
 void rcError(ex_t);


ossp-pkg/rc/rc_private.h 1.23 -> 1.24

--- rc_private.h 2003/05/15 12:49:11     1.23
+++ rc_private.h 2003/05/15 22:22:30     1.24
@@ -88,10 +88,10 @@
 
 /* Section type */
 typedef struct {
-    int nPri;
-    int nUid;
-    char *szData;
-    size_t Bytes;
+    int m_nPri;
+    int m_nUid;
+    char *m_szData;
+    size_t m_Bytes;
 } rc_section_t;
 
 /* Processor class */


ossp-pkg/rc/rc_proc.c 1.22 -> 1.23

--- rc_proc.c    2003/05/15 12:49:11     1.22
+++ rc_proc.c    2003/05/15 22:22:30     1.23
@@ -193,7 +193,8 @@
 ************************************************/
 rc_return_t procRun(rc_proc_t *pRc)
 {
-    int   nIter = 0;
+    int   nIter    = 0;
+    int   nTotsecs = pRc->m_pAnal->m_nRcs * pRc->m_pAnal->m_nSecs;
     char *pszVec[RC_EXEC_MAXARGS];
 
     /****************************************************/
@@ -213,10 +214,12 @@
             TRACE("Bad, execvp in child returned -1");
     }
     else if (configGetval(RC_PRN_VAL)) {                         /* Print  */
+        qsort((void *)pRc->m_ppSectvec, (size_t)nTotsecs, sizeof (rc_section_t *), priCompare);
         scriptDump(pRc->m_pScriptcom);
-        for (nIter = 0; nIter < pRc->m_pAnal->m_nRcs * pRc->m_pAnal->m_nSecs; nIter++)
+        for (nIter = 0; nIter < nTotsecs; nIter++) {
             if (pRc->m_ppSectvec[nIter])
                 sectionDump(pRc->m_ppSectvec[nIter]);
+        }
     }
     else /* Something is wrong here */
         return(RC_THROW(RC_ERR_INT));


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

--- rc_script.c  2003/05/14 16:36:28     1.14
+++ rc_script.c  2003/05/15 22:22:30     1.15
@@ -189,13 +189,12 @@
             piSubtemp = strnstr(piStart, RC_DEF_PRG, piEnd - piStart);
             if (piSubtemp) { /* Priority pattern found */
 /* FIXME: Remove the 1 in the following line! */
-                nPri = strtol(piSubtemp + strlen(RC_DEF_PRG) + 1, (char **)NULL, 10);
+                nPri = strtol(piSubtemp + strlen(RC_DEF_PRG), (char **)NULL, 10);
                 sectionSetpri(pSec, nPri);
             }
             else /* Fallback to default value */
                 sectionSetpri(pSec, RC_DEF_PRI);
 
-/*fprintf(stderr, "nPri ist %d!\n", pSec->nPri);*/
             /* Handle the section userid   */
             return(pSec);   /* Section found, so return the text */
         }


ossp-pkg/rc/rc_sect.c 1.4 -> 1.5

--- rc_sect.c    2003/05/15 12:49:11     1.4
+++ rc_sect.c    2003/05/15 22:22:30     1.5
@@ -61,11 +61,11 @@
 
     /* Today is a rain and no coffee day */
     pSec = (rc_section_t *)malloc(sizeof(rc_section_t));
-    pSec->nPri   = pOrigsec->nPri;
-    pSec->nUid   = pOrigsec->nUid;
-    pSec->szData = malloc(strlen(pOrigsec->szData) * sizeof(char) + 1);
-    strcpy(pSec->szData, pOrigsec->szData);
-    pSec->Bytes  = pOrigsec->Bytes;
+    pSec->m_nPri   = pOrigsec->m_nPri;
+    pSec->m_nUid   = pOrigsec->m_nUid;
+    pSec->m_Bytes  = pOrigsec->m_Bytes;
+    pSec->m_szData = malloc(strlen(pOrigsec->m_szData) * sizeof(char) + 1);
+    strcpy(pSec->m_szData, pOrigsec->m_szData);
 
     if (!pSec)
         RC_THROW(RC_ERR_MEM);
@@ -80,7 +80,7 @@
 const int sectionGetpri(rc_section_t *pSec)
 { /* Priority of section, used to order sections during exec|eval|print */
     if (pSec)
-        return(pSec->nPri);
+        return(pSec->m_nPri);
     else
         RC_THROW(RC_ERR_USE);
 
@@ -90,7 +90,7 @@
 const int sectionGetuid(rc_section_t *pSec)
 { /* Userid of section, used with setuid during exec or eval */
     if (pSec)
-        return(pSec->nUid);
+        return(pSec->m_nUid);
     else
         RC_THROW(RC_ERR_USE);
 
@@ -99,8 +99,8 @@
 
 const char *sectionGetdata(rc_section_t *pSec)
 { /* Data of section, this is the script body of the particular section */
-    if (pSec && pSec->szData)
-        return(pSec->szData);
+    if (pSec && pSec->m_szData)
+        return(pSec->m_szData);
     else
         RC_THROW(RC_ERR_USE);
 
@@ -110,7 +110,7 @@
 size_t sectionGetlen(rc_section_t *pSec)
 { /* Data length of section, length of a script body of a particular section */
     if (pSec)
-        return(pSec->Bytes);
+        return(pSec->m_Bytes);
     else
         RC_THROW(RC_ERR_USE);
 
@@ -124,7 +124,7 @@
 rc_return_t sectionSetpri(rc_section_t *pSec, long nPriority)
 { /* Priority of section, used to order sections during exec|eval|print */
     if (pSec) {
-        pSec->nPri = nPriority;
+        pSec->m_nPri = nPriority;
         return(RC_THROW(RC_OK));
     }
 
@@ -134,7 +134,7 @@
 rc_return_t sectionSetuid(rc_section_t *pSec, long nUserid)
 { /* Userid of section, used with setuid during exec or eval */
     if (pSec) {
-        pSec->nUid = nUserid;
+        pSec->m_nUid = nUserid;
         return(RC_THROW(RC_OK));
     }
 
@@ -144,15 +144,15 @@
 rc_return_t sectionSetdata(rc_section_t *pSec, const char *kszScript)
 { /* Data of section, this is the script body of the particular section */
     if (pSec) {
-        pSec->Bytes = strlen(kszScript) * sizeof(char) + sizeof(char);
-        if (pSec->szData) { /* The section data is already in use */
-            free(pSec->szData);
-            pSec->szData = malloc(pSec->Bytes);
-            strcpy(pSec->szData, kszScript);
+        pSec->m_Bytes = strlen(kszScript) * sizeof(char) + sizeof(char);
+        if (pSec->m_szData) { /* The section data is already in use */
+            free(pSec->m_szData);
+            pSec->m_szData = malloc(pSec->m_Bytes);
+            strcpy(pSec->m_szData, kszScript);
         }
         else { /* Set the data the usual way */
-            pSec->szData = malloc(pSec->Bytes);
-            strcpy(pSec->szData, kszScript);
+            pSec->m_szData = malloc(pSec->m_Bytes);
+            strcpy(pSec->m_szData, kszScript);
         }
         return(RC_THROW(RC_OK));
     }
@@ -163,17 +163,17 @@
 rc_return_t sectionSetndata(rc_section_t *pSec, const char *kszScript, size_t Len)
 { /* Data of section, this is the script body of the particular section */
     if (pSec) {
-        pSec->Bytes = Len * sizeof(char) + sizeof(char); /* Set size */
-        if (pSec->szData) { /* The section data is already in use */
-            free(pSec->szData);
-            pSec->szData = malloc(pSec->Bytes);
-            strncpy(pSec->szData, kszScript, Len);
-            *(pSec->szData + Len) = NULL; /* Terminate outgoing */
+        pSec->m_Bytes = Len * sizeof(char) + sizeof(char); /* Set size */
+        if (pSec->m_szData) { /* The section data is already in use */
+            free(pSec->m_szData);
+            pSec->m_szData = malloc(pSec->m_Bytes);
+            strncpy(pSec->m_szData, kszScript, Len);
+            *(pSec->m_szData + Len) = NULL; /* Terminate outgoing */
         }
         else { /* Set the data the usual way */
-            pSec->szData = malloc(pSec->Bytes);
-            strncpy(pSec->szData, kszScript, Len);
-            *(pSec->szData + Len) = NULL; /* Terminate outgoing */
+            pSec->m_szData = malloc(pSec->m_Bytes);
+            strncpy(pSec->m_szData, kszScript, Len);
+            *(pSec->m_szData + Len) = NULL; /* Terminate outgoing */
         }
         return(RC_THROW(RC_OK));
     }
@@ -187,8 +187,6 @@
 ************************************************/
 rc_return_t sectionDump(rc_section_t *pSec)
 {
-    /* Don't remove this! It encapsulates the script object, */
-    /*                    which might not be a simple string */
     if (pSec) {
         fprintf(stdout, "%s", sectionGetdata(pSec));
         return(RC_THROW(RC_OK));
@@ -205,8 +203,8 @@
 {
     /* Cleanup our junk */
     if (pSec) {
-        if (pSec->szData)
-            free(pSec->szData);
+        if (pSec->m_szData)
+            free(pSec->m_szData);
         free(pSec);
     }
     else    /* Dumbass passed an empty section object */


ossp-pkg/rc/rc_util.c 1.6 -> 1.7

--- rc_util.c    2003/05/15 12:49:11     1.6
+++ rc_util.c    2003/05/15 22:22:30     1.7
@@ -105,3 +105,26 @@
 
     return(RC_THROW(RC_OK));
 }
+
+/* Section priority compare, to use with qsort(3) */
+int priCompare(const void *pkv1, const void *pkv2)
+{
+    int nOne = ((rc_section_t *)pkv1)->m_nPri;
+    int nTwo = ((rc_section_t *)pkv2)->m_nPri;
+
+    if (nOne)
+        if (nTwo)
+            if (*(int *)nOne > *(int *)nTwo)
+                return (1);
+            else if (*(int *)nOne < *(int *)nTwo)
+                return (-1);
+            else
+                return (0);
+        else
+            return (-1);
+    else if (nTwo)
+        return (1);
+    else
+        return (0);
+}
+

CVSTrac 2.0.1