From 5fc904b099a7a65591465ee815d27c24cb1b0b52 Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Tue, 6 Dec 2011 13:28:54 -0800 Subject: [PATCH] Use FFI on JRuby to perform fast restart --- lib/puma/cli.rb | 9 +++++++-- lib/puma/jruby_restart.rb | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 lib/puma/jruby_restart.rb diff --git a/lib/puma/cli.rb b/lib/puma/cli.rb index ded837e5..20279c5e 100644 --- a/lib/puma/cli.rb +++ b/lib/puma/cli.rb @@ -81,8 +81,13 @@ module Puma end def restart! - Dir.chdir @restart_dir - Kernel.exec(*@restart_argv) + if IS_JRUBY + require 'puma/jruby_restart' + JRubyRestart.chdir_exec(@restart_dir, Gem.ruby, *@restart_argv) + else + Dir.chdir @restart_dir + Kernel.exec(*@restart_argv) + end end # Write +str+ to +@stdout+ diff --git a/lib/puma/jruby_restart.rb b/lib/puma/jruby_restart.rb new file mode 100644 index 00000000..ddadc82c --- /dev/null +++ b/lib/puma/jruby_restart.rb @@ -0,0 +1,22 @@ +require 'ffi' + +module Puma + module JRubyRestart + extend FFI::Library + ffi_lib 'c' + + attach_function :execlp, [:string, :varargs], :int + attach_function :chdir, [:string], :int + + def self.chdir_exec(dir, cmd, *argv) + chdir(dir) + argv.unshift(cmd) + argv = ([:string] * argv.size).zip(argv).flatten + argv <<:int + argv << 0 + execlp(cmd, *argv) + raise SystemCallError.new(FFI.errno) + end + end +end +