sys-proctable 1.2.7 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc04e64b1355f4df7eef6d44666c323d45bb3d6dde7ced1d078ab7b3a0108367
4
- data.tar.gz: 64227d33681d13797ca0911199d2040f097e32de56656506d28f232d2adb7938
3
+ metadata.gz: 30b96245d1885b969f8aaa3098d42e38082ef4b3eb221c77aaa009aeff77f6af
4
+ data.tar.gz: 569dea384f6de6a9c1f1bea3a44cc62295e93f07fb7f6cc81d085a23746cf7c8
5
5
  SHA512:
6
- metadata.gz: 1fa256e92c462347cabca2d4992c74dc5cbfdf7985159668b74617863b321d663209239d4d5c3e00f3cf4cf8275ace09d464fe1782024b2c21855c7128c4a4f1
7
- data.tar.gz: 6c16116b746153a4f75932c5d2f1f5ab560100d648dd5bc904b4f1aca3b434b8667ef41fd89d34e23b303fff38fa6e7a9f089d42be60d8f4628c34e46aeb87af
6
+ metadata.gz: e16055b962e3d7af78309f5e47286e1def1f391b28a818fd4a8f2937e561b17c5dfcf050a5db0b355846639c7314f9a8c1615db6028bf8f4ba9130832532f84a
7
+ data.tar.gz: f2b69818ad45bb9e959eff7c9fe9e4137dc7aecc59378c332ef1637011d8ea1c9ec19749a9ea912f19d694502ba1d989eb37a5e0ab0a4cea51c63a304c134c13
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.3.0 - 26-Dec-2022
2
+ * Added DragonflyBSD support.
3
+ * Reorganized the BSD code so that FreeBSD and Dragonfly BSD live in their
4
+ own space for easier maintenance.
5
+
1
6
  ## 1.2.7 - 28-Oct-2022
2
7
  * Fix bug on Solaris where it would fail trying to read zero-byte pseudo-kernel
3
8
  processes. Thanks go to Robert Waffen for the spot and the patch.
data/MANIFEST.md CHANGED
@@ -14,7 +14,14 @@
14
14
  * lib/sys/proctable/version.rb
15
15
  * lib/aix/sys/proctable.rb
16
16
  * lib/darwin/sys/proctable.rb
17
- * lib/freebsd/sys/proctable.rb
17
+ * lib/bsd/sys/dragonfly/sys/proctable.rb
18
+ * lib/bsd/sys/dragonfly/sys/proctable/constants.rb
19
+ * lib/bsd/sys/dragonfly/sys/proctable/functions.rb
20
+ * lib/bsd/sys/dragonfly/sys/proctable/structs.rb
21
+ * lib/bsd/sys/freebsd/sys/proctable.rb
22
+ * lib/bsd/sys/freebsd/sys/proctable/constants.rb
23
+ * lib/bsd/sys/freebsd/sys/proctable/functions.rb
24
+ * lib/bsd/sys/freebsd/sys/proctable/structs.rb
18
25
  * lib/linux/sys/proctable.rb
19
26
  * lib/sunos/sys/proctable.rb
20
27
  * lib/windows/sys/proctable.rb
data/README.md CHANGED
@@ -18,6 +18,7 @@
18
18
  * Windows 2000 or later
19
19
  * Linux 2.6+
20
20
  * FreeBSD
21
+ * DragonflyBSD
21
22
  * Solaris 8+
22
23
  * OS X 10.7+
23
24
  * AIX 5.3+
data/Rakefile CHANGED
@@ -63,9 +63,9 @@ RSpec::Core::RakeTask.new(:spec) do |t|
63
63
  when /darwin/i
64
64
  t.rspec_opts = '-Ilib/darwin'
65
65
  t.pattern << 'spec/sys_proctable_darwin_spec.rb'
66
- when /freebsd/i
67
- t.rspec_opts = '-Ilib/freebsd'
68
- t.pattern << 'spec/sys_proctable_freebsd_spec.rb'
66
+ when /bsd|dragonfly/i
67
+ t.rspec_opts = '-Ilib/bsd'
68
+ t.pattern << 'spec/sys_proctable_bsd_spec.rb'
69
69
  when /linux/i
70
70
  t.rspec_opts = '-Ilib/linux'
71
71
  t.pattern << 'spec/sys_proctable_linux_spec.rb'
