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.8 by ats, Sat Oct 18 23:04:23 2003 UTC vs.
Revision 1.19 by ats, Sun Jul 18 21:30:11 2004 UTC

# Line 1 | Line 1
1 < /*
2 < * i-scream central monitoring system
1 > /*
2 > * i-scream libstatgrab
3   * http://www.i-scream.org
4 < * Copyright (C) 2000-2003 i-scream
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
# Line 24 | Line 27
27  
28   #include <sys/utsname.h>
29   #include "statgrab.h"
30 + #include <stdlib.h>
31   #ifdef SOLARIS
32   #include <kstat.h>
33   #include <time.h>
34   #endif
35 < #ifdef LINUX
35 > #if defined(LINUX) || defined(CYGWIN)
36   #include <stdio.h>
37   #endif
38 < #ifdef FREEBSD
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(){
50 > sg_host_info *sg_get_host_info(){
51  
52 <        static general_stat_t general_stat;    
52 >        static sg_host_info general_stat;      
53          static struct utsname os;
54  
55   #ifdef SOLARIS
# Line 49 | Line 58 | general_stat_t *get_general_stats(){
58          kstat_t *ksp;
59          kstat_named_t *kn;
60   #endif
61 < #ifdef LINUX
61 > #if defined(LINUX) || defined(CYGWIN)
62          FILE *f;
63   #endif
64 < #ifdef FREEBSD
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){
72 +                sg_set_error_with_errno(SG_ERROR_UNAME, NULL);
73                  return NULL;
74          }
75          
76          general_stat.os_name = os.sysname;
77 <        general_stat.os_release = os.release;
78 <        general_stat.os_version = os.version;
79 <        general_stat.platform = os.machine;
80 <        general_stat.hostname = os.nodename;
77 >        general_stat.os_release = os.release;
78 >        general_stat.os_version = os.version;
79 >        general_stat.platform = os.machine;
80 >        general_stat.hostname = os.nodename;
81  
82          /* get uptime */
83   #ifdef SOLARIS
84          if ((kc = kstat_open()) == NULL) {
85 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
86                  return NULL;
87          }
88          if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){
89 +                sg_set_error(SG_ERROR_KSTAT_LOOKUP, "unix,-1,system_misc");
90                  return NULL;
91          }
92          if (kstat_read(kc, ksp, 0) == -1) {
93 +                sg_set_error(SG_ERROR_KSTAT_READ, NULL);
94                  return NULL;
95          }
96          if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
97 +                sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "boot_time");
98                  return NULL;
99          }
100          boottime=(kn->value.ui32);
# Line 89 | Line 104 | general_stat_t *get_general_stats(){
104          time(&curtime);
105          general_stat.uptime = curtime - boottime;
106   #endif
107 < #ifdef LINUX
107 > #if defined(LINUX) || defined(CYGWIN)
108          if ((f=fopen("/proc/uptime", "r")) == NULL) {
109 +                sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/uptime");
110                  return NULL;
111          }
112          if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){
113 +                sg_set_error(SG_ERROR_PARSE, NULL);
114                  return NULL;
115          }
116          fclose(f);
117   #endif
118 < #ifdef FREEBSD
118 > #ifdef ALLBSD
119 >        mib[0] = CTL_KERN;
120 >        mib[1] = KERN_BOOTTIME;
121          size = sizeof boottime;
122 <        if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0){
122 >        if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){
123 >                sg_set_error_with_errno(SG_ERROR_SYSCTL,
124 >                                        "CTL_KERN.KERN_BOOTTIME");
125                  return NULL;
126          }
127          time(&curtime);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines