This commit introduces the virHookCheck() before running the command (hook).
The virHookCheck() before virCommandRun() will avoid errors with changes
(removal and other permissions changes) in the hook file, while the libvirt
daemon is running.

Now, when you remove the hook file while libvirtd is running you get the
following error:

virsh # start WINDOWS_7
error: Failed to start domain WINDOWS_7
error: Hook script execution failed: internal error: Child process (LC_ALL=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/home/julio USER=root LOGNAME=root /etc/libvirt/hooks/qemu WINDOWS_7
prepare begin -) unexpected exit status 127: libvirt:  error : cannot execute
binary /etc/libvirt/hooks/qemu: No such file or directory

Cc: Carlos Castilho <cc...@br.ibm.com>
Signed-off-by: Julio Faracco <jcfara...@gmail.com>
---
 src/util/virhook.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/util/virhook.c b/src/util/virhook.c
index d37d6da..f741b30 100644
--- a/src/util/virhook.c
+++ b/src/util/virhook.c
@@ -294,7 +294,12 @@ virHookCall(int driver,
     if (output)
         virCommandSetOutputBuffer(cmd, output);
 
-    ret = virCommandRun(cmd, NULL);
+    ret = virHookCheck(driver, virHookDriverTypeToString(driver));
+
+    if (ret > 0) {
+        ret = virCommandRun(cmd, NULL);
+    }
+
     if (ret < 0) {
         /* Convert INTERNAL_ERROR into known error.  */
         virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s",
-- 
1.9.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to