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.11 by ats, Mon Nov 10 23:25:45 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"
27 < #include <stdio.h>
26 > #include "statgrab.h"
27 > #include <stdlib.h>
28   #ifdef SOLARIS
29   #include <kstat.h>
30   #include <time.h>
31   #endif
32 + #if defined(LINUX) || defined(CYGWIN)
33 + #include <stdio.h>
34 + #endif
35 + #ifdef ALLBSD
36 + #ifdef FREEBSD
37 + #include <sys/types.h>
38 + #include <sys/sysctl.h>
39 + #else
40 + #include <sys/param.h>
41 + #include <sys/sysctl.h>
42 + #endif
43 + #include <time.h>
44 + #include <sys/time.h>
45 + #endif
46  
47   general_stat_t *get_general_stats(){
48  
49          static general_stat_t general_stat;    
50 +        static struct utsname os;
51  
52 <        struct utsname os;
52 > #ifdef SOLARIS
53          time_t boottime,curtime;
54          kstat_ctl_t *kc;
55          kstat_t *ksp;
56          kstat_named_t *kn;
57 + #endif
58 + #if defined(LINUX) || defined(CYGWIN)
59 +        FILE *f;
60 + #endif
61 + #ifdef ALLBSD
62 +        int mib[2];
63 +        struct timeval boottime;
64 +        time_t curtime;
65 +        size_t size;
66 + #endif
67  
68          if((uname(&os)) < 0){
45                errf("Failed to get os stats (%m)");
69                  return NULL;
70          }
71          
# Line 53 | Line 76 | general_stat_t *get_general_stats(){
76          general_stat.hostname = os.nodename;
77  
78          /* get uptime */
79 + #ifdef SOLARIS
80          if ((kc = kstat_open()) == NULL) {
57                errf("kstat_open failure (%m)");
81                  return NULL;
82          }
83          if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){
61                errf("failed to find lookup information (%m)");
84                  return NULL;
85          }
86          if (kstat_read(kc, ksp, 0) == -1) {
65                errf("Failed to read kernel information (%m)");
87                  return NULL;
88          }
89          if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
69                errf("Failed to get uptime (%m)");
90                  return NULL;
91          }
92          boottime=(kn->value.ui32);
73        if((kstat_close(kc)) != 0){
74                errf("Failed to close kstat control structure (%m)");
75                return NULL;
76        }
93  
94 +        kstat_close(kc);
95 +
96          time(&curtime);
97          general_stat.uptime = curtime - boottime;
98 + #endif
99 + #if defined(LINUX) || defined(CYGWIN)
100 +        if ((f=fopen("/proc/uptime", "r")) == NULL) {
101 +                return NULL;
102 +        }
103 +        if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){
104 +                return NULL;
105 +        }
106 +        fclose(f);
107 + #endif
108 + #ifdef ALLBSD
109 +        mib[0] = CTL_KERN;
110 +        mib[1] = KERN_BOOTTIME;
111 +        size = sizeof boottime;
112 +        if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){
113 +                return NULL;
114 +        }
115 +        time(&curtime);
116 +        general_stat.uptime=curtime-boottime.tv_sec;
117 + #endif
118  
119          return &general_stat;
120          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines