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

# Content
1 /*
2 * i-scream central monitoring system
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
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 #include <sys/utsname.h>
26 #include "statgrab.h"
27 #ifdef SOLARIS
28 #include <kstat.h>
29 #include <time.h>
30 #endif
31 #ifdef LINUX
32 #include <stdio.h>
33 #endif
34 #ifdef FREEBSD
35 #include <sys/types.h>
36 #include <sys/sysctl.h>
37 #include <time.h>
38 #include <sys/time.h>
39 #endif
40
41 general_stat_t *get_general_stats(){
42
43 static general_stat_t general_stat;
44 static struct utsname os;
45
46 #ifdef SOLARIS
47 time_t boottime,curtime;
48 kstat_ctl_t *kc;
49 kstat_t *ksp;
50 kstat_named_t *kn;
51 #endif
52 #ifdef LINUX
53 FILE *f;
54 #endif
55 #ifdef FREEBSD
56 struct timeval boottime;
57 time_t curtime;
58 size_t size;
59 #endif
60
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 #ifdef SOLARIS
73 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
87 kstat_close(kc);
88
89 time(&curtime);
90 general_stat.uptime = curtime - boottime;
91 #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 #endif
101 #ifdef FREEBSD
102 size = sizeof boottime;
103 if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0){
104 return NULL;
105 }
106 time(&curtime);
107 general_stat.uptime=curtime-boottime.tv_sec;
108 #endif
109
110 return &general_stat;
111
112 }