-
-
Save mattyoho/583108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment