ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/os_info.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/os_info.c (file contents):
Revision 1.1 by pajs, Tue Feb 18 19:28:30 2003 UTC vs.
Revision 1.6 by tdb, Sun Aug 24 20:24:09 2003 UTC

# Line 1 | Line 1
1   /*
2   * i-scream central monitoring system
3 < * http://www.i-scream.org.uk
4 < * Copyright (C) 2000-2002 i-scream
3 > * http://www.i-scream.org
4 > * Copyright (C) 2000-2003 i-scream
5   *
6   * This program is free software; you can redistribute it and/or
7   * modify it under the terms of the GNU General Public License
# Line 22 | Line 22
22   #include "config.h"
23   #endif
24  
25 #include "statgrab.h"
25   #include <sys/utsname.h>
26 < #include "ukcprog.h"
28 < #include <stdio.h>
26 > #include "statgrab.h"
27   #ifdef SOLARIS
28   #include <kstat.h>
29   #include <time.h>
30   #endif
31 + #ifdef LINUX
32 + #include <stdio.h>
33 + #endif
34 + #ifdef FREEBSD
35 + #include <sys/types.h>
36 + #include <sys/sysctl.h>
37 + #include <time.h>
38 + #include <sys/time.h>
39 + #endif
40  
41   general_stat_t *get_general_stats(){
42  
43          static general_stat_t general_stat;    
44 +        static struct utsname os;
45  
46 <        struct utsname os;
46 > #ifdef SOLARIS
47          time_t boottime,curtime;
48          kstat_ctl_t *kc;
49          kstat_t *ksp;
50          kstat_named_t *kn;
51 + #endif
52 + #ifdef LINUX
53 +        FILE *f;
54 + #endif
55 + #ifdef FREEBSD
56 +        struct timeval boottime;
57 +        time_t curtime;
58 +        size_t size;
59 + #endif
60  
61          if((uname(&os)) < 0){
45                errf("Failed to get os stats (%m)");
62                  return NULL;
63          }
64          
# Line 53 | Line 69 | general_stat_t *get_general_stats(){
69          general_stat.hostname = os.nodename;
70  
71          /* get uptime */
72 + #ifdef SOLARIS
73          if ((kc = kstat_open()) == NULL) {
57                errf("kstat_open failure (%m)");
74                  return NULL;
75          }
76          if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){
61                errf("failed to find lookup information (%m)");
77                  return NULL;
78          }
79          if (kstat_read(kc, ksp, 0) == -1) {
65                errf("Failed to read kernel information (%m)");
80                  return NULL;
81          }
82          if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
69                errf("Failed to get uptime (%m)");
83                  return NULL;
84          }
85          boottime=(kn->value.ui32);
73        if((kstat_close(kc)) != 0){
74                errf("Failed to close kstat control structure (%m)");
75                return NULL;
76        }
86  
87 +        kstat_close(kc);
88 +
89          time(&curtime);
90          general_stat.uptime = curtime - boottime;
91 + #endif
92 + #ifdef LINUX
93 +        if ((f=fopen("/proc/uptime", "r")) == NULL) {
94 +                return NULL;
95 +        }
96 +        if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){
97 +                return NULL;
98 +        }
99 +        fclose(f);
100 + #endif
101 + #ifdef FREEBSD
102 +        if (sysctlbyname("kern.boottime", NULL, &size, NULL, NULL) < 0){
103 +                return NULL;
104 +        }
105 +        if (sysctlbyname("kern.boottime", &boottime, &size, NULL, NULL) < 0){
106 +                return NULL;
107 +        }
108 +        time(&curtime);
109 +        general_stat.uptime=curtime-boottime.tv_sec;
110 + #endif
111  
112          return &general_stat;
113          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines