sys-proctable 0.7.5 → 0.7.6

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.
@@ -0,0 +1,177 @@
1
+ /*****************************************************************************
2
+ * solaris.h
3
+ *
4
+ * Solaris specific header file. Some things copy/pasted straight out
5
+ * of Dan Urist's Proc::ProcessTable Perl module.
6
+ *****************************************************************************/
7
+ #include <stdio.h>
8
+ #include <stdlib.h>
9
+ #include <dirent.h>
10
+ #include <sys/param.h>
11
+ #include <sys/types.h>
12
+ #include <sys/proc.h>
13
+ #include <fcntl.h>
14
+ #include <string.h>
15
+ #include <unistd.h>
16
+ #include <utmpx.h>
17
+
18
+ /* This bit of magic was taken from a post by Stefan Teleman on the KDE
19
+ * mailing list. It allows us to build without having to disable largefile
20
+ * support or explicitly build a 64 bit Ruby.
21
+ */
22
+ #if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
23
+ #define PROCFS_FILE_OFFSET_BITS_HACK 1
24
+ #undef _FILE_OFFSET_BITS
25
+ #else
26
+ #define PROCFS_FILE_OFFSET_BITS_HACK 0
27
+ #endif
28
+
29
+ #if defined(HAVE_PROCFS_H)
30
+ #include <procfs.h>
31
+ #else
32
+ #include <sys/procfs.h>
33
+ #endif
34
+
35
+ #if (PROCFS_FILE_OFFSET_BITS_HACK - 0 == 1)
36
+ #define _FILE_OFFSET_BITS 64
37
+ #endif
38
+
39
+ #ifndef CLK_TCK
40
+ #define CLK_TCK sysconf(_SC_CLK_TCK)
41
+ #endif
42
+
43
+ #ifndef NAME_MAX
44
+ #define NAME_MAX 255
45
+ #endif
46
+
47
+ /* Ruby 1.8.3 or later */
48
+ #ifdef HAVE_TYPE_RB_PID_T
49
+ #define pid_t rb_pid_t
50
+ #endif
51
+
52
+ #define COMM_MAX 64
53
+ #define STATE_MAX 20
54
+ #define WCHAN_MAX 64
55
+
56
+ /* Function prototypes */
57
+ static void getprusage(pid_t pid, prusage_t* pr_usage);
58
+
59
+ /* Process state strings that we return */
60
+ #define SLEEP "sleep"
61
+ #define WAIT "wait"
62
+ #define RUN "run"
63
+ #define IDLE "idle"
64
+ #define ZOMBIE "zombie"
65
+ #define STOP "stop"
66
+ #define ONPROC "onprocessor"
67
+
68
+ /*
69
+ * A simple static structure, mainly for use with the 'fields()' class method.
70
+ * The fields here *should* be identical to the fields listed in the ps_struct.
71
+ * The exception is the 'comm' field, which I added to give it a bit of
72
+ * (foolish?) consistency with the other platforms. I will try to make sure
73
+ * that field is common to all platforms.
74
+ */
75
+ static char* fields[] = {
76
+ "flag",
77
+ #ifdef HAVE_PROCFS_H
78
+ "nlwp",
79
+ #endif
80
+ "pid",
81
+ "ppid",
82
+ "pgid",
83
+ "sid",
84
+ "uid",
85
+ "euid",
86
+ "gid",
87
+ "egid",
88
+ "priority",
89
+ "nice",
90
+ "ttydev",
91
+ "time",
92
+ "ctime",
93
+ "size",
94
+ "rss",
95
+ "wchan",
96
+ "pctcpu",
97
+ "pctmem",
98
+ "state",
99
+ "fname",
100
+ "cmdline",
101
+ "start",
102
+ #ifdef HAVE_PROCFS_H
103
+ "processor",
104
+ #endif
105
+ "comm",
106
+ "num_args",
107
+ "cmd_args",
108
+ "lwpid",
109
+ "count",
110
+ "tstamp",
111
+ "create",
112
+ "term",
113
+ "rtime",
114
+ "utime",
115
+ "stime",
116
+ "ttime",
117
+ "tftime",
118
+ "dftime",
119
+ "kftime",
120
+ "ltime",
121
+ "slptime",
122
+ "wtime",
123
+ "stoptime",
124
+ "minf",
125
+ "majf",
126
+ "nswap",
127
+ "inblk",
128
+ "oublk",
129
+ "msnd",
130
+ "mrcv",
131
+ "sigs",
132
+ "vctx",
133
+ "ictx",
134
+ "sysc",
135
+ "ioch"
136
+ };
137
+
138
+ /*
139
+ * Private function for getting data out of the /proc/self/usage directory.
140
+ * Based on Rich Teer's function in "Solaris Systems Programming", p.329
141
+ * and p.332.
142
+ */
143
+ #if defined(HAVE_PROCFS_H)
144
+ static void getprusage(pid_t pid, prusage_t* pr_usage){
145
+ int fd;
146
+ char name[PATH_MAX];
147
+
148
+ snprintf(name, PATH_MAX, "/proc/%ld/usage", (long)pid);
149
+
150
+ if((fd = open(name, O_RDONLY)) == -1)
151
+ rb_sys_fail(0);
152
+
153
+ if(read(fd,pr_usage,sizeof(prusage_t)) == -1){
154
+ close(fd);
155
+ rb_sys_fail(0);
156
+ }
157
+
158
+ close(fd);
159
+ }
160
+ #else
161
+ static void getprusage(pid_t pid, prusage_t* pr_usage){
162
+ int fd;
163
+ char name[PATH_MAX];
164
+
165
+ snprintf(name, PATH_MAX, "/proc/%ld", (long)pid);
166
+
167
+ if((fd = open(name, O_RDONLY)) == -1)
168
+ rb_sys_fail(0);
169
+
170
+ if(ioctl(fd,PIOCUSAGE,pr_usage) == -1){
171
+ close(fd);
172
+ rb_sys_fail(0);
173
+ }
174
+
175
+ close(fd);
176
+ }
177
+ #endif
@@ -1,2 +1,2 @@
1
1
  /* version.h - stores the version number for all platforms (that use C) */