@@ -0,0 +1,11 @@
1
+ module Sys
2
+ module ProcTableConstants
3
+ WMESGLEN = 8
4
+ MAXCOMLEN = 16
5
+ NGROUPS = 16
6
+ MAXLOGNAME = 33
7
+
8
+ KERN_PROC_ALL = 0
9
+ KERN_PROC_PID = 1
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require 'ffi'
2
+
3
+ module Sys
4
+ module ProcTableFunctions
5
+ extend FFI::Library
6
+ ffi_lib :kvm
7
+
8
+ attach_function :devname, [:dev_t, :mode_t], :string
9
+ attach_function :kvm_open, [:string, :string, :string, :int, :string], :pointer
10
+ attach_function :kvm_close, [:pointer], :int
11
+ attach_function :kvm_getprocs, [:pointer, :int, :int, :pointer], :pointer
12
+ attach_function :kvm_getargv, [:pointer, :pointer, :int], :pointer
13
+ end
14
+ end
@@ -0,0 +1,298 @@
1
+ require 'ffi'
2
+ require_relative 'constants'
3
+
4
+ module Sys
5
+ module ProcTableStructs
6
+ extend FFI::Library
7
+
8
+ class Timeval < FFI::Struct
9
+ layout(:tv_sec, :time_t, :tv_usec, :suseconds_t)
10
+ end
11
+
12
+ class RTPrio < FFI::Struct
13
+ layout(:type, :ushort, :prio, :ushort)
14
+ end
15
+
16
+ class Rusage < FFI::Struct
17
+ layout(
18
+ :ru_utime, Timeval,
19
+ :ru_stime, Timeval,
20
+ :ru_maxrss, :long,
21
+ :ru_ixrss, :long,
22
+ :ru_idrss, :long,
23
+ :ru_isrss, :long,
24
+ :ru_minflt, :long,
25
+ :ru_majflt, :long,
26
+ :ru_nswap, :long,
27
+ :ru_inblock, :long,
28
+ :ru_oublock, :long,
29
+ :ru_msgsnd, :long,
30
+ :ru_msgrcv, :long,
31
+ :ru_nsignals, :long,
32
+ :ru_nvcsw, :long,
33
+ :ru_nivcsw, :long
34
+ )
35
+
36
+ def utime
37
+ Time.at(self[:ru_utime][:tv_sec])
38
+ end
39
+
40
+ def stime
41
+ Time.at(self[:ru_stime][:tv_sec])
42
+ end
43
+
44
+ def maxrss
45
+ self[:ru_maxrss]
46
+ end
47
+
48
+ def ixrss
49
+ self[:ru_ixrss]
50
+ end
51
+
52
+ def idrss
53
+ self[:ru_idrss]
54
+ end
55
+
56
+ def isrss
57
+ self[:ru_isrss]
58
+ end
59
+
60
+ def minflt
61
+ self[:ru_minflt]
62
+ end
63
+
64
+ def majflt
65
+ self[:ru_majflt]
66
+ end
67
+
68
+ def nswap
69
+ self[:ru_nswap]
70
+ end
71
+
72
+ def inblock
73
+ self[:ru_inblock]
74
+ end
75
+
76
+ def oublock
77
+ self[:ru_oublock]
78
+ end
79
+
80
+ def msgsnd
81
+ self[:ru_msgsnd]
82
+ end
83
+
84
+ def msgrcv
85
+ self[:ru_msgrcv]
86
+ end
87
+
88
+ def nsignals
89
+ self[:ru_nsignals]
90
+ end
91
+
92
+ def nvcsw
93
+ self[:ru_nivcsw]
94
+ end
95
+
96
+ def nivcsw
97
+ self[:ru_nivcsw]
98
+ end
99
+ end
100
+
101
+ enum :lwpstat, [:LSRUN, 1, :LSSTOP, :LSSLEEP]
102
+ enum :procstat, [:SIDL, 1, :SACTIVE, :SSTOP, :SZOMB, :SCORE]
103
+
104
+ class Sigset < FFI::Struct
105
+ layout(:__bits, [:uint, 4])
106
+
107
+ def bits
108
+ self[:__bits].to_a
109
+ end
110
+ end
111
+
112
+ class KInfoLWP < FFI::Struct
113
+ include Sys::ProcTableConstants
114
+
115
+ layout(
116
+ :kl_pid, :pid_t,
117
+ :kl_tid, :lwpid_t,
118
+ :kl_flags, :int,
119
+ :kl_stat, :lwpstat,
120
+ :kl_lock, :int,
121
+ :kl_tdflags, :int,
122
+ :kl_mpcount, :int,
123
+ :kl_prio, :int,
124
+ :kl_tdprio, :int,
125
+ :kl_rtprio, RTPrio,
126
+ :kl_uticks, :uint64_t,
127
+ :kl_sticks, :uint64_t,
128
+ :kl_iticks, :uint64_t,
129
+ :kl_cpticks, :uint64_t,
130
+ :kl_pctcpu, :uint,
131
+ :kl_slptime, :uint,
132
+ :kl_origcpu, :int,
133
+ :kl_estcpu, :int,
134
+ :kl_cpuid, :int,
135
+ :kl_ru, Rusage,
136
+ :kl_siglist, Sigset,
137
+ :kl_sigmask, Sigset,
138
+ :kl_wchan, :uintptr_t,
139
+ :kl_wmesg, [:char, WMESGLEN+1],
140
+ :kl_comm, [:char, MAXCOMLEN+1]
141
+ )
142
+
143
+ def pid
144
+ self[:kl_pid]
145
+ end
146
+
147
+ def tid
148
+ self[:kl_tid]
149
+ end
150
+
151
+ def flags
152
+ self[:kl_flags]
153
+ end
154
+
155
+ def stat
156
+ self[:kl_stat]
157
+ end
158
+
159
+ def lock
160
+ self[:kl_lock]
161
+ end
162
+
163
+ def tdflags
164
+ self[:kl_tdflags]
165
+ end
166
+
167
+ def prio
168
+ self[:kl_prio]
169
+ end
170
+
171
+ def tdprio
172
+ self[:kl_tdprio]
173
+ end
174
+
175
+ def rtprio
176
+ self[:kl_rtprio]
177
+ end
178
+
179
+ def uticks
180
+ self[:kl_uticks]
181
+ end
182
+
183
+ def sticks
184
+ self[:kl_sticks]
185
+ end
186
+
187
+ def iticks
188
+ self[:kl_iticks]
189
+ end
190
+
191
+ def cpticks
192
+ self[:kl_cpticks]
193
+ end
194
+
195
+ def pctcpu
196
+ self[:kl_pctcpu]
197
+ end
198
+
199
+ def slptime
200
+ self[:kl_slptime]
201
+ end
202
+
203
+ def origcpu
204
+ self[:kl_origcpu]
205
+ end
206
+
207
+ def estcpu
208
+ self[:kl_estcpu]
209
+ end
210
+
211
+ def cpuid
212
+ self[:kl_cpuid]
213
+ end
214
+
215
+ def ru
216
+ self[:kl_ru]
217
+ end
218
+
219
+ def siglist
220
+ self[:kl_siglist]
221
+ end
222
+
223
+ def sigmask
224
+ self[:kl_sigmask]
225
+ end
226
+
227
+ def wchan
228
+ self[:kl_wchan]
229
+ end
230
+
231
+ def wmesg
232
+ self[:kl_wmesg].to_s
233
+ end
234
+
235
+ def comm
236
+ self[:kl_comm].to_s
237
+ end
238
+ end
239
+
240
+ class KInfoProc < FFI::Struct
241
+ include Sys::ProcTableConstants
242
+
243
+ def self.roundup(x, y)
244
+ ((x + y-1) / y) * y
245
+ end
246
+
247
+ layout(
248
+ :kp_paddr, :uintptr_t,
249
+ :kp_flags, :int,
250
+ :kp_stat, :procstat,
251
+ :kp_lock, :int,
252
+ :kp_acflag, :int,
253
+ :kp_traceflag, :int,
254
+ :kp_fd, :uintptr_t,
255
+ :kp_siglist, Sigset,
256
+ :kp_sigignore, Sigset,
257
+ :kp_sigcatch, Sigset,
258
+ :kp_sigflag, :int,
259
+ :kp_start, Timeval,
260
+ :kp_comm, [:char, MAXCOMLEN+1],
261
+ :kp_uid, :uid_t,
262
+ :kp_ngroups, :short,
263
+ :kp_groups, [:gid_t, NGROUPS],
264
+ :kp_ruid, :uid_t,
265
+ :kp_svuid, :uid_t,
266
+ :kp_rgid, :gid_t,
267
+ :kp_svgid, :gid_t,
268
+ :kp_pid, :pid_t,
269
+ :kp_ppid, :pid_t,
270
+ :kp_pgid, :pid_t,
271
+ :kp_jobc, :int,
272
+ :kp_sid, :pid_t,
273
+ :kp_login, [:char, roundup(MAXLOGNAME, FFI::Type::LONG.size)],
274
+ :kp_tdev, :dev_t,
275
+ :kp_tpgid, :pid_t,
276
+ :kp_tsid, :pid_t,
277
+ :kp_exitstat, :ushort,
278
+ :kp_nthreads, :int,
279
+ :kp_nice, :int,
280
+ :kp_swtime, :uint,
281
+ :kp_vm_map_size, :size_t,
282
+ :kp_vm_rssize, :segsz_t,
283
+ :kp_vm_swrss, :segsz_t,
284
+ :kp_vm_tsize, :segsz_t,
285
+ :kp_vm_dsize, :segsz_t,
286
+ :kp_vm_ssize, :segsz_t,
287
+ :kp_vm_prssize, :uint,
288
+ :kp_jailid, :int,
289
+ :kp_ru, Rusage,
290
+ :kp_cru, Rusage,
291
+ :kp_auxflags, :int,
292
+ :kp_lwp, KInfoLWP,
293
+ :kp_ktaddr, :uintptr_t,
294
+ :kp_spare, [:int, 2]
295
+ )
296
+ end
297
+ end
298
+ end
@@ -0,0 +1,175 @@
1
+ require_relative 'proctable/constants'
2
+ require_relative 'proctable/structs'
3
+ require_relative 'proctable/functions'
4
+ require 'sys/proctable/version'
5
+
6
+ module Sys
7
+ class ProcTable
8
+ include Sys::ProcTableConstants
9
+ include Sys::ProcTableStructs
10
+ extend Sys::ProcTableFunctions
11
+
12
+ # Error typically raised if the ProcTable.ps method fails.
13
+ class Error < StandardError; end
14
+
15
+ # There is no constructor
16
+ private_class_method :new
17
+
18
+ @fields = %w[
19
+ paddr flags stat lock acflag traceflag fd siglist sigignore
20
+ sigcatch sigflag start comm uid ngroups groups ruid svuid
21
+ rgid svgid pid ppid pgid jobc sid login tdev tpgid tsid exitstat
22
+ nthreads nice swtime vm_map_size vm_rssize vm_swrss vm_tsize
23
+ vm_dsize vm_ssize vm_prssize jailid ru cru auxflags lwp ktaddr
24
+ ]
25
+
26
+ ProcTableStruct = Struct.new('ProcTableStruct', *@fields) do
27
+ alias cmdline comm
28
+ end
29
+
30
+ # In block form, yields a ProcTableStruct for each process entry that you
31
+ # have rights to. This method returns an array of ProcTableStruct's in
32
+ # non-block form.
33
+ #
34
+ # If a +pid+ is provided, then only a single ProcTableStruct is yielded or
35
+ # returned, or nil if no process information is found for that +pid+.
36
+ #
37
+ # Example:
38
+ #
39
+ # # Iterate over all processes
40
+ # ProcTable.ps do |proc_info|
41
+ # p proc_info
42
+ # end
43
+ #
44
+ # # Print process table information for only pid 1001
45
+ # p ProcTable.ps(pid: 1001)
46
+ #
47
+ def self.ps(**kwargs)
48
+ pid = kwargs[:pid]
49
+
50
+ begin
51
+ kd = kvm_open(nil, nil, nil, 0, nil)
52
+
53
+ if kd.null?
54
+ raise SystemCallError.new('kvm_open', FFI.errno)
55
+ end
56
+
57
+ ptr = FFI::MemoryPointer.new(:int) # count
58
+
59
+ if pid
60
+ procs = kvm_getprocs(kd, KERN_PROC_PID, pid, ptr)
61
+ else
62
+ procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, ptr)
63
+ end
64
+
65
+ if procs.null?
66
+ if pid && FFI.errno == Errno::ESRCH::Errno
67
+ return nil
68
+ else
69
+ raise SystemCallError.new('kvm_getprocs', FFI.errno)
70
+ end
71
+ end
72
+
73
+ count = ptr.read_int
74
+ array = []
75
+
76
+ 0.upto(count-1){ |i|
77
+ cmd = nil
78
+ kinfo = KInfoProc.new(procs[i * KInfoProc.size])
79
+
80
+ args = kvm_getargv(kd, kinfo, 0)
81
+
82
+ unless args.null?
83
+ cmd = []
84
+
85
+ until ((ptr = args.read_pointer).null?)
86
+ cmd << ptr.read_string
87
+ args += FFI::Type::POINTER.size
88
+ end
89
+
90
+ cmd = cmd.join(' ')
91
+ end
92
+
93
+ struct = ProcTableStruct.new(
94
+ kinfo[:kp_paddr],
95
+ kinfo[:kp_flags],
96
+ kinfo[:kp_stat],
97
+ kinfo[:kp_lock],
98
+ kinfo[:kp_acflag],
99
+ kinfo[:kp_traceflag],
100
+ kinfo[:kp_fd],
101
+ kinfo[:kp_siglist].bits,
102
+ kinfo[:kp_sigignore].bits,
103
+ kinfo[:kp_sigcatch].bits,
104
+ kinfo[:kp_sigflag],
105
+ Time.at(kinfo[:kp_start][:tv_sec]),
106
+ kinfo[:kp_comm].to_s,
107
+ kinfo[:kp_uid],
108
+ kinfo[:kp_ngroups],
109
+ kinfo[:kp_groups].to_a[0..kinfo[:kp_ngroups]-1],
110
+ kinfo[:kp_ruid],
111
+ kinfo[:kp_svuid],
112
+ kinfo[:kp_rgid],
113
+ kinfo[:kp_svgid],
114
+ kinfo[:kp_pid],
115
+ kinfo[:kp_ppid],
116
+ kinfo[:kp_pgid],
117
+ kinfo[:kp_jobc],
118
+ kinfo[:kp_sid],
119
+ kinfo[:kp_login].to_s,
120
+ kinfo[:kp_tdev],
121
+ kinfo[:kp_tpgid],
122
+ kinfo[:kp_tsid],
123
+ kinfo[:kp_exitstat],
124
+ kinfo[:kp_nthreads],
125
+ kinfo[:kp_nice],
126
+ kinfo[:kp_swtime],
127
+ kinfo[:kp_vm_map_size],
128
+ kinfo[:kp_vm_rssize],
129
+ kinfo[:kp_vm_swrss],
130
+ kinfo[:kp_vm_tsize],
131
+ kinfo[:kp_vm_dsize],
132
+ kinfo[:kp_vm_ssize],
133
+ kinfo[:kp_vm_prssize],
134
+ kinfo[:kp_jailid],
135
+ kinfo[:kp_ru],
136
+ kinfo[:kp_cru],
137
+ kinfo[:kp_auxflags],
138
+ kinfo[:kp_lwp],
139
+ kinfo[:kp_ktaddr],
140
+ )
141
+
142
+ struct.freeze # This is readonly data
143
+
144
+ if block_given?
145
+ yield struct
146
+ else
147
+ array << struct
148
+ end
149
+ }
150
+ ensure
151
+ kvm_close(kd) unless kd.null?
152
+ end
153
+
154
+ if block_given?
155
+ nil
156
+ else
157
+ pid ? array.first : array
158
+ end
159
+ end
160
+
161
+ # Returns an array of fields that each ProcTableStruct will contain. This
162
+ # may be useful if you want to know in advance what fields are available
163
+ # without having to perform at least one read of the /proc table.
164
+ #
165
+ # Example:
166
+ #
167
+ # Sys::ProcTable.fields.each{ |field|
168
+ # puts "Field: #{field}"
169
+ # }
170
+ #
171
+ def self.fields
172
+ @fields
173
+ end
174
+ end
175
+ end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ case RbConfig::CONFIG['host_os']
2
+ when /freebsd/i
3
+ require_relative 'freebsd/sys/proctable'
4
+ when /dragonfly/i
5
+ require_relative 'dragonfly/sys/proctable'
6
+ else
7
+ raise "Unsupported version of BSD"
8
+ end
@@ -1,6 +1,6 @@
1
1
  module Sys
2
2
  class ProcTable
3
3
  # The version of the sys-proctable library
4
- VERSION = '1.2.7'.freeze
4
+ VERSION = '1.3.0'.freeze
5
5
  end
6
6
  end
data/lib/sys/proctable.rb CHANGED
@@ -5,8 +5,8 @@ case RbConfig::CONFIG['host_os']
5
5
  require_relative '../aix/sys/proctable'
6
6
  when /darwin/i
7
7
  require_relative '../darwin/sys/proctable'
8
- when /freebsd/i
9
- require_relative '../freebsd/sys/proctable'
8
+ when /freebsd|dragonfly/i
9
+ require_relative '../bsd/sys/proctable'
10
10
  when /linux/i
11
11
  require_relative '../linux/sys/proctable'
12
12
  when /sunos|solaris/i
data/lib/sys/top.rb CHANGED
@@ -20,13 +20,18 @@ module Sys
20
20
 
21
21
  aix = RbConfig::CONFIG['host_os'] =~ /aix/i
22
22
  darwin = RbConfig::CONFIG['host_os'] =~ /darwin/i
23
+ dragonfly = RbConfig::CONFIG['host_os'] =~ /dragonfly/i
23
24
 
24
25
  # Sort by pid on Windows and AIX by default
25
26
  if (File::ALT_SEPARATOR || aix || darwin) && field == 'pctcpu'
