Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FreeBSD to github workflow. #111

Merged
merged 8 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 17 additions & 25 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'jruby', 'truffleruby']
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', 'jruby', 'truffleruby']
platform: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- ruby-version: truffleruby
Expand All @@ -33,28 +33,20 @@ jobs:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
freebsd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test in FreeBSD
id: test
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: |
pkg install -y ruby devel/ruby-gems

# test_solaris:
# runs-on: macos-12
# name: A job to run test in Solaris
# steps:
# - uses: actions/checkout@v2
# - name: test Solaris
# id: test
# uses: vmactions/solaris-vm@v0
# with:
# usesh: true
# prepare: |
# # as far as i know latest possible version ist 2.6.x in Solaris 11.4
# pkgutil -y -i runtime/ruby-26
# ruby -v
# gem install bundler
# bundle install
# #
# # maybe use puppet to get new ruby (?)
# # so we would get ruby 2.7.6p219
# # curl -JLO 'https://pm.puppetlabs.com/puppet-agent/2021.7.1/7.20.0/repos/solaris/11/puppet7/puppet-agent@7.20.0,5.11-1.i386.p5p'
# # pkg install -g file://$(pwd)/puppet-agent\@7.20.0\,5.11-1.i386.p5p pkg:/puppet-agent

# run: |
# bundle exec rake
run: |
ruby -e 'puts RbConfig::CONFIG["host_os"]'
gem install bundler --no-document
bundle install --quiet
bundle exec rspec
172 changes: 8 additions & 164 deletions lib/bsd/sys/freebsd/sys/proctable.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
require 'ffi'
require_relative 'proctable/constants'
require_relative 'proctable/structs'
require_relative 'proctable/functions'
require 'sys/proctable/version'

module Sys
class ProcTable
extend FFI::Library
include Sys::ProcTableConstants
include Sys::ProcTableStructs
extend Sys::ProcTableFunctions

# Error typically raised if the ProcTable.ps method fails.
class Error < StandardError; end
Expand All @@ -13,158 +17,6 @@ class Error < StandardError; end

private

ffi_lib :kvm

attach_function :devname, [:dev_t, :mode_t], :string
attach_function :kvm_open, [:string, :string, :string, :int, :string], :pointer
attach_function :kvm_close, [:pointer], :int
attach_function :kvm_getprocs, [:pointer, :int, :int, :pointer], :pointer
attach_function :kvm_getargv, [:pointer, :pointer, :int], :pointer

POSIX_ARG_MAX = 4096

KERN_PROC_PID = 1
KERN_PROC_PROC = 8

S_IFCHR = 0020000

WMESGLEN = 8
LOCKNAMELEN = 8
OCOMMLEN = 16
COMMLEN = 19
KI_EMULNAMELEN = 16
KI_NGROUPS = 16
LOGNAMELEN = 17
KI_NSPARE_INT = 9
KI_NSPARE_LONG = 12
KI_NSPARE_PTR = 6

class Timeval < FFI::Struct
layout(:tv_sec, :time_t, :tv_usec, :suseconds_t)
end

class Priority < FFI::Struct
layout(
:pri_class, :uchar,
:pri_level, :uchar,
:pri_native, :uchar,
:pri_user, :uchar
)
end

class Rusage < FFI::Struct
layout(
:ru_utime, Timeval,
:ru_stime, Timeval,
:ru_maxrss, :long,
:ru_ixrss, :long,
:ru_idrss, :long,
:ru_isrss, :long,
:ru_minflt, :long,
:ru_majflt, :long,
:ru_nswap, :long,
:ru_inblock, :long,
:ru_oublock, :long,
:ru_msgsnd, :long,
:ru_msgrcv, :long,
:ru_nsignals, :long,
:ru_nvcsw, :long,
:ru_nivcsw, :long
)
end

class Pargs < FFI::Struct
layout(
:ar_ref, :uint,
:ar_length, :uint,
:ar_args, [:uchar, 1]
)
end

class KInfoProc < FFI::Struct
layout(
:ki_structsize, :int,
:ki_layout, :int,
:ki_args, :pointer,
:ki_paddr, :pointer,
:ki_addr, :pointer,
:ki_tracep, :pointer,
:ki_textvp, :pointer,
:ki_fd, :pointer,
:ki_vmspace, :pointer,
:ki_wchan, :pointer,
:ki_pid, :pid_t,
:ki_ppid, :pid_t,
:ki_pgid, :pid_t,
:ki_tpgid, :pid_t,
:ki_sid, :pid_t,
:ki_tsid, :pid_t,
:ki_jobc, :short,
:ki_spare_short1, :short,
:ki_tdev, :dev_t,
:ki_siglist, [:uint32_t, 4],
:ki_sigmask, [:uint32_t, 4],
:ki_sigignore, [:uint32_t, 4],
:ki_sigcatch, [:uint32_t, 4],
:ki_uid, :uid_t,
:ki_ruid, :uid_t,
:ki_svuid, :uid_t,
:ki_rgid, :gid_t,
:ki_svgid, :gid_t,
:ki_ngroups, :short,
:ki_spare_short2, :short,
:ki_groups, [:gid_t, KI_NGROUPS],
:ki_size, :uint32_t,
:ki_rssize, :segsz_t,
:ki_swrss, :segsz_t,
:ki_tsize, :segsz_t,
:ki_dsize, :segsz_t,
:ki_ssize, :segsz_t,
:ki_xstat, :u_short,
:ki_acflag, :u_short,
:ki_pctcpu, :fixpt_t,
:ki_estcpu, :uint,
:ki_slptime, :uint,
:ki_swtime, :uint,
:ki_swtime, :int,
:ki_runtime, :uint64_t,
:ki_start, Timeval,
:ki_childtime, Timeval,
:ki_flag, :long,
:ki_kiflag, :long,
:ki_traceflag, :int,
:ki_stat, :char,
:ki_nice, :char,
:ki_lock, :char,
:ki_rqindex, :char,
:ki_oncpu, :uchar,
:ki_lastcpu, :uchar,
:ki_ocomm, [:char, OCOMMLEN+1],
:ki_wmesg, [:char, WMESGLEN+1],
:ki_login, [:char, LOGNAMELEN+1],
:ki_lockname, [:char, LOCKNAMELEN+1],
:ki_comm, [:char, COMMLEN+1],
:ki_emul, [:char, KI_EMULNAMELEN+1],
:ki_sparestrings, [:char, 68],
:ki_spareints, [:int, KI_NSPARE_INT],
:ki_cr_flags, :uint,
:ki_jid, :int,
:ki_numthreads, :int,
:ki_tid, :pid_t,
:ki_pri, Priority,
:ki_rusage, Rusage,
:ki_rusage_ch, Rusage,
:ki_pcb, :pointer,
:ki_kstack, :pointer,
:ki_udata, :pointer,
:ki_tdaddr, :pointer,
:ki_spareptrs, [:pointer, KI_NSPARE_PTR],
:ki_sparelongs, [:long, KI_NSPARE_LONG],
:ki_sflags, :long,
:ki_tdflags, :long
)
end

@fields = %w[
pid ppid pgid tpgid sid tsid jobc uid ruid rgid
ngroups groups size rssize swrss tsize dsize ssize
Expand Down Expand Up @@ -337,16 +189,6 @@ def self.fields
@fields
end

private

SIDL = 1
SRUN = 2
SSLEEP = 3
SSTOP = 4
SZOMB = 5
SWAIT = 6
SLOCK = 7

def self.get_state(int)
case int
when SIDL; "idle"
Expand All @@ -359,5 +201,7 @@ def self.get_state(int)
else; "unknown"
end
end

private_class_method :get_state
end
end
29 changes: 29 additions & 0 deletions lib/bsd/sys/freebsd/sys/proctable/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Sys
module ProcTableConstants
POSIX_ARG_MAX = 4096

KERN_PROC_PID = 1
KERN_PROC_PROC = 8

S_IFCHR = 0020000

WMESGLEN = 8
LOCKNAMELEN = 8
OCOMMLEN = 16
COMMLEN = 19
KI_EMULNAMELEN = 16
KI_NGROUPS = 16
LOGNAMELEN = 17
KI_NSPARE_INT = 9
KI_NSPARE_LONG = 12
KI_NSPARE_PTR = 6

SIDL = 1
SRUN = 2
SSLEEP = 3
SSTOP = 4
SZOMB = 5
SWAIT = 6
SLOCK = 7
end
end
14 changes: 14 additions & 0 deletions lib/bsd/sys/freebsd/sys/proctable/functions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'ffi'

module Sys
module ProcTableFunctions
extend FFI::Library
ffi_lib :kvm

attach_function :devname, [:dev_t, :mode_t], :string
attach_function :kvm_open, [:string, :string, :string, :int, :string], :pointer
attach_function :kvm_close, [:pointer], :int
attach_function :kvm_getprocs, [:pointer, :int, :int, :pointer], :pointer
attach_function :kvm_getargv, [:pointer, :pointer, :int], :pointer
end
end
Loading
Loading