the first snippet include for <sys/times.h> might be needed by the previous
patch.

merges bos_level with fixes to avoid memory leaks and returning undefined
values on error.

the version provided by Michael ignores searchs for "bos.rte.?p" that might
seem to be needed for AIX 4.x based on the comments from the original
implementation.  it also renames most of the variables and the function and
adds more ODM object initializations but without a clear explanation of what
bug was being solved so I kept the original implementation here but if there
is a scary in this batch is this one.

Signed-off-by: Carlo Marcelo Arenas Belon <[EMAIL PROTECTED]>
---
 trunk/monitor-core/libmetrics/aix/metrics.c |   90 +++++++++++++++-----------
 1 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/trunk/monitor-core/libmetrics/aix/metrics.c 
b/trunk/monitor-core/libmetrics/aix/metrics.c
index ed2e0a7..8c0c2c7 100644
--- a/trunk/monitor-core/libmetrics/aix/metrics.c
+++ b/trunk/monitor-core/libmetrics/aix/metrics.c
@@ -38,6 +38,8 @@
 #include <signal.h>
 #include <odmi.h>
 #include <cf.h>
+#include <sys/types.h>
+#include <sys/time.h>
 #include <sys/utsname.h>
 #include <sys/proc.h>
 
@@ -45,17 +47,16 @@
 
 #include "libmetrics.h"
 
-
-
-
 struct Class *My_CLASS;
 
 struct product {
-        char filler[12];
-        char lpp_name[145];      /* offset: 0xc ( 12) */
+        __long32_t _id;          /* offset: 0x00 (   0) */
+        __long32_t _reserved;    /* offset: 0x04 (   4) */
+        __long32_t _scratch;     /* offset: 0x08 (   8) */
+        char lpp_name[145];      /* offset: 0x0c (  12) */
         char comp_id[20];        /* offset: 0x9d ( 157) */
         short update;            /* offset: 0xb2 ( 178) */
-        long cp_flag;            /* offset: 0xb4 ( 180) */
+        __long32_t cp_flag;      /* offset: 0xb4 ( 180) */
         char fesn[10];           /* offset: 0xb8 ( 184) */
         char *name;              /*[42] offset: 0xc4 ( 196) */
         short state;             /* offset: 0xc8 ( 200) */
@@ -107,19 +108,14 @@ struct cpuinfo_stats {
    double wait;
 } current_cpuinfo;
 
-int aixver, aixrel, aixlev, aixfix;
+static int aixver, aixrel, aixlev, aixfix;
 struct utsname unames;
 
-
 /* Prototypes
  */
 void  update_ifdata(void);
 int bos_level(int *aix_version, int *aix_release, int *aix_level, int 
*aix_fix);
 
-
-
-
-
 /*
  * This function is called only once by the gmond.  Use to 
  * initialize data structures, etc or just return SYNAPSE_SUCCESS;
@@ -727,7 +723,7 @@ mtu_func ( void )
 }
 
 /* int bos_level(int *aix_version, int *aix_release, int *aix_level, int 
*aix_fix)
- *  is copied form 
+ *  is copied from:
  *
  *  First stab at support for metrics in AIX
  *  by Preston Smith <[EMAIL PROTECTED]>
@@ -736,12 +732,15 @@ mtu_func ( void )
  *  AIX V5 support, bugfixes added by Davide Tacchella <[EMAIL PROTECTED]>
  *  May 10, 2002
  *
+ *  AIX 5L adaptation done by Michael Perzl ([EMAIL PROTECTED])
+ *  March 30, 2006
  */
 
 int bos_level(int *aix_version, int *aix_release, int *aix_level, int *aix_fix)
 {
     struct Class *my_cl;   /* customized devices class ptr */
     struct product  productobj;     /* customized device object storage */
+    int maxVer, maxTel, maxMod, maxFix;
     int rc, getit, found = 0;
     char *path;
 
@@ -760,22 +759,26 @@ int bos_level(int *aix_version, int *aix_release, int 
*aix_level, int *aix_fix)
     /*
      * Mount the lpp class
      */
-    if ((My_CLASS = odm_mount_class("product")) == (CLASS_SYMBOL) -1)
+    if ((My_CLASS = odm_mount_class("product")) == (CLASS_SYMBOL) -1) {
+        free(path);
         return odmerrno;
-
+    }
     /*
      * open customized devices object class
      */
-    if ((int)(my_cl = odm_open_class(My_CLASS)) == -1)
+    if ((int)(my_cl = odm_open_class(My_CLASS)) == -1) {
+        free(path)
         return E_ODMOPEN;
+    }
 
     /*
-     * Loop trough all entries for the lpp name, ASSUMING the last
-     * one denotes the up to date number!!!
-     */
-    /*
+     * Loop trough all entries for the lpp name
+     *
      * AIX > 4.2 uses bos.mp or bos.up
+     * we look also for bos.mp64 abd bos.up64
      */
+    maxVer = maxRel = maxMod = maxFix = 0;
+    
     getit = ODM_FIRST;
     while ((rc = (int)odm_get_obj(my_cl, "name like bos.?p",
                                   &productobj, getit)) != 0) {
@@ -783,17 +786,31 @@ int bos_level(int *aix_version, int *aix_release, int 
*aix_level, int *aix_fix)
         if (rc == -1) {
             /* ODM failure */
             break;
+        } else {
+            if (productobj.ver > maxVer) maxVer = productobj.ver;
+            if (productobj.rel > maxRel) maxRel = productobj.rel;
+            if (productobj.mod > maxMod) maxMod = productobj.mod;
+            if (productobj.fix > maxFix) maxFix = productobj.fix;
+            found++;
         }
-        else {
-            *aix_version = productobj.ver;
-            *aix_release = productobj.rel;
-            *aix_level   = productobj.mod;
-            *aix_fix     = productobj.fix;
+    }
+    getit = ODM_FIRST;
+    while ((rc = (int)odm_get_obj(my_cl, "name like bos.?p64",
+                                  &productobj, getit)) != 0) {
+        getit = ODM_NEXT;
+        if (rc == -1) {
+            /* ODM failure */
+            break;
+        } else {
+            if (productobj.ver > maxVer) maxVer = productobj.ver;
+            if (productobj.rel > maxRel) maxRel = productobj.rel;
+            if (productobj.mod > maxMod) maxMod = productobj.mod;
+            if (productobj.fix > maxFix) maxFix = productobj.fix;
             found++;
         }
     }
     /*
-     * AIX < 4.2 uses bos.mp or bos.up
+     * AIX < 4.2 
      */
     if (!found) {
         getit = ODM_FIRST;
@@ -803,18 +820,20 @@ int bos_level(int *aix_version, int *aix_release, int 
*aix_level, int *aix_fix)
             if (rc == -1) {
                 /* ODM failure */
                 break;
-            }
-            else {
-                *aix_version = productobj.ver;
-                *aix_release = productobj.rel;
-                *aix_level   = productobj.mod;
-                *aix_fix     = productobj.fix;
+            } else {
+                if (productobj.ver > maxVer) maxVer = productobj.ver;
+                if (productobj.rel > maxRel) maxRel = productobj.rel;
+                if (productobj.mod > maxMod) maxMod = productobj.mod;
+                if (productobj.fix > maxFix) maxFix = productobj.fix;
                 found++;
             }
         }
     }
 
-
+    *aix_version = productobj.ver;
+    *aix_release = productobj.rel;
+    *aix_level   = productobj.mod;
+    *aix_fix     = productobj.fix;
 
     /*
      * close lpp object class
@@ -828,9 +847,6 @@ int bos_level(int *aix_version, int *aix_release, int 
*aix_level, int *aix_fix)
 
 } /* bos_level */
 
-
-
-
 #define CALC_NETSTAT(type) (double) 
((cur_ninfo->type<last_ninfo->type)?-1:(cur_ninfo->type - 
last_ninfo->type)/timediff)
 void
 update_ifdata(void){
@@ -885,5 +901,3 @@ update_ifdata(void){
      }
 
 }  /* update_ifdata */
-
-
-- 
1.5.3.7


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ganglia-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to