Skip to content

Commit

Permalink
Use kvm_openfiles instead of kvm_open.
Browse files Browse the repository at this point in the history
  • Loading branch information
djberg96 committed Feb 16, 2025
1 parent b1854ae commit 0d386fa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/bsd/sys/freebsd/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ class Error < StandardError; end
#
def self.ps(**kwargs)
pid = kwargs[:pid]
errbuf = 0.chr * POSIX2_LINE_MAX

begin
kd = kvm_open(nil, nil, nil, 0, nil)
kd = kvm_openfiles(nil, nil, nil, 0, errbuf)

if kd.null?
raise SystemCallError.new('kvm_open', FFI.errno)
error = errbuf.split(0.chr).first
raise SystemCallError.new("kvm_openfiles - #{error}", FFI.errno)
end

ptr = FFI::MemoryPointer.new(:int) # count
Expand Down
1 change: 1 addition & 0 deletions lib/bsd/sys/freebsd/sys/proctable/constants.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Sys
module ProcTableConstants
POSIX_ARG_MAX = 4096
POSIX2_LINE_MAX = 2048

KERN_PROC_PID = 1
KERN_PROC_PROC = 8
Expand Down
2 changes: 1 addition & 1 deletion lib/bsd/sys/freebsd/sys/proctable/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ProcTableFunctions
ffi_lib :kvm

attach_function :devname, [:dev_t, :mode_t], :string
attach_function :kvm_open, [:string, :string, :string, :int, :string], :pointer
attach_function :kvm_openfiles, [:string, :string, :string, :int, :buffer_out], :pointer
attach_function :kvm_close, [:pointer], :int
attach_function :kvm_getprocs, [:pointer, :int, :int, :pointer], :pointer
attach_function :kvm_getargv, [:pointer, :pointer, :int], :pointer
Expand Down

0 comments on commit 0d386fa

Please sign in to comment.