26
27
  field = 'pid'
27
28
  end
28
29
 
29
- Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
30
+ if dragonfly && field == 'pctcpu'
31
+ Sys::ProcTable.ps.sort_by{ |obj| obj.lwp.pctcpu }[0..num-1]
32
+ else
33
+ Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
34
+ end
30
35
  end
31
36
  end
32
37
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,9 @@ RSpec.configure do |config|
6
6
  config.filter_run_excluding(:aix) unless RbConfig::CONFIG['host_os'] =~ /aix/i
7
7
  config.filter_run_excluding(:darwin) unless RbConfig::CONFIG['host_os'] =~ /mac|darwin/i
8
8
  config.filter_run_excluding(:linux) unless RbConfig::CONFIG['host_os'] =~ /linux/i
9
+ config.filter_run_excluding(:bsd) unless RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/i
9
10
  config.filter_run_excluding(:freebsd) unless RbConfig::CONFIG['host_os'] =~ /freebsd/i
11
+ config.filter_run_excluding(:dragonfly) unless RbConfig::CONFIG['host_os'] =~ /dragonfly/i
10
12
  config.filter_run_excluding(:sunos) unless RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
11
13
  config.filter_run_excluding(:windows) unless Gem.win_platform?
12
14
  config.filter_run_excluding(:jruby) if RUBY_PLATFORM == 'java'
