ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/libstatgrab/os_info.c
Revision: 1.8
Committed: Mon Mar 3 12:32:36 2003 UTC (21 years, 8 months ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +0 -0 lines
State: FILE REMOVED
Error occurred while calculating annotation data.
Log Message:
Following up on Pete's commit of the new ihost - the new configure stuff.
Also dropped the old libstatgrab.

File Contents

# Content
1 /*
2 * i-scream central monitoring system
3 * http://www.i-scream.org.uk
4 * Copyright (C) 2000-2002 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 "ukcprog.h"
27 #include <stdio.h>
28 #ifdef SOLARIS
29 #include <kstat.h>
30 #include <time.h>
31 #endif
32 #ifdef FREEBSD
33 #include <sys/types.h>
34 #include <sys/sysctl.h>
35 #include <time.h>
36 #include <sys/time.h>
37 #endif
38
39 char *get_os_info(){
40 char *xml_os_info;
41 struct utsname os;
42 long uptime;
43 #ifdef SOLARIS
44 time_t boottime,curtime;
45 kstat_ctl_t *kc;
46 kstat_t *ksp;
47 kstat_named_t *kn;
48 #endif
49 #ifdef LINUX
50 FILE *f;
51 #endif
52 #ifdef FREEBSD
53 struct timeval boottime;
54 time_t curtime;
55 size_t size;
56 #endif
57 if((uname(&os)) < 0){
58 errf("Failed to get os stats (%m)");
59 return NULL;
60 }
61
62 /* Get the uptime */
63 #ifdef SOLARIS
64 if ((kc = kstat_open()) == NULL) {
65 errf("kstat_open failure (%m)");
66 return NULL;
67 }
68 if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){
69 errf("failed to find lookup information (%m)");
70 return NULL;
71 }
72 if (kstat_read(kc, ksp, 0) == -1) {
73 errf("Failed to read kernel information (%m)");
74 return NULL;
75 }
76 if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
77 errf("Failed to get uptime (%m)");
78 return NULL;
79 }
80 boottime=(kn->value.ui32);
81 time(&curtime);
82 if((kstat_close(kc)) != 0){
83 errf("Failed to close kstat control structure (%m)");
84 return NULL;
85 }
86 uptime=curtime-boottime;
87 #endif
88 #ifdef LINUX
89 if ((f=fopen("/proc/uptime", "r")) == NULL) {
90 errf("Failed to open /proc/uptime (%m)");
91 return NULL;
92 }
93 if((fscanf(f,"%ld",&uptime)) != 1){
94 errf("Failed to read uptime (%m)");
95 return NULL;
96 }
97 if ((fclose(f)) != 0) {
98 errf("Failed to close file (%m)");
99 return NULL;
100 }
101 #endif
102 #ifdef FREEBSD
103 #define BOOT_TIME_NAME "kern.boottime"
104
105 if (sysctlbyname(BOOT_TIME_NAME, NULL, &size, NULL, NULL) < 0){
106 errf("sysctlbyname failed (%m)");
107 return NULL;
108 }
109 if (sysctlbyname(BOOT_TIME_NAME, &boottime, &size, NULL, NULL) < 0){
110 errf("sysctlbyname failed (%m)");
111 return NULL;
112 }
113 time(&curtime);
114 uptime=curtime-boottime.tv_sec;
115
116 #endif
117
118
119 xml_os_info=strf("<os><name>%s</name><release>%s</release><version>%s</version><sysname>%s</sysname><platform>%s</platform><uptime>%ld</uptime></os>", os.sysname, os.release, os.version, os.nodename, os.machine, uptime);
120
121 return xml_os_info;
122 }