ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/os_info.c
Revision: 1.8
Committed: Sat Oct 18 23:04:23 2003 UTC (20 years, 7 months ago) by ats
Content type: text/plain
Branch: MAIN
Changes since 1.7: +1 -0 lines
Log Message:
... and the size parameter should be initialised to the size of the
buffer first (although FreeBSD doesn't actually seem to care, NetBSD
does, and the manual page says so).

File Contents

# User Rev Content
1 pajs 1.1 /*
2     * i-scream central monitoring system
3 tdb 1.6 * http://www.i-scream.org
4     * Copyright (C) 2000-2003 i-scream
5 pajs 1.1 *
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.
10     *
11     * This program 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.
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.
19     */
20    
21     #ifdef HAVE_CONFIG_H
22     #include "config.h"
23     #endif
24    
25 tdb 1.3 #include <sys/utsname.h>
26 pajs 1.1 #include "statgrab.h"
27     #ifdef SOLARIS
28     #include <kstat.h>
29     #include <time.h>
30     #endif
31 pajs 1.4 #ifdef LINUX
32     #include <stdio.h>
33     #endif
34 pajs 1.5 #ifdef FREEBSD
35     #include <sys/types.h>
36     #include <sys/sysctl.h>
37     #include <time.h>
38     #include <sys/time.h>
39     #endif
40 pajs 1.1
41     general_stat_t *get_general_stats(){
42    
43     static general_stat_t general_stat;
44 pajs 1.4 static struct utsname os;
45 pajs 1.1
46 pajs 1.4 #ifdef SOLARIS
47 pajs 1.1 time_t boottime,curtime;
48     kstat_ctl_t *kc;
49     kstat_t *ksp;
50     kstat_named_t *kn;
51 pajs 1.4 #endif
52     #ifdef LINUX
53     FILE *f;
54     #endif
55 pajs 1.5 #ifdef FREEBSD
56     struct timeval boottime;
57     time_t curtime;
58     size_t size;
59     #endif
60 pajs 1.1
61     if((uname(&os)) < 0){
62     return NULL;
63     }
64    
65     general_stat.os_name = os.sysname;
66     general_stat.os_release = os.release;
67     general_stat.os_version = os.version;
68     general_stat.platform = os.machine;
69     general_stat.hostname = os.nodename;
70    
71     /* get uptime */
72 pajs 1.4 #ifdef SOLARIS
73 pajs 1.1 if ((kc = kstat_open()) == NULL) {
74     return NULL;
75     }
76     if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){
77     return NULL;
78     }
79     if (kstat_read(kc, ksp, 0) == -1) {
80     return NULL;
81     }
82     if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
83     return NULL;
84     }
85     boottime=(kn->value.ui32);
86 pajs 1.2
87     kstat_close(kc);
88 pajs 1.1
89     time(&curtime);
90     general_stat.uptime = curtime - boottime;
91 pajs 1.4 #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 pajs 1.5 #endif
101     #ifdef FREEBSD
102 ats 1.8 size = sizeof boottime;
103 ats 1.7 if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0){
104 pajs 1.5 return NULL;
105     }
106     time(&curtime);
107     general_stat.uptime=curtime-boottime.tv_sec;
108 pajs 1.4 #endif
109 pajs 1.1
110     return &general_stat;
111    
112     }