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.14 by tdb, Mon Feb 16 14:55:32 2004 UTC

# Line 1 | Line 1
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-2004 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
8 < * as published by the Free Software Foundation; either version 2
9 < * of the License, or (at your option) any later version.
6 > * This library is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public
8 > * License as published by the Free Software Foundation; either
9 > * version 2.1 of the License, or (at your option) any later version.
10   *
11 < * This program is distributed in the hope that it will be useful,
11 > * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 < * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 < * GNU General Public License for more details.
13 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 > * Lesser General Public License for more details.
15   *
16 < * You should have received a copy of the GNU General Public License
17 < * along with this program; if not, write to the Free Software
18 < * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 > * You should have received a copy of the GNU Lesser General Public
17 > * License along with this library; if not, write to the Free Software
18 > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 > * 02111-1307 USA
20 > *
21 > * $Id$
22   */
23  
24   #ifdef HAVE_CONFIG_H
25   #include "config.h"
26   #endif
27  
25 #include "statgrab.h"
28   #include <sys/utsname.h>
29 < #include "ukcprog.h"
30 < #include <stdio.h>
29 > #include "statgrab.h"
30 > #include <stdlib.h>
31   #ifdef SOLARIS
32   #include <kstat.h>
33   #include <time.h>
34   #endif
35 + #if defined(LINUX) || defined(CYGWIN)
36 + #include <stdio.h>
37 + #endif
38 + #ifdef ALLBSD
39 + #if defined(FREEBSD) || defined(DFBSD)
40 + #include <sys/types.h>
41 + #include <sys/sysctl.h>
42 + #else
43 + #include <sys/param.h>
44 + #include <sys/sysctl.h>
45 + #endif
46 + #include <time.h>
47 + #include <sys/time.h>
48 + #endif
49  
50   general_stat_t *get_general_stats(){
51  
52          static general_stat_t general_stat;    
53 +        static struct utsname os;
54  
55 <        struct utsname os;
55 > #ifdef SOLARIS
56          time_t boottime,curtime;
57          kstat_ctl_t *kc;
58          kstat_t *ksp;
59          kstat_named_t *kn;
60 + #endif
61 + #if defined(LINUX) || defined(CYGWIN)
62 +        FILE *f;
63 + #endif
64 + #ifdef ALLBSD
65 +        int mib[2];
66 +        struct timeval boottime;
67 +        time_t curtime;
68 +        size_t size;
69 + #endif
70  
71          if((uname(&os)) < 0){
45                errf("Failed to get os stats (%m)");
72                  return NULL;
73          }
74          
# Line 53 | Line 79 | general_stat_t *get_general_stats(){
79          general_stat.hostname = os.nodename;
80  
81          /* get uptime */
82 + #ifdef SOLARIS
83          if ((kc = kstat_open()) == NULL) {
57                errf("kstat_open failure (%m)");
84                  return NULL;
85          }
86          if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){
61                errf("failed to find lookup information (%m)");
87                  return NULL;
88          }
89          if (kstat_read(kc, ksp, 0) == -1) {
65                errf("Failed to read kernel information (%m)");
90                  return NULL;
91          }
92          if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
69                errf("Failed to get uptime (%m)");
93                  return NULL;
94          }
95          boottime=(kn->value.ui32);
73        if((kstat_close(kc)) != 0){
74                errf("Failed to close kstat control structure (%m)");
75                return NULL;
76        }
96  
97 +        kstat_close(kc);
98 +
99          time(&curtime);
100          general_stat.uptime = curtime - boottime;
101 + #endif
102 + #if defined(LINUX) || defined(CYGWIN)
103 +        if ((f=fopen("/proc/uptime", "r")) == NULL) {
104 +                return NULL;
105 +        }
106 +        if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){
107 +                return NULL;
108 +        }
109 +        fclose(f);
110 + #endif
111 + #ifdef ALLBSD
112 +        mib[0] = CTL_KERN;
113 +        mib[1] = KERN_BOOTTIME;
114 +        size = sizeof boottime;
115 +        if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){
116 +                return NULL;
117 +        }
118 +        time(&curtime);
119 +        general_stat.uptime=curtime-boottime.tv_sec;
120 + #endif
121  
122          return &general_stat;
123          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines