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

.execv(path, *args) ⇒ Object

int execv(const char *path, char *const argv[]);



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ragweed/wraptux/wraptux.rb', line 74

def execv(path, *args)
  FFI.errno = 0
  args.flatten!
  argv = FFI::MemoryPointer.new(:pointer, args.size + 2)
  argv[0].put_pointer(0, FFI::MemoryPointer.from_string(path.to_s))
  args.each_with_index do |arg, i|
    argv[i + 1].put_pointer(0, FFI::MemoryPointer.from_string(arg.to_s))
  end
  argv[args.size + 1].put_pointer(0, nil)

  Libc.execv(path, argv)
  # if this returns, an error has occured
  raise SystemCallError :execv, FFI.errno
end

.kill(pid, sig) ⇒ Object

int kill(pid_t pid, int sig);



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

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);



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

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);



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

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);



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

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