2
- #define SYS_PROCTABLE_VERSION "0.7.5"
2
+ #define SYS_PROCTABLE_VERSION "0.7.6"
@@ -1,35 +1,22 @@
1
- ##################################################
1
+ #######################################################################
2
2
  # tc_all.rb
3
3
  #
4
- # Test suite for methods common to all platforms.
5
- ##################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- require 'fileutils'
10
- Dir.chdir '..' if base == 'test'
11
-
12
- if RUBY_PLATFORM.match('mswin')
13
- File.rename('lib/sys/windows.rb', 'lib/sys/proctable.rb')
14
- else
15
- require 'rbconfig'
16
- file = 'ext/proctable.' + Config::CONFIG['DLEXT']
17
- Dir.mkdir('sys') unless File.exists?('sys')
18
- FileUtils.cp(file, 'sys')
19
- end
20
-
21
- $LOAD_PATH.unshift(Dir.pwd)
22
- $LOAD_PATH.unshift(Dir.pwd + '/lib')
23
- end
24
-
4
+ # Test suite for methods common to all platforms. Generally speaking
5
+ # you should run this test case using the 'rake test' task.
6
+ #######################################################################
7
+ require 'socket'
25
8
  require 'test/unit'
26
9
  require 'sys/proctable'
27
10
  include Sys
28
11
 
29
12
  class TC_ProcTable_All < Test::Unit::TestCase
13
+ def setup
14
+ @host = Socket.gethostname
15
+ @pid = RUBY_PLATFORM.match('mswin') ? 0 : 1
16
+ end
30
17
 
31
18
  def test_version
32
- assert_equal('0.7.5', ProcTable::VERSION)
19
+ assert_equal('0.7.6', ProcTable::VERSION)
33
20
  end
34
21
 
35
22
  def test_fields
@@ -49,17 +36,24 @@ class TC_ProcTable_All < Test::Unit::TestCase
49
36
  assert_nothing_raised{ ProcTable.ps(0) }
50
37
  assert_nothing_raised{ ProcTable.ps(nil) }
51
38
  assert_raises(TypeError){ ProcTable.ps('vim') }
52
- assert_raises(ArgumentError){ ProcTable.ps(0,1) }
39
+
40
+ if RUBY_PLATFORM.match('mswin')
41
+ assert_nothing_raised{ ProcTable.ps(0, @host) }
42
+ assert_raises(ArgumentError){ ProcTable.ps(0, @host, 1) }
43
+ else
44
+ assert_raises(ArgumentError){ ProcTable.ps(0, @host) }
45
+ end
53
46
  end
54
47
 
55
48
  def test_ps_return_values
56
49
  assert_kind_of(Array, ProcTable.ps)
57
- assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(1))
50
+ assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(@pid))
58
51
  assert_equal(nil, ProcTable.ps(999999999))
59
52
  assert_equal(nil, ProcTable.ps{})
60
53
  end
61
-
62
- alias :set_up :setup
63
- alias :tear_down :teardown
64
-
54
+
55
+ def teardown
56
+ @host = nil
57
+ @pid = nil
58
+ end
65
59
  end
@@ -3,27 +3,12 @@
3
3
  #
4
4
  # Test suite for sys-proctable for FreeBSD.
5
5
  ############################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- require 'fileutils'
10
- require 'rbconfig'
11
-
12
- Dir.chdir '..' if base == 'test'
13
- file = 'ext/proctable.' + Config::CONFIG['DLEXT']
14
- Dir.mkdir('sys') unless File.exists?('sys')
15
- FileUtils.cp(file, 'sys')
16
-
17
- $LOAD_PATH.unshift(Dir.pwd)
18
- end
19
-
20
6
  require "sys/proctable"
21
7
  require "test/unit"
22
8
  require "test/tc_all"
23
9
  include Sys
24
10
 
25
11
  class TC_ProcTable_FreeBSD < Test::Unit::TestCase
26
-
27
12
  def setup
28
13
  @fields = %w/
29
14
  comm pid ppid pgid sid tdev_maj tdev_min flags start
