From 9b40810e775b493bb4b0c48139e427b83c7ed8c6 Mon Sep 17 00:00:00 2001 From: Kenneth Chan Date: Tue, 18 Dec 2018 14:24:58 -0800 Subject: [PATCH 1/2] Add execution timeout --- lib/rghost/gs_alone.rb | 2 +- lib/rghost/ruby_ghost_config.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rghost/gs_alone.rb b/lib/rghost/gs_alone.rb index e51c35f..7a23e09 100755 --- a/lib/rghost/gs_alone.rb +++ b/lib/rghost/gs_alone.rb @@ -12,7 +12,7 @@ def run unless File.exists?(RGhost::Config::GS[:path].to_s) RGhost::Config.config_platform end - r=system(RGhost::Config::GS[:path]+cmd) + r=system("timeout #{RGhost::Config::GS[:timeout].to_i}s #{RGhost::Config::GS[:path]}#{cmd}") puts RGhost::Config::GS[:path]+cmd if @debug #puts r diff --git a/lib/rghost/ruby_ghost_config.rb b/lib/rghost/ruby_ghost_config.rb index b83ff67..8f1add7 100755 --- a/lib/rghost/ruby_ghost_config.rb +++ b/lib/rghost/ruby_ghost_config.rb @@ -64,6 +64,7 @@ module RGhost::Config :plugin => nil, :path => nil, :tmpdir => ENV["TMP"] || ENV["TMPDIR"] || ENV["TEMPDIR"] || ENV["TEMP"] || "/tmp", + :timeout => ENV['GS_TIMEOUT'] || 3000, :pslibdir => File.join( File.dirname(__FILE__),"ps"), :extensions => [], :preload => [], From 5eb09f3b945b6e2e07c07586ef6e2cd36c5aa12a Mon Sep 17 00:00:00 2001 From: Kenneth Chan Date: Tue, 18 Dec 2018 15:04:33 -0800 Subject: [PATCH 2/2] Add option to disable timeout --- lib/rghost/gs_alone.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/rghost/gs_alone.rb b/lib/rghost/gs_alone.rb index 7a23e09..2ba1310 100755 --- a/lib/rghost/gs_alone.rb +++ b/lib/rghost/gs_alone.rb @@ -12,9 +12,15 @@ def run unless File.exists?(RGhost::Config::GS[:path].to_s) RGhost::Config.config_platform end - r=system("timeout #{RGhost::Config::GS[:timeout].to_i}s #{RGhost::Config::GS[:path]}#{cmd}") + + full_command = "#{RGhost::Config::GS[:path]}#{cmd}" + timeout = RGhost::Config::GS[:timeout].to_i + if timeout > 0 + full_command = "timeout #{timeout}s #{full_command}" + end + r=system(full_command) - puts RGhost::Config::GS[:path]+cmd if @debug + puts full_command if @debug #puts r r end