Module: Ragweed::Wraptux

Defined in:
lib/ragweed/wraptux.rb,
lib/ragweed/wraptux/threads.rb,
lib/ragweed/wraptux/wraptux.rb,
lib/ragweed/wraptux/constants.rb

Defined Under Namespace

Modules: Libc, PagePermissions, Ptrace, Signal, ThreadInfo, Wait Classes: PTRegs

Constant Summary collapse

VERSION =

:stopdoc:

File.read(File.join(File.dirname(__FILE__),"..","..","VERSION")).strip
LIBPATH =
::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR

Class Method Summary collapse

Class Method Details

.kill(pid, sig) ⇒ Object

int kill(pid_t pid, int sig);



57
58
59
60
61
62
# File 'lib/ragweed/wraptux/wraptux.rb', line 57

def kill pid, sig
  FFI.errno = 0
  r = Libc.kill pid, sig
  raise SystemCallError.new "waitpid", FFI.errno if r == -1
  r
end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



19
20
21
# File 'lib/ragweed/wraptux.rb', line 19

def self.libpath( *args )
  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



27
28
29
# File 'lib/ragweed/wraptux.rb', line 27

def self.path( *args )
  args.empty? ? PATH : ::File.join(PATH, args.flatten)
end

.ptrace(req, pid, addr, data) ⇒ Object

long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);



65
66
67
68
69
70
# File 'lib/ragweed/wraptux/wraptux.rb', line 65

def ptrace req, pid, addr, data
  FFI.errno = 0
  r = Libc.ptrace req, pid, addr, data
  #raise SystemCallError.new "ptrace", FFI.errno if r == -1 and !FFI.errno.zero?
  r
end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



41
42
43
44
45
46
47
48
# File 'lib/ragweed/wraptux.rb', line 41

def self.require_all_libs_relative_to( fname, dir = nil )
  self.require_utils
  dir ||= ::File.basename(fname, '.*')
  search_me = ::File.expand_path(
      ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
  Dir.glob(search_me).sort.each {|rb| require rb }
  # require File.dirname(File.basename(__FILE__)) + "/#{x}"
end

.require_utilsObject

Utility function to load utility classes and extensions



32
33
34
# File 'lib/ragweed/wraptux.rb', line 32

def self.require_utils
  %w{utils}.each{|r| require self.libpath(r)+'.rb'}
end

.versionObject

Returns the version string for the library.



11
12
13
# File 'lib/ragweed/wraptux.rb', line 11

def self.version
  VERSION
end

.waitObject

pid_t wait(int *status);



38
39
40
41
42
43
44
# File 'lib/ragweed/wraptux/wraptux.rb', line 38

def wait
  stat = FFI::MemoryPointer.new(:int, 1)
  FFI.errno = 0
  pid = Libc.wait stat
  raise SystemCallError.new "wait", FFI.errno if pid == -1
  [pid, stat.read_pointer.get_int32]
end

.waitpid(pid, opts = 0) ⇒ Object

pid_t waitpid(pid_t pid, int *status, int options);



47
48
49
50
51
52
53
54
# File 'lib/ragweed/wraptux/wraptux.rb', line 47

def waitpid pid, opts = 0
  p = FFI::MemoryPointer.new(:int, 1)
  FFI.errno = 0
  r = Libc.waitpid(pid,p,opts)
  raise SystemCallError.new "waitpid", FFI.errno if r == -1
  status = p.get_int32(0)
  [r, status]
end