From bc37f1aadc2c244c9ae31575b5051056475b95a4 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 22 Apr 2020 20:45:12 +0200 Subject: [PATCH] M #-: Kill drivers after grace period --- src/mad/Mad.cc | 23 ++++++++++++++++------- src/mad/ruby/OpenNebulaDriver.rb | 5 ++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/mad/Mad.cc b/src/mad/Mad.cc index 5761e379b1..d244400530 100644 --- a/src/mad/Mad.cc +++ b/src/mad/Mad.cc @@ -34,9 +34,8 @@ Mad::~Mad() { - char buf[]="FINALIZE\n"; - int status; - pid_t rp; + char buf[] = "FINALIZE\n"; + bool success = false; if ( pid==-1) { @@ -49,13 +48,23 @@ Mad::~Mad() close(mad_nebula_pipe); close(nebula_mad_pipe); - rp = waitpid(pid, &status, WNOHANG); - - if ( rp == 0 ) + for (int i=0; i < 2; ++i) { + int status; + + if ( waitpid(pid, &status, WNOHANG) != 0 ) + { + success = true; + break; + } + sleep(1); - waitpid(pid, &status, WNOHANG); } + + if (!success) + { + kill(pid, SIGKILL); + }; } /* -------------------------------------------------------------------------- */ diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 9a860f6614..982b96619a 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -140,9 +140,8 @@ class OpenNebulaDriver < ActionManager # Start the driver. Reads from STDIN and executes methods associated with # the messages def start_driver - loop_thread = Thread.new { loop } + Thread.new { loop } start_listener - loop_thread.kill end # This function parses a string with this form: @@ -187,7 +186,7 @@ class OpenNebulaDriver < ActionManager def loop Kernel.loop do - exit(-1) if STDIN.eof? + exit!(-1) if STDIN.eof? str = STDIN.gets next unless str