[PATCH] qemusecuritytest: Call real virFileExists in mock

Michal Privoznik posted 1 patch 3 weeks, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/dd5d2f41e751192ff647482f4438c8949becf3ba.1712651360.git.mprivozn@redhat.com
tests/qemusecuritymock.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
[PATCH] qemusecuritytest: Call real virFileExists in mock
Posted by Michal Privoznik 3 weeks, 2 days ago
When I suggested to Jim to call real virFileExists() I forgot to
also suggest calling init_syms(). Without it, real_virFileExists
pointer might be left unset. And indeed, that's what we were
seeing on FreeBSD.

This effectively reverts commit 4b5cc57ed35dc24d11673dd3f04bfb8073c0340d.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

Green pipeline:

https://gitlab.com/MichalPrivoznik/libvirt/-/pipelines/1245457856

Okay, it doesn't test FreeBSD, but it tests x86_64-ubuntu-2204-clang
which was also experiencing the failure:

https://gitlab.com/libvirt/libvirt/-/jobs/6574951734

 tests/qemusecuritymock.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c
index dc8a893e9d..2dfd6c33a0 100644
--- a/tests/qemusecuritymock.c
+++ b/tests/qemusecuritymock.c
@@ -66,6 +66,7 @@ static int (*real_close)(int fd);
 static int (*real_setfilecon_raw)(const char *path, const char *context);
 static int (*real_getfilecon_raw)(const char *path, char **context);
 #endif
+static bool (*real_virFileExists)(const char *file);
 
 
 /* Global mutex to avoid races */
@@ -123,6 +124,7 @@ init_syms(void)
     VIR_MOCK_REAL_INIT(setfilecon_raw);
     VIR_MOCK_REAL_INIT(getfilecon_raw);
 #endif
+    VIR_MOCK_REAL_INIT(virFileExists);
 
     /* Intentionally not calling init_hash() here */
 }
@@ -386,8 +388,11 @@ bool virFileExists(const char *path)
 {
     VIR_LOCK_GUARD lock = virLockGuardLock(&m);
 
-    if (getenv(ENVVAR) == NULL)
-        return access(path, F_OK) == 0;
+    if (getenv(ENVVAR) == NULL) {
+        init_syms();
+
+        return real_virFileExists(path);
+    }
 
     init_hash();
     if (virHashHasEntry(chown_paths, path))
-- 
2.43.2
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [PATCH] qemusecuritytest: Call real virFileExists in mock
Posted by Jim Fehlig 3 weeks, 2 days ago
On 4/9/24 2:41 AM, Michal Privoznik wrote:
> When I suggested to Jim to call real virFileExists() I forgot to
> also suggest calling init_syms(). Without it, real_virFileExists
> pointer might be left unset. And indeed, that's what we were
> seeing on FreeBSD.
> 
> This effectively reverts commit 4b5cc57ed35dc24d11673dd3f04bfb8073c0340d. >
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

Thanks for fixing the mess from my small patch :-). I was deep in another task 
when I noticed the build failure, but that's a poor excuse for not properly 
investigating it and pushing a hurried fix.

Reviewed-by: Jim Fehlig <jfehlig@suse.com>

Regards,
Jim

> ---
> 
> Green pipeline:
> 
> https://gitlab.com/MichalPrivoznik/libvirt/-/pipelines/1245457856
> 
> Okay, it doesn't test FreeBSD, but it tests x86_64-ubuntu-2204-clang
> which was also experiencing the failure:
> 
> https://gitlab.com/libvirt/libvirt/-/jobs/6574951734
> 
>   tests/qemusecuritymock.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c
> index dc8a893e9d..2dfd6c33a0 100644
> --- a/tests/qemusecuritymock.c
> +++ b/tests/qemusecuritymock.c
> @@ -66,6 +66,7 @@ static int (*real_close)(int fd);
>   static int (*real_setfilecon_raw)(const char *path, const char *context);
>   static int (*real_getfilecon_raw)(const char *path, char **context);
>   #endif
> +static bool (*real_virFileExists)(const char *file);
>   
>   
>   /* Global mutex to avoid races */
> @@ -123,6 +124,7 @@ init_syms(void)
>       VIR_MOCK_REAL_INIT(setfilecon_raw);
>       VIR_MOCK_REAL_INIT(getfilecon_raw);
>   #endif
> +    VIR_MOCK_REAL_INIT(virFileExists);
>   
>       /* Intentionally not calling init_hash() here */
>   }
> @@ -386,8 +388,11 @@ bool virFileExists(const char *path)
>   {
>       VIR_LOCK_GUARD lock = virLockGuardLock(&m);
>   
> -    if (getenv(ENVVAR) == NULL)
> -        return access(path, F_OK) == 0;
> +    if (getenv(ENVVAR) == NULL) {
> +        init_syms();
> +
> +        return real_virFileExists(path);
> +    }
>   
>       init_hash();
>       if (virHashHasEntry(chown_paths, path))
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [PATCH] qemusecuritytest: Call real virFileExists in mock
Posted by Jiri Denemark 3 weeks, 2 days ago
On Tue, Apr 09, 2024 at 10:41:37 +0200, Michal Privoznik wrote:
> When I suggested to Jim to call real virFileExists() I forgot to
> also suggest calling init_syms(). Without it, real_virFileExists
> pointer might be left unset. And indeed, that's what we were
> seeing on FreeBSD.
> 
> This effectively reverts commit 4b5cc57ed35dc24d11673dd3f04bfb8073c0340d.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
> 
> Green pipeline:
> 
> https://gitlab.com/MichalPrivoznik/libvirt/-/pipelines/1245457856
> 
> Okay, it doesn't test FreeBSD, but it tests x86_64-ubuntu-2204-clang
> which was also experiencing the failure:
> 
> https://gitlab.com/libvirt/libvirt/-/jobs/6574951734
> 
>  tests/qemusecuritymock.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org