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.12 by tdb, Fri Jan 16 15:54:54 2004 UTC vs.
Revision 1.20 by tdb, Mon Nov 1 18:30:17 2004 UTC

# Line 1 | Line 1
1   /*
2 < * i-scream central monitoring system
2 > * i-scream libstatgrab
3   * http://www.i-scream.org
4   * Copyright (C) 2000-2004 i-scream
5   *
# Line 17 | Line 17
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 34 | Line 36
36   #include <stdio.h>
37   #endif
38   #ifdef ALLBSD
39 < #ifdef FREEBSD
39 > #if defined(FREEBSD) || defined(DFBSD)
40   #include <sys/types.h>
41   #include <sys/sysctl.h>
42   #else
# Line 44 | Line 46
46   #include <time.h>
47   #include <sys/time.h>
48   #endif
49 + #ifdef HPUX
50 + #include <sys/param.h>
51 + #include <sys/pstat.h>
52 + #include <time.h>
53 + #endif
54  
55 < general_stat_t *get_general_stats(){
55 > sg_host_info *sg_get_host_info(){
56  
57 <        static general_stat_t general_stat;    
57 >        static sg_host_info general_stat;
58          static struct utsname os;
59  
60 + #ifdef HPUX
61 +        struct pst_static pstat_static;
62 +        time_t currtime;
63 +        long boottime;
64 + #endif
65   #ifdef SOLARIS
66          time_t boottime,curtime;
67          kstat_ctl_t *kc;
# Line 67 | Line 79 | general_stat_t *get_general_stats(){
79   #endif
80  
81          if((uname(&os)) < 0){
82 +                sg_set_error_with_errno(SG_ERROR_UNAME, NULL);
83                  return NULL;
84          }
85          
86          general_stat.os_name = os.sysname;
87 <        general_stat.os_release = os.release;
88 <        general_stat.os_version = os.version;
89 <        general_stat.platform = os.machine;
90 <        general_stat.hostname = os.nodename;
87 >        general_stat.os_release = os.release;
88 >        general_stat.os_version = os.version;
89 >        general_stat.platform = os.machine;
90 >        general_stat.hostname = os.nodename;
91  
92          /* get uptime */
93 + #ifdef HPUX
94 +        if (pstat_getstatic(&pstat_static, sizeof(pstat_static), 1, 0) == -1) {
95 +                sg_set_error_with_errno(SG_ERROR_PSTAT, "pstat_static");
96 +                return NULL;
97 +        }
98 +
99 +        currtime = time(NULL);
100 +
101 +        boottime = pstat_static.boot_time;
102 +
103 +        general_stat.uptime = currtime - boottime;
104 + #endif
105   #ifdef SOLARIS
106          if ((kc = kstat_open()) == NULL) {
107 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
108                  return NULL;
109          }
110          if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){
111 +                sg_set_error(SG_ERROR_KSTAT_LOOKUP, "unix,-1,system_misc");
112                  return NULL;
113          }
114          if (kstat_read(kc, ksp, 0) == -1) {
115 +                sg_set_error(SG_ERROR_KSTAT_READ, NULL);
116                  return NULL;
117          }
118          if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
119 +                sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "boot_time");
120                  return NULL;
121          }
122          boottime=(kn->value.ui32);
# Line 99 | Line 128 | general_stat_t *get_general_stats(){
128   #endif
129   #if defined(LINUX) || defined(CYGWIN)
130          if ((f=fopen("/proc/uptime", "r")) == NULL) {
131 +                sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/uptime");
132                  return NULL;
133          }
134          if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){
135 +                sg_set_error(SG_ERROR_PARSE, NULL);
136                  return NULL;
137          }
138          fclose(f);
# Line 111 | Line 142 | general_stat_t *get_general_stats(){
142          mib[1] = KERN_BOOTTIME;
143          size = sizeof boottime;
144          if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){
145 +                sg_set_error_with_errno(SG_ERROR_SYSCTL,
146 +                                        "CTL_KERN.KERN_BOOTTIME");
147                  return NULL;
148          }
149          time(&curtime);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines