Skip to content

Commit 2f98451

Browse files
committed
Revert "Add os.cpus() and os.uptime() support for sunos"
Cherry-pick fail. Breaks linux. Will land again shortly. This reverts commit e8cf98c. This reverts commit d953856. This reverts commit 752bbd6.
1 parent e8cf98c commit 2f98451

File tree

4 files changed

+13
-161
lines changed

4 files changed

+13
-161
lines changed

src/platform.h

-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
#define NODE_PLATFORM_H_
2424

2525
#include <v8.h>
26-
#ifdef __sun
27-
#include <kstat.h>
28-
#endif
2926

3027
namespace node {
3128

@@ -42,7 +39,6 @@ class Platform {
4239
static double GetTotalMemory();
4340
static double GetUptime();
4441
static int GetLoadAvg(v8::Local<v8::Array> *loads);
45-
static v8::Handle<v8::Value> GetInterfaceAddresses();
4642
};
4743

4844

src/platform_sunos.cc

+4-128
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
#include <stdlib.h> /* getexecname() */
2828
#include <strings.h> /* strncpy() */
2929

30-
#include <kstat.h>
31-
#include <errno.h>
32-
#include <inttypes.h>
33-
#include <sys/types.h>
3430

3531
#if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
3632
#define PROCFS_FILE_OFFSET_BITS_HACK 1
@@ -50,7 +46,6 @@ namespace node {
5046

5147
using namespace v8;
5248

53-
5449
char** Platform::SetupArgs(int argc, char *argv[]) {
5550
return argv;
5651
}
@@ -113,103 +108,11 @@ int Platform::GetExecutablePath(char* buffer, size_t* size) {
113108
}
114109

115110

116-
static Handle<Value> data_named(kstat_named_t *knp) {
117-
Handle<Value> val;
118-
119-
switch (knp->data_type) {
120-
case KSTAT_DATA_CHAR:
121-
val = Number::New(knp->value.c[0]);
122-
break;
123-
case KSTAT_DATA_INT32:
124-
val = Number::New(knp->value.i32);
125-
break;
126-
case KSTAT_DATA_UINT32:
127-
val = Number::New(knp->value.ui32);
128-
break;
129-
case KSTAT_DATA_INT64:
130-
val = Number::New(knp->value.i64);
131-
break;
132-
case KSTAT_DATA_UINT64:
133-
val = Number::New(knp->value.ui64);
134-
break;
135-
case KSTAT_DATA_STRING:
136-
val = String::New(KSTAT_NAMED_STR_PTR(knp));
137-
break;
138-
default:
139-
throw (String::New("unrecognized data type"));
140-
}
141-
142-
return (val);
143-
}
111+
// TODO: libkstat provides all this info. Need to link it though.
144112

145113

146114
int Platform::GetCPUInfo(Local<Array> *cpus) {
147-
HandleScope scope;
148-
Local<Object> cpuinfo;
149-
Local<Object> cputimes;
150-
151-
int lookup_instance;
152-
kstat_ctl_t *kc;
153-
kstat_t *ksp;
154-
kstat_named_t *knp;
155-
156-
if ((kc = kstat_open()) == NULL)
157-
throw "could not open kstat";
158-
159-
*cpus = Array::New();
160-
161-
lookup_instance = 0;
162-
while (ksp = kstat_lookup(kc, "cpu_info", lookup_instance, NULL)) {
163-
cpuinfo = Object::New();
164-
165-
if (kstat_read(kc, ksp, NULL) == -1) {
166-
/*
167-
* It is deeply annoying, but some kstats can return errors
168-
* under otherwise routine conditions. (ACPI is one
169-
* offender; there are surely others.) To prevent these
170-
* fouled kstats from completely ruining our day, we assign
171-
* an "error" member to the return value that consists of
172-
* the strerror().
173-
*/
174-
cpuinfo->Set(String::New("error"), String::New(strerror(errno)));
175-
(*cpus)->Set(lookup_instance, cpuinfo);
176-
} else {
177-
knp = (kstat_named_t *) kstat_data_lookup(ksp, "clock_MHz");
178-
cpuinfo->Set(String::New("speed"), data_named(knp));
179-
knp = (kstat_named_t *) kstat_data_lookup(ksp, "brand");
180-
cpuinfo->Set(String::New("model"), data_named(knp));
181-
(*cpus)->Set(lookup_instance, cpuinfo);
182-
}
183-
184-
lookup_instance++;
185-
}
186-
187-
lookup_instance = 0;
188-
while (ksp = kstat_lookup(kc, "cpu", lookup_instance, "sys")){
189-
cpuinfo = (*cpus)->Get(lookup_instance)->ToObject();
190-
cputimes = Object::New();
191-
192-
if (kstat_read(kc, ksp, NULL) == -1) {
193-
cputimes->Set(String::New("error"), String::New(strerror(errno)));
194-
cpuinfo->Set(String::New("times"), cpuinfo);
195-
} else {
196-
knp = (kstat_named_t *) kstat_data_lookup(ksp, "cpu_ticks_kernel");
197-
cputimes->Set(String::New("system"), data_named(knp));
198-
knp = (kstat_named_t *) kstat_data_lookup(ksp, "cpu_ticks_user");
199-
cputimes->Set(String::New("user"), data_named(knp));
200-
knp = (kstat_named_t *) kstat_data_lookup(ksp, "cpu_ticks_idle");
201-
cputimes->Set(String::New("idle"), data_named(knp));
202-
knp = (kstat_named_t *) kstat_data_lookup(ksp, "intr");
203-
cputimes->Set(String::New("irq"), data_named(knp));
204-
205-
cpuinfo->Set(String::New("times"), cputimes);
206-
}
207-
208-
lookup_instance++;
209-
}
210-
211-
kstat_close(kc);
212-
115+
// http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/cmd/psrinfo/psrinfo.pl
213116
return 0;
214117
}
215118

@@ -225,29 +128,8 @@ double Platform::GetTotalMemory() {
225128

226129

227130
double Platform::GetUptime() {
228-
kstat_ctl_t *kc;
229-
kstat_t *ksp;
230-
kstat_named_t *knp;
231-
232-
long hz = sysconf(_SC_CLK_TCK);
233-
ulong_t clk_intr;
234-
235-
if ((kc = kstat_open()) == NULL) {
236-
throw "could not open kstat";
237-
}
238-
239-
ksp = kstat_lookup(kc, "unix", 0, "system_misc");
240-
241-
if (kstat_read(kc, ksp, NULL) == -1) {
242-
throw "unable to read kstat";
243-
} else {
244-
knp = (kstat_named_t *) kstat_data_lookup(ksp, "clk_intr");
245-
clk_intr = knp->value.ul;
246-
}
247-
248-
kstat_close(kc);
249-
250-
return static_cast<double>(clk_intr / hz);
131+
// http://munin-monitoring.org/attachment/ticket/419/uptime
132+
return 0.0;
251133
}
252134

253135

@@ -256,11 +138,5 @@ int Platform::GetLoadAvg(Local<Array> *loads) {
256138
}
257139

258140

259-
Handle<Value> Platform::GetInterfaceAddresses() {
260-
HandleScope scope;
261-
return scope.Close(Object::New());
262-
}
263-
264-
265141
} // namespace node
266142

test/simple/test-os.js

+8-26
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,11 @@ var common = require('../common');
2323
var assert = require('assert');
2424
var os = require('os');
2525

26-
var hostname = os.hostname()
27-
console.log("hostname = %s", hostname);
28-
assert.ok(hostname.length > 0);
29-
30-
var uptime = os.uptime();
31-
console.log("uptime = %d", uptime);
32-
assert.ok(uptime > 0);
33-
34-
var cpus = os.cpus();
35-
console.log("cpus = ", cpus);
36-
assert.ok(cpus.length > 0);
37-
38-
var type = os.type();
39-
console.log("type = ", type);
40-
assert.ok(type.length > 0);
41-
42-
var release = os.release();
43-
console.log("release = ", release);
44-
assert.ok(release > 0);
45-
46-
if (process.platform != 'sunos') {
47-
// not implemeneted yet
48-
assert.ok(os.loadavg().length > 0);
49-
assert.ok(os.freemem() > 0);
50-
assert.ok(os.totalmem() > 0);
51-
}
26+
assert.ok(os.hostname().length > 0);
27+
assert.ok(os.loadavg().length > 0);
28+
assert.ok(os.uptime() > 0);
29+
assert.ok(os.freemem() > 0);
30+
assert.ok(os.totalmem() > 0);
31+
assert.ok(os.cpus().length > 0);
32+
assert.ok(os.type().length > 0);
33+
assert.ok(os.release().length > 0);

wscript

+1-3
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,6 @@ def configure(conf):
359359
conf.fatal("Cannot find socket library")
360360
if not conf.check(lib='nsl', uselib_store="NSL"):
361361
conf.fatal("Cannot find nsl library")
362-
if not conf.check(lib='kstat', uselib_store="KSTAT"):
363-
conf.fatal("Cannot find kstat library")
364362

365363
conf.sub_config('deps/libeio')
366364

@@ -804,7 +802,7 @@ def build(bld):
804802
node = bld.new_task_gen("cxx", product_type)
805803
node.name = "node"
806804
node.target = "node"
807-
node.uselib = 'RT EV OPENSSL CARES EXECINFO DL KVM SOCKET NSL KSTAT UTIL OPROFILE'
805+
node.uselib = 'RT EV OPENSSL CARES EXECINFO DL KVM SOCKET NSL UTIL OPROFILE'
808806
node.add_objects = 'eio http_parser'
809807
if product_type_is_lib:
810808
node.install_path = '${LIBDIR}'

0 commit comments

Comments
 (0)