sys-uptime 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +10 -0
- data/MANIFEST +13 -17
- data/README +8 -10
- data/doc/uptime.txt +8 -6
- data/ext/extconf.rb +14 -17
- data/ext/uptime.c +49 -29
- data/test/tc_uptime.rb +9 -24
- metadata +4 -4
data/CHANGES
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.5.0 - 30-Mar-2007
|
2
|
+
* For platforms that use C code, the code now always uses the sysctl()
|
3
|
+
function if supported by your system. This replaces the platform specific
|
4
|
+
checks I was doing for the various BSD flavors.
|
5
|
+
* Fix for OS X - the Uptime.boot_time method now works.
|
6
|
+
* UptimeError is now Uptime::Error.
|
7
|
+
* Improved RDoc in the uptime.c source code.
|
8
|
+
* Added a Rakefile - users should now use the 'test' and 'install' rake tasks.
|
9
|
+
* Updates to the MANIFEST, README and uptime.txt files.
|
10
|
+
|
1
11
|
== 0.4.5 - 19-Nov-2006
|
2
12
|
* Internal layout changes, minor doc updates and gemspec improvements.
|
3
13
|
* No code changes.
|
data/MANIFEST
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
CHANGES
|
2
|
-
MANIFEST
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
doc/uptime.txt
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
lib/sys/linux.rb
|
15
|
-
lib/sys/windows.rb
|
16
|
-
|
17
|
-
test/tc_uptime.rb
|
1
|
+
* CHANGES
|
2
|
+
* MANIFEST
|
3
|
+
* Rakefile
|
4
|
+
* README
|
5
|
+
* install.rb
|
6
|
+
* sys-uptime.gemspec
|
7
|
+
* doc/uptime.txt
|
8
|
+
* examples/test.rb
|
9
|
+
* ext/extconf.rb
|
10
|
+
* ext/uptime.c
|
11
|
+
* lib/sys/linux.rb
|
12
|
+
* lib/sys/windows.rb
|
13
|
+
* test/tc_uptime.rb
|
data/README
CHANGED
@@ -4,17 +4,15 @@
|
|
4
4
|
= Prerequisites
|
5
5
|
Ruby 1.8.0 or later.
|
6
6
|
Ruby 1.8.2 or later is recommended on MS Windows.
|
7
|
+
A C compiler, except for MS Windows.
|
7
8
|
|
8
9
|
= Installation
|
9
|
-
===
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=== Windows and Linux:
|
16
|
-
ruby test\tc_uptime.rb (optional)
|
17
|
-
ruby install.rb
|
10
|
+
=== Manual
|
11
|
+
rake test (optional)
|
12
|
+
rake install
|
13
|
+
=== Gems
|
14
|
+
ruby sys-uptime.gemspec
|
15
|
+
gem install sys-uptime-X.Y.Z.gem # Where 'X.Y.Z' are version numbers
|
18
16
|
|
19
17
|
== Notes
|
20
|
-
For additional documentation see doc/uptime.txt.
|
18
|
+
For additional documentation see doc/uptime.txt.
|
data/doc/uptime.txt
CHANGED
@@ -43,10 +43,12 @@ Uptime.uptime
|
|
43
43
|
seconds the system has been running as a colon-separated string.
|
44
44
|
|
45
45
|
== Exceptions
|
46
|
-
|
47
|
-
Raised if something goes wrong.
|
48
|
-
failure of the times() function.
|
49
|
-
|
46
|
+
Uptime::Error
|
47
|
+
Raised if something goes wrong. On Unix, this would likely mean a
|
48
|
+
failure of the times() function. That would be highly unusual.
|
49
|
+
|
50
|
+
On Windows, it probably means you failed to connect to WMI properly. The
|
51
|
+
mostly likely reason would be that the WMI service wasn't running.
|
50
52
|
|
51
53
|
== Notes
|
52
54
|
On MS Windows each of the class methods optionally takes a host name as
|
@@ -73,7 +75,7 @@ UptimeError
|
|
73
75
|
Ruby's
|
74
76
|
|
75
77
|
== Copyright
|
76
|
-
Copyright 2002-
|
78
|
+
Copyright 2002-2007, Daniel J. Berger
|
77
79
|
|
78
80
|
All Rights Reserved. This module is free software. It may be used,
|
79
81
|
redistributed and/or modified under the same terms as Ruby itself.
|
@@ -90,7 +92,7 @@ UptimeError
|
|
90
92
|
|
91
93
|
== Author
|
92
94
|
Daniel J. Berger
|
93
|
-
djberg96 at gmail dot com
|
95
|
+
djberg96 at nospam at gmail dot com
|
94
96
|
imperator on IRC (Freenode)
|
95
97
|
|
96
98
|
== See Also
|
data/ext/extconf.rb
CHANGED
@@ -1,29 +1,26 @@
|
|
1
|
-
|
1
|
+
##########################################################################
|
2
2
|
# extconf.rb
|
3
3
|
#
|
4
|
-
# Configuration & build script for sys-uptime.
|
5
|
-
|
4
|
+
# Configuration & build script for sys-uptime. Generally speaking you
|
5
|
+
# should build sys-uptime with the 'rake build' task instead of running
|
6
|
+
# this script manually.
|
7
|
+
##########################################################################
|
6
8
|
require 'mkmf'
|
7
9
|
require 'fileutils'
|
8
10
|
|
9
11
|
if RUBY_PLATFORM =~ /windows|win32|cygwin|mingw|dos|linux/i
|
10
12
|
STDERR.puts 'Run the "install.rb" script instead on this platform'
|
11
13
|
exit
|
12
|
-
else
|
13
|
-
# Don't install the pure Ruby libraries during 'make install'.
|
14
|
-
if File.basename(Dir.pwd) =~ /ext|sys-uptime/i
|
15
|
-
Dir.chdir('..'){
|
16
|
-
if File.exists?('lib/sys/windows.rb')
|
17
|
-
FileUtils.mv('lib/sys/windows.rb', 'lib/sys/windows.orig')
|
18
|
-
end
|
19
|
-
|
20
|
-
if File.exists?('lib/sys/linux.rb')
|
21
|
-
FileUtils.mv('lib/sys/linux.rb', 'lib/sys/linux.orig')
|
22
|
-
end
|
23
|
-
}
|
24
|
-
end
|
25
14
|
end
|
26
15
|
|
27
16
|
have_header('sys/loadavg.h')
|
28
|
-
|
17
|
+
|
18
|
+
if have_func('sysctl')
|
19
|
+
have_header('sys/param.h')
|
20
|
+
have_header('sys/time.h')
|
21
|
+
have_header('sys/types.h')
|
22
|
+
else
|
23
|
+
have_header('utmpx.h')
|
24
|
+
end
|
25
|
+
|
29
26
|
create_makefile('sys/uptime')
|
data/ext/uptime.c
CHANGED
@@ -8,21 +8,27 @@
|
|
8
8
|
* sys-uptime source code for most *nix platforms
|
9
9
|
*****************************************************************************/
|
10
10
|
#include <ruby.h>
|
11
|
+
#include <string.h>
|
12
|
+
#include <errno.h>
|
11
13
|
|
12
|
-
#
|
13
|
-
|
14
|
+
#ifdef HAVE_SYSCTL
|
15
|
+
|
16
|
+
#include <sys/sysctl.h>
|
14
17
|
|
15
|
-
#
|
18
|
+
#ifdef HAVE_SYS_PARAM_H
|
16
19
|
#include <sys/param.h>
|
17
20
|
#endif
|
18
21
|
|
19
|
-
#
|
20
|
-
#include <sys/
|
22
|
+
#ifdef HAVE_SYS_TIME_H
|
23
|
+
#include <sys/time.h>
|
21
24
|
#endif
|
22
25
|
|
23
|
-
#
|
26
|
+
#ifdef HAVE_SYS_TYPES_H
|
27
|
+
#include <sys/types.h>
|
28
|
+
#endif
|
24
29
|
|
25
30
|
#else
|
31
|
+
|
26
32
|
#include <sys/times.h>
|
27
33
|
#include <unistd.h>
|
28
34
|
#include <time.h>
|
@@ -31,10 +37,6 @@
|
|
31
37
|
#include <utmpx.h>
|
32
38
|
#endif
|
33
39
|
|
34
|
-
#ifdef HAVE_SYS_LOADAVG_H
|
35
|
-
#include <sys/loadavg.h>
|
36
|
-
#endif
|
37
|
-
|
38
40
|
#ifdef _SC_CLK_TCK
|
39
41
|
#define TICKS sysconf(_SC_CLK_TCK)
|
40
42
|
#else
|
@@ -43,24 +45,29 @@
|
|
43
45
|
|
44
46
|
#endif
|
45
47
|
|
48
|
+
#ifdef HAVE_SYS_LOADAVG_H
|
49
|
+
#include <sys/loadavg.h>
|
50
|
+
#endif
|
51
|
+
|
46
52
|
#define MAXSTRINGSIZE 32 /* reasonable limit */
|
47
53
|
|
48
|
-
#define SYS_UPTIME_VERSION "0.
|
54
|
+
#define SYS_UPTIME_VERSION "0.5.0"
|
49
55
|
|
50
56
|
VALUE cUptimeError;
|
51
57
|
|
52
58
|
unsigned long get_uptime_secs()
|
53
59
|
{
|
54
|
-
#
|
60
|
+
#ifdef HAVE_SYSCTL
|
55
61
|
struct timeval tv;
|
56
62
|
size_t tvlen = sizeof(tv);
|
57
63
|
int mib[2];
|
58
64
|
|
59
65
|
mib[0] = CTL_KERN;
|
60
66
|
mib[1] = KERN_BOOTTIME;
|
61
|
-
|
62
|
-
|
63
|
-
|
67
|
+
|
68
|
+
if(sysctl(mib, 2, &tv, &tvlen, NULL, 0))
|
69
|
+
rb_raise(cUptimeError, "sysctl() call failed %s", strerror(errno));
|
70
|
+
|
64
71
|
return time(NULL) - tv.tv_sec;
|
65
72
|
#else
|
66
73
|
struct tms tms;
|
@@ -68,10 +75,10 @@ unsigned long get_uptime_secs()
|
|
68
75
|
seconds = times(&tms) / TICKS;
|
69
76
|
|
70
77
|
if(-1 == seconds)
|
71
|
-
rb_raise(cUptimeError,"times() function failed");
|
78
|
+
rb_raise(cUptimeError, "times() function failed: %s", strerror(errno));
|
72
79
|
|
73
80
|
if(seconds < 0)
|
74
|
-
rb_raise(cUptimeError,"value returned larger than type could handle");
|
81
|
+
rb_raise(cUptimeError, "value returned larger than type could handle");
|
75
82
|
|
76
83
|
return seconds;
|
77
84
|
#endif
|
@@ -142,6 +149,7 @@ static VALUE uptime_uptime()
|
|
142
149
|
seconds -= minutes*60;
|
143
150
|
|
144
151
|
sprintf(c_string, "%ld:%ld:%ld:%ld", days, hours, minutes, seconds);
|
152
|
+
|
145
153
|
return rb_str_new2(c_string);
|
146
154
|
}
|
147
155
|
|
@@ -167,6 +175,7 @@ static VALUE uptime_dhms()
|
|
167
175
|
rb_ary_push(a, INT2FIX(h));
|
168
176
|
rb_ary_push(a, INT2FIX(m));
|
169
177
|
rb_ary_push(a, INT2FIX(s));
|
178
|
+
|
170
179
|
return a;
|
171
180
|
}
|
172
181
|
|
@@ -177,17 +186,20 @@ static VALUE uptime_dhms()
|
|
177
186
|
* Returns the boot time as a Time object.
|
178
187
|
*/
|
179
188
|
static VALUE uptime_btime(){
|
180
|
-
|
189
|
+
VALUE v_time = Qnil;
|
190
|
+
|
191
|
+
#ifdef HAVE_SYSCTL
|
181
192
|
struct timeval tv;
|
182
193
|
size_t tvlen = sizeof(tv);
|
183
194
|
int mib[2];
|
184
195
|
|
185
196
|
mib[0] = CTL_KERN;
|
186
197
|
mib[1] = KERN_BOOTTIME;
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
198
|
+
|
199
|
+
if(sysctl(mib, 2, &tv, &tvlen, NULL, 0))
|
200
|
+
rb_raise(cUptimeError, "sysctl() call failed: %s", strerror(errno));
|
201
|
+
|
202
|
+
v_time = rb_time_new(tv.tv_sec,tv.tv_usec);
|
191
203
|
#else
|
192
204
|
#ifdef HAVE_UTMPX_H
|
193
205
|
struct utmpx* ent;
|
@@ -196,28 +208,36 @@ static VALUE uptime_btime(){
|
|
196
208
|
|
197
209
|
while( (ent = getutxent()) ){
|
198
210
|
if(ent->ut_type == BOOT_TIME){
|
199
|
-
|
200
|
-
|
211
|
+
v_time = rb_time_new(ent->ut_tv.tv_sec, ent->ut_tv.tv_usec);
|
212
|
+
break;
|
213
|
+
}
|
201
214
|
}
|
202
215
|
|
203
216
|
endutxent();
|
204
217
|
#else
|
205
|
-
rb_raise(cUptimeError,"boot_time
|
218
|
+
rb_raise(cUptimeError, "boot_time method not implemented on this platform");
|
206
219
|
#endif
|
207
220
|
#endif
|
208
|
-
|
221
|
+
|
222
|
+
return v_time;
|
209
223
|
}
|
210
224
|
|
211
225
|
void Init_uptime()
|
212
226
|
{
|
213
227
|
VALUE mSys, cUptime;
|
214
228
|
|
215
|
-
/*
|
229
|
+
/* The Sys module only serves as a toplevel namespace */
|
216
230
|
mSys = rb_define_module("Sys");
|
231
|
+
|
232
|
+
/* The Uptime class contains several class methods for obtaining uptime
|
233
|
+
* information.
|
234
|
+
*/
|
217
235
|
cUptime = rb_define_class_under(mSys, "Uptime", rb_cObject);
|
218
|
-
|
236
|
+
|
237
|
+
/* The Uptime::Error class is raised if any of the Uptime methods fail */
|
238
|
+
cUptimeError = rb_define_class_under(cUptime, "Error", rb_eStandardError);
|
219
239
|
|
220
|
-
/*
|
240
|
+
/* 0.5.0: The version of this package, returned as a String */
|
221
241
|
rb_define_const(cUptime, "VERSION", rb_str_new2(SYS_UPTIME_VERSION));
|
222
242
|
|
223
243
|
/* Class Methods */
|
data/test/tc_uptime.rb
CHANGED
@@ -1,35 +1,16 @@
|
|
1
|
-
|
1
|
+
#####################################################################
|
2
2
|
# tc_uptime.rb
|
3
3
|
#
|
4
|
-
# Test suite for sys-uptime.
|
5
|
-
|
6
|
-
|
7
|
-
if base == 'test' || base =~ /sys-uptime.*/
|
8
|
-
require 'fileutils'
|
9
|
-
Dir.chdir('..') if base == 'test'
|
10
|
-
Dir.mkdir('sys') unless File.exists?('sys')
|
11
|
-
|
12
|
-
if RUBY_PLATFORM.match('mswin')
|
13
|
-
FileUtils.cp('lib/sys/windows.rb', 'sys/uptime.rb') rescue nil
|
14
|
-
elsif RUBY_PLATFORM.match('linux')
|
15
|
-
FileUtils.cp('lib/sys/linux.rb', 'sys/uptime.rb') rescue nil
|
16
|
-
else
|
17
|
-
require 'rbconfig'
|
18
|
-
file = 'ext/uptime.' + Config::CONFIG['DLEXT']
|
19
|
-
FileUtils.cp(file, 'sys')
|
20
|
-
end
|
21
|
-
|
22
|
-
$LOAD_PATH.unshift(Dir.pwd)
|
23
|
-
$LOAD_PATH.unshift(Dir.pwd + '/lib')
|
24
|
-
end
|
25
|
-
|
4
|
+
# Test suite for sys-uptime. This should generally be run via the
|
5
|
+
# 'rake test' task, since it handles the pre-setup code for you.
|
6
|
+
#####################################################################
|
26
7
|
require 'sys/uptime'
|
27
8
|
require 'test/unit'
|
28
9
|
include Sys
|
29
10
|
|
30
11
|
class TC_Uptime < Test::Unit::TestCase
|
31
12
|
def test_version
|
32
|
-
assert_equal('0.
|
13
|
+
assert_equal('0.5.0', Uptime::VERSION)
|
33
14
|
end
|
34
15
|
|
35
16
|
def test_seconds
|
@@ -77,4 +58,8 @@ class TC_Uptime < Test::Unit::TestCase
|
|
77
58
|
assert_nothing_raised{ Uptime.boot_time }
|
78
59
|
assert_kind_of(Time, Uptime.boot_time)
|
79
60
|
end
|
61
|
+
|
62
|
+
def test_uptime_error
|
63
|
+
assert_kind_of(StandardError, Uptime::Error.new)
|
64
|
+
end
|
80
65
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: sys-uptime
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2007-03-30 00:00:00 -06:00
|
8
8
|
summary: A Ruby interface for getting system uptime information.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,8 +34,8 @@ files:
|
|
34
34
|
- CHANGES
|
35
35
|
- README
|
36
36
|
- MANIFEST
|
37
|
-
- ext/uptime.c
|
38
37
|
- ext/extconf.rb
|
38
|
+
- ext/uptime.c
|
39
39
|
test_files:
|
40
40
|
- test/tc_uptime.rb
|
41
41
|
rdoc_options: []
|