public
Last active

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
~/projects/jruby ➔ jruby -rreal_unix -e 'trap("INT") { puts :there; exit }; puts :here; select(nil, nil, nil, nil)'
here
^Cthere
 
~/projects/jruby ➔ jruby -rreal_unix -e 'puts $$; exec "echo $$"'
461
461
 
~/projects/jruby ➔ cat real_unix.rb
require 'ffi'
 
module RealUnix
extend FFI::Library
 
ffi_lib 'c'
 
attach_function :execv, [ :string, :buffer_in ], :int
attach_function :exit, [ :int ], :void
def self.exec(*args)
args.unshift "/bin/sh", "-c"
cmd = args[0]
exec_args = FFI::MemoryPointer.new(:pointer, args.length + 1)
args.each_with_index do |arg, i|
exec_args[i].put_pointer(0, FFI::MemoryPointer.from_string(arg))
end
execv(cmd, exec_args)
end
end
 
module Kernel
alias :old_exec :exec
alias :old_exit :exit
def exec(*args); RealUnix.exec(*args); end
def exit(code = 0); RealUnix.exit(code); end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.