@@ -57,8 +42,4 @@ class TC_ProcTable_FreeBSD < Test::Unit::TestCase
57
42
  @fields = nil
58
43
  @pt = nil
59
44
  end
60
-
61
- alias :set_up :setup
62
- alias :tear_down :teardown
63
-
64
45
  end
@@ -3,27 +3,12 @@
3
3
  #
4
4
  # Test case for sys-proctable for HP-UX.
5
5
  ##################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- require 'fileutils'
10
- require 'rbconfig'
11
-
12
- Dir.chdir('..') if base == 'test'
13
- file = 'ext/proctable.' + Config::CONFIG['DLEXT']
14
- Dir.mkdir('sys') unless File.exists?('sys')
15
- FileUtils.cp(file, 'sys')
16
-
17
- $LOAD_PATH.unshift(Dir.pwd)
18
- end
19
-
20
6
  require "sys/proctable"
21
7
  require "test/unit"
22
8
  require "test/tc_all"
23
9
  include Sys
24
10
 
25
11
  class TC_ProcTable_HPUX < Test::Unit::TestCase
26
-
27
12
  def setup
28
13
  @fields = %w/
29
14
  comm uid pid ppid dsize tsize ssize nice ttydev pgrp pri addr
@@ -61,7 +46,4 @@ class TC_ProcTable_HPUX < Test::Unit::TestCase
61
46
  @fields = nil
62
47
  @pt = nil
63
48
  end
64
-
65
- alias :set_up :setup
66
- alias :tear_down :teardown
67
49
  end
@@ -3,20 +3,6 @@
3
3
  #
4
4
  # Test suite for the BSD specific version of the kvm interface.
5
5
  ################################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- require 'fileutils'
10
- require 'rbconfig'
11
-
12
- Dir.chdir '..' if base == 'test'
13
- file = 'ext/proctable.' + Config::CONFIG['DLEXT']
14
- Dir.mkdir('sys') unless File.exists?('sys')
15
- FileUtils.cp(file, 'sys')
16
-
17
- $LOAD_PATH.unshift(Dir.pwd)
18
- end
19
-
20
6
  require "test/unit"
21
7
  require "sys/proctable"
22
8
  include Sys
@@ -3,20 +3,8 @@
3
3
  #
4
4
  # Test suite for sys-proctable for Linux.
5
5
  ##########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- require 'fileutils'
10
- require 'rbconfig'
11
-
12
- Dir.chdir('..') if base == 'test'
13
- file = 'ext/proctable.' + Config::CONFIG['DLEXT']
14
- Dir.mkdir('sys') unless File.exists?('sys')
15
- FileUtils.cp(file, 'sys')
16
-
17
- $LOAD_PATH.unshift(Dir.pwd)
18
- end
19
-
6
+ require "sys/proctable"
7
+ require "test/unit"
20
8
  require "test/tc_all"
21
9
 
22
10
  class TC_ProcTable_Linux < Test::Unit::TestCase
@@ -54,8 +42,4 @@ class TC_ProcTable_Linux < Test::Unit::TestCase
54
42
  def teardown
55
43
  @pt = nil
56
44
  end
57
-
58
- alias :set_up :setup
59
- alias :tear_down :teardown
60
-
61
45
  end
@@ -3,20 +3,6 @@
3
3
  #
4
4
  # Test suite for sys-proctable for SunOS/Solaris.
5
5
  ##################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- require 'fileutils'
10
- require 'rbconfig'
11
-
12
- Dir.chdir '..' if base == 'test'
13
- file = 'ext/proctable.' + Config::CONFIG['DLEXT']
14
- Dir.mkdir('sys') unless File.exists?('sys')
15
- FileUtils.cp(file, 'sys')
16
-
17
- $LOAD_PATH.unshift(Dir.pwd)
18
- end
19
-
20
6
  require "sys/proctable"
21
7
  require "test/unit"
22
8
  require "test/tc_all"
@@ -63,7 +49,4 @@ class TC_ProcTable_SunOS < Test::Unit::TestCase
63
49
  @pt = nil
64
50
  @fields = nil
65
51
  end
66
-
67
- alias :set_up :setup
68
- alias :tear_down :teardown
69
52
  end
@@ -3,14 +3,6 @@
3
3
  #
4
4
  # Test suite for the sys-top package that is included with this distribution.
5
5
  ##############################################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- Dir.chdir('..') if base == 'test'
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + '/lib')
12
- end
13
-
14
6
  require 'test/unit'
15
7
  require 'sys/top'
16
8
  include Sys
@@ -3,18 +3,9 @@
3
3
  #
4
4
  # Test suite for sys-proctable for MS Windows
5
5
  ##################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-proctable.*/
9
- Dir.chdir('..') if base == 'test'
10
- File.rename("lib/sys/windows.rb", "lib/sys/proctable.rb")
11
- $LOAD_PATH.unshift(Dir.pwd + '/lib')
12
- end
13
-
14
6
  require 'sys/proctable'
15
7
  require 'test/unit'
16
8
  require 'test/tc_all'
17
- include Sys
18
9
 
19
10
  class TC_ProcTable_MSWindows < Test::Unit::TestCase
20
11
  def setup