When running as a session (non-root) daemon, system hook directories (/etc/libvirt/hooks/<driver>.d/) may not be readable by the user, causing EACCES errors that abort hook execution.
Switch from virDirOpenIfExists() to virDirOpenQuiet() in virHookCheckDir() and handle both ENOENT and EACCES gracefully by skipping inaccessible directories instead of failing. Signed-off-by: Marc-André Lureau <[email protected]> --- src/util/virhook.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index 9cbe55faa03e..bd206f8cf1c2 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -165,12 +165,15 @@ virHookCheckDir(const char *hook_dir, const char *driver) return 0; } - if ((ret = virDirOpenIfExists(&dir, dir_path)) < 0) + if ((ret = virDirOpenQuiet(&dir, dir_path)) < 0) { + if (errno == ENOENT || errno == EACCES) { + VIR_DEBUG("Hook dir %s is not accessible: %s", + dir_path, g_strerror(errno)); + return 0; + } + virReportSystemError(errno, + _("cannot open directory '%1$s'"), dir_path); return -1; - - if (!ret) { - VIR_DEBUG("No hook script dir %s", dir_path); - return 0; } while ((ret = virDirRead(dir, &entry, dir_path)) > 0) { -- 2.56.0.rc0.29.g47ce80527c56
