examples/jexec.rb
author Michael Granger <ged@FaerieMUD.org>
Thu, 20 Nov 2008 17:12:39 +0000
changeset 5 41a1542b3b10
parent 0 92d00ff32c56
child 7 4460fc10c6a3
permissions -rw-r--r--
Cleaned up bsdjail extension code a bit more and made the extconf check for the actual headers being included.

#!/usr/bin/ruby

BEGIN {
	require 'pathname'
	basedir = Pathname.new( __FILE__ ).dirname.parent
	
	$LOAD_PATH.unshift basedir + "ext" unless 
		$LOAD_PATH.include? basedir + "ext"
}


require 'bsdjail'

jid = Integer( ARGV.shift )
args = ARGV

$deferr.puts "In process #{Process.pid}, about to jail_attach() with a block"

childpid = BSD::Jail.attach( jid ) do
	Dir.chdir( "/" )
	$deferr.puts "Child #{Process.pid} exec()ing:", "  " + args.join(" ")
	exec( *args )
end

$deferr.puts "Parent: waiting on imprisoned child #{childpid}"
Process.waitpid( childpid )

$deferr.puts "Child exited with exit code: %d" % [ $?.exitstatus ]