From 374b9f684588e681fc40cfc2907cbb77bdb9e9d6 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Thu, 26 Mar 2020 19:20:46 +0100 Subject: [PATCH] B #4392: Detect VNC proxy under Apache Passenger (#4432) --- src/sunstone/OpenNebulaVNC.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/sunstone/OpenNebulaVNC.rb b/src/sunstone/OpenNebulaVNC.rb index 120f2a1745..66456634fa 100644 --- a/src/sunstone/OpenNebulaVNC.rb +++ b/src/sunstone/OpenNebulaVNC.rb @@ -190,6 +190,10 @@ class OpenNebulaVNC def proxy(vm_resource) # Check configurations and VM attributes + unless is_lockfile? + return error(400, "VNC Proxy is not running") + end + if !is_running? return error(400, "VNC Proxy is not running") end @@ -344,6 +348,20 @@ class OpenNebulaVNC end alias_method :get_pid, :is_running? + def is_lockfile? + dn = File.dirname(@lock_file) + bn = File.basename(@lock_file) + + # Due to restrictions which doesn't allow to stat the lock file + # when Sunstone is running under Apache with SELinux enabled, + # as a workaround we read content of the whole lock directory. + begin + Dir.entries(dn).include?(bn) + rescue StandardError + false + end + end + if RUBY_VERSION<'1.9' def spawn(*args) fork {