merge fixes into one single function for boottime and creates a global

a global boottime is needed for previous patches so this might need to me
moved up.

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

diff --git a/trunk/monitor-core/libmetrics/aix/metrics.c 
b/trunk/monitor-core/libmetrics/aix/metrics.c
index 91a150e..31a1771 100644
--- a/trunk/monitor-core/libmetrics/aix/metrics.c
+++ b/trunk/monitor-core/libmetrics/aix/metrics.c
@@ -115,6 +115,7 @@ struct cpuinfo_stats {
 } current_cpuinfo;
 
 static int aixver, aixrel, aixlev, aixfix;
+static time_t boottime;
 struct utsname unames;
 
 /* Prototypes
@@ -160,22 +161,27 @@ g_val_t
 boottime_func ( void )
 {
    g_val_t val;
-   int boottime = 0;
    struct utmp buf;
-   FILE *utmp = fopen(UTMP_FILE, "r");
-
-   if (utmp == NULL) {
-     /* Can't open utmp, use current time as boottime */
-     boottime = time(NULL);
-   } else {
-     while (fread((char *) &buf, sizeof(buf), 1, utmp) == 1) {
-        if (buf.ut_type == BOOT_TIME) {
-            boottime = buf.ut_time;
-            break;
-        }
-     }
+   FILE *utmp;
+   
+   if (!boottime) {
+      utmp = fopen(UTMP_FILE, "r");
+
+      if (utmp == NULL) {
+         /* Can't open utmp, use current time as boottime */
+         boottime = time(NULL);
+      } else {
+         while (fread((char *) &buf, sizeof(buf), 1, utmp) == 1) {
+            if (buf.ut_type == BOOT_TIME) {
+               boottime = buf.ut_time;
+               break;
+            }
+         }
+        fclose (utmp);
+      }
    }
    val.uint32 = boottime;
+
    return val;
 }
 
-- 
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