@@ -15,7 +15,7 @@ RSpec.describe 'common' do
15
15
 
16
16
  context 'constants' do
17
17
  it 'has a VERSION constant set to the expected value' do
18
- expect(Sys::ProcTable::VERSION).to eql('1.2.7')
18
+ expect(Sys::ProcTable::VERSION).to eql('1.3.0')
19
19
  expect(Sys::ProcTable::VERSION).to be_frozen
20
20
  end
21
21
 
@@ -1,13 +1,14 @@
1
1
  ################################################################
2
- # sys_proctable_freebsd_rspec.rb
2
+ # sys_proctable_bsd_rspec.rb
3
3
  #
4
- # Test suite for FreeBSD for the sys-proctable library.
5
- # You should run these tests via the 'rake spec' task.
4
+ # Specs for BSD related operating systems for the sys-proctable
5
+ # library. You should run these tests via the 'rake spec' task.
6
6
  ################################################################
7
7
  require 'spec_helper'
8
+ require 'mkmf-lite'
8
9
 
9
- RSpec.describe Sys::ProcTable, :freebsd do
10
- let(:fields){
10
+ RSpec.describe Sys::ProcTable, :bsd do
11
+ let(:fields_freebsd){
11
12
  %w[
12
13
  pid ppid pgid tpgid sid tsid jobc uid ruid rgid
13
14
  ngroups groups size rssize swrss tsize dsize ssize
@@ -19,12 +20,23 @@ RSpec.describe Sys::ProcTable, :freebsd do
19
20
  ]
20
21
  }
21
22
 
23
+ let(:fields_dragonfly){
24
+ %w[
25
+ paddr flags stat lock acflag traceflag fd siglist sigignore
26
+ sigcatch sigflag start comm uid ngroups groups ruid svuid
27
+ rgid svgid pid ppid pgid jobc sid login tdev tpgid tsid exitstat
28
+ nthreads nice swtime vm_map_size vm_rssize vm_swrss vm_tsize
29
+ vm_dsize vm_ssize vm_prssize jailid ru cru auxflags lwp ktaddr
30
+ ]
31
+ }
32
+
22
33
  context 'fields singleton method' do
23
34
  it 'responds to a fields method' do
24
35
  expect(described_class).to respond_to(:fields)
25
36
  end
26
37
 
27
38
  it 'returns the expected results for the fields method' do
39
+ fields = RbConfig::CONFIG['host_os'] =~ /freebsd/i ? fields_freebsd : fields_dragonfly
28
40
  expect(described_class.fields).to be_kind_of(Array)
29
41
  expect(described_class.fields).to eql(fields)
30
42
  end
@@ -64,47 +76,47 @@ RSpec.describe Sys::ProcTable, :freebsd do
64
76
  expect(process.comm).to be_kind_of(String)
65
77
  end
66
78
 
67
- it 'contains a state member and returns the expected value' do
79
+ it 'contains a state member and returns the expected value', :freebsd do
68
80
  expect(process).to respond_to(:state)
69
81
  expect(process.state).to be_kind_of(String)
70
82
  end
71
83
 
72
- it 'contains a pctcpu member and returns the expected value' do
84
+ it 'contains a pctcpu member and returns the expected value', :freebsd do
73
85
  expect(process).to respond_to(:pctcpu)
74
86
  expect(process.pctcpu).to be_kind_of(Float)
75
87
  end
76
88
 
77
- it 'contains a oncpu member and returns the expected value' do
89
+ it 'contains a oncpu member and returns the expected value', :freebsd do
78
90
  expect(process).to respond_to(:oncpu)
79
91
  expect(process.oncpu).to be_kind_of(Integer)
80
92
  end
81
93
 
82
- it 'contains a ttynum member and returns the expected value' do
94
+ it 'contains a ttynum member and returns the expected value', :freebsd do
83
95
  expect(process).to respond_to(:ttynum)
84
96
  expect(process.ttynum).to be_kind_of(Integer)
85
97
  end
86
98
 
87
- it 'contains a ttydev member and returns the expected value' do
99
+ it 'contains a ttydev member and returns the expected value', :freebsd do
88
100
  expect(process).to respond_to(:ttydev)
89
101
  expect(process.ttydev).to be_kind_of(String)
90
102
  end
91
103
 
92
- it 'contains a wmesg member and returns the expected value' do
104
+ it 'contains a wmesg member and returns the expected value', :freebsd do
93
105
  expect(process).to respond_to(:wmesg)
94
106
  expect(process.wmesg).to be_kind_of(String)
95
107
  end
96
108
 
97
- it 'contains a runtime member and returns the expected value' do
109
+ it 'contains a runtime member and returns the expected value', :freebsd do
98
110
  expect(process).to respond_to(:runtime)
99
111
  expect(process.runtime).to be_kind_of(Integer)
100
112
  end
101
113
 
102
- it 'contains a priority member and returns the expected value' do
114
+ it 'contains a priority member and returns the expected value', :freebsd do
103
115
  expect(process).to respond_to(:priority)
104
116
  expect(process.priority).to be_kind_of(Integer)
105
117
  end
106
118
 
107
- it 'contains a usrpri member and returns the expected value' do
119
+ it 'contains a usrpri member and returns the expected value', :freebsd do
108
120
  expect(process).to respond_to(:usrpri)
109
121
  expect(process.usrpri).to be_kind_of(Integer)
110
122
  end
@@ -124,85 +136,109 @@ RSpec.describe Sys::ProcTable, :freebsd do
124
136
  expect(process.start).to be_kind_of(Time)
125
137
  end
126
138
 
127
- it 'contains a maxrss member and returns the expected value' do
139
+ it 'contains a maxrss member and returns the expected value', :freebsd do
128
140
  expect(process).to respond_to(:maxrss)
129
141
  expect(process.maxrss).to be_kind_of(Integer)
130
142
  end
131
143
 
132
- it 'contains a ixrss member and returns the expected value' do
144
+ it 'contains a ixrss member and returns the expected value', :freebsd do
133
145
  expect(process).to respond_to(:ixrss)
134
146
  expect(process.ixrss).to be_kind_of(Integer)
135
147
  end
136
148
 
137
149
  # TODO: The value returned on PC BSD 10 does not appear to be valid. Investigate.
138
- it 'contains a idrss member and returns the expected value' do
150
+ it 'contains a idrss member and returns the expected value', :freebsd do
139
151
  expect(process).to respond_to(:idrss)
140
152
  expect(process.idrss).to be_kind_of(Numeric)
141
153
  end
142
154
 
143
- it 'contains a isrss member and returns the expected value' do
155
+ it 'contains a isrss member and returns the expected value', :freebsd do
144
156
  expect(process).to respond_to(:isrss)
145
157
  expect(process.isrss).to be_kind_of(Integer)
146
158
  end
147
159
 
148
- it 'contains a minflt member and returns the expected value' do
160
+ it 'contains a minflt member and returns the expected value', :freebsd do
149
161
  expect(process).to respond_to(:minflt)
150
162
  expect(process.minflt).to be_kind_of(Integer)
151
163
  end
152
164
 
153
- it 'contains a majflt member and returns the expected value' do
165
+ it 'contains a majflt member and returns the expected value', :freebsd do
154
166
  expect(process).to respond_to(:majflt)
155
167
  expect(process.majflt).to be_kind_of(Integer)
156
168
  end
157
169
 
158
- it 'contains a nswap member and returns the expected value' do
170
+ it 'contains a nswap member and returns the expected value', :freebsd do
159
171
  expect(process).to respond_to(:nswap)
160
172
  expect(process.nswap).to be_kind_of(Integer)
161
173
  end
162
174
 
163
- it 'contains a inblock member and returns the expected value' do
175
+ it 'contains a inblock member and returns the expected value', :freebsd do
164
176
  expect(process).to respond_to(:inblock)
165
177
  expect(process.inblock).to be_kind_of(Integer)
166
178
  end
167
179
 
168
- it 'contains a oublock member and returns the expected value' do
180
+ it 'contains a oublock member and returns the expected value', :freebsd do
169
181
  expect(process).to respond_to(:oublock)
170
182
  expect(process.oublock).to be_kind_of(Integer)
171
183
  end
172
184
 
173
- it 'contains a msgsnd member and returns the expected value' do
185
+ it 'contains a msgsnd member and returns the expected value', :freebsd do
174
186
  expect(process).to respond_to(:msgsnd)
175
187
  expect(process.msgsnd).to be_kind_of(Integer)
176
188
  end
177
189
 
178
- it 'contains a msgrcv member and returns the expected value' do
190
+ it 'contains a msgrcv member and returns the expected value', :freebsd do
179
191
  expect(process).to respond_to(:msgrcv)
180
192
  expect(process.msgrcv).to be_kind_of(Integer)
181
193
  end
182
194
 
183
- it 'contains a nsignals member and returns the expected value' do
195
+ it 'contains a nsignals member and returns the expected value', :freebsd do
184
196
  expect(process).to respond_to(:nsignals)
185
197
  expect(process.nsignals).to be_kind_of(Integer)
186
198
  end
187
199
 
188
- it 'contains a nvcsw member and returns the expected value' do
200
+ it 'contains a nvcsw member and returns the expected value', :freebsd do
189
201
  expect(process).to respond_to(:nvcsw)
190
202
  expect(process.nvcsw).to be_kind_of(Integer)
191
203
  end
192
204
 
193
- it 'contains a nivcsw member and returns the expected value' do
205
+ it 'contains a nivcsw member and returns the expected value', :freebsd do
194
206
  expect(process).to respond_to(:nivcsw)
195
207
  expect(process.nivcsw).to be_kind_of(Integer)
196
208
  end
197
209
 
198
- it 'contains a utime member and returns the expected value' do
210
+ it 'contains a utime member and returns the expected value', :freebsd do
199
211
  expect(process).to respond_to(:utime)
200
212
  expect(process.utime).to be_kind_of(Integer)
201
213
  end
202
214
 
203
- it 'contains a stime member and returns the expected value' do
215
+ it 'contains a stime member and returns the expected value', :freebsd do
204
216
  expect(process).to respond_to(:stime)
205
217
  expect(process.stime).to be_kind_of(Integer)
206
218
  end
207
219
  end
220
+
221
+ context 'C struct verification' do
222
+ let(:dummy){ Class.new{ extend Mkmf::Lite } }
223
+
224
+ it 'has a timeval struct of the expected size' do
225
+ expect(Sys::ProcTableStructs::Timeval.size).to eq(dummy.check_sizeof('struct timeval', 'sys/time.h'))
226
+ end
227
+
228
+ it 'has an rtprio struct of the expected size' do
229
+ expect(Sys::ProcTableStructs::RTPrio.size).to eq(dummy.check_sizeof('struct rtprio', 'sys/rtprio.h'))
230
+ end
231
+
232
+ it 'has an rusage struct of the expected size' do
233
+ expect(Sys::ProcTableStructs::Rusage.size).to eq(dummy.check_sizeof('struct rusage', 'sys/resource.h'))
234
+ end
235
+
236
+ it 'has an kinfo_lwp struct of the expected size' do
237
+ expect(Sys::ProcTableStructs::KInfoLWP.size).to eq(dummy.check_sizeof('struct kinfo_lwp', 'sys/kinfo.h'))
238
+ end
239
+
240
+ it 'has an kinfo_proc struct of the expected size' do
241
+ expect(Sys::ProcTableStructs::KInfoProc.size).to eq(dummy.check_sizeof('struct kinfo_proc', 'sys/kinfo.h'))
242
+ end
243
+ end
208
244
  end
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.add_development_dependency('rake')
19
19
  spec.add_development_dependency('rubocop')
20
20
  spec.add_development_dependency('rubocop-rspec')
21
+ spec.add_development_dependency('mkmf-lite')
21
22
 
22
23
  spec.metadata = {
23
24
  'homepage_uri' => 'https://github.com/djberg96/sys-proctable',
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-proctable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2022-10-28 00:00:00.000000000 Z
38
+ date: 2022-12-26 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
@@ -107,6 +107,20 @@ dependencies:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: mkmf-lite
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
110
124
  description: |2
111
125
  The sys-proctable library provides an interface for gathering information
112
126
  about processes on your system, i.e. the process table. Most major
@@ -129,8 +143,16 @@ files:
129
143
  - certs/djberg96_pub.pem
130
144
  - examples/example_ps.rb
131
145
  - lib/aix/sys/proctable.rb
146
+ - lib/bsd/sys/dragonfly/sys/proctable.rb
147
+ - lib/bsd/sys/dragonfly/sys/proctable/constants.rb
148
+ - lib/bsd/sys/dragonfly/sys/proctable/functions.rb
149
+ - lib/bsd/sys/dragonfly/sys/proctable/structs.rb
150
+ - lib/bsd/sys/freebsd/sys/proctable.rb
151
+ - lib/bsd/sys/freebsd/sys/proctable/constants.rb
152
+ - lib/bsd/sys/freebsd/sys/proctable/functions.rb
153
+ - lib/bsd/sys/freebsd/sys/proctable/structs.rb
154
+ - lib/bsd/sys/proctable.rb
132
155
  - lib/darwin/sys/proctable.rb
133
- - lib/freebsd/sys/proctable.rb
134
156
  - lib/linux/sys/proctable.rb
135
157
  - lib/linux/sys/proctable/cgroup_entry.rb
136
158
  - lib/linux/sys/proctable/smaps.rb
@@ -144,8 +166,8 @@ files:
144
166
  - spec/spec_helper.rb
145
167
  - spec/sys_proctable_aix_spec.rb
146
168
  - spec/sys_proctable_all_spec.rb
169
+ - spec/sys_proctable_bsd_spec.rb
147
170
  - spec/sys_proctable_darwin_spec.rb
148
- - spec/sys_proctable_freebsd_spec.rb
149
171
  - spec/sys_proctable_linux_spec.rb
150
172
  - spec/sys_proctable_sunos_spec.rb
151
173
  - spec/sys_proctable_windows_spec.rb
@@ -177,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
199
  - !ruby/object:Gem::Version
178
200
  version: '0'
179
201
  requirements: []
180
- rubygems_version: 3.3.7
202
+ rubygems_version: 3.3.26
181
203
  signing_key:
182
204
  specification_version: 4
183
205
  summary: An interface for providing process table information
@@ -185,8 +207,8 @@ test_files:
185
207
  - spec/spec_helper.rb
186
208
  - spec/sys_proctable_aix_spec.rb
187
209
  - spec/sys_proctable_all_spec.rb
210
+ - spec/sys_proctable_bsd_spec.rb
188
211
  - spec/sys_proctable_darwin_spec.rb
189
- - spec/sys_proctable_freebsd_spec.rb
190
212
  - spec/sys_proctable_linux_spec.rb
191
213
  - spec/sys_proctable_sunos_spec.rb
192
214
  - spec/sys_proctable_windows_spec.rb
metadata.gz.sig CHANGED
Binary file