[libvirt] [PATCH 1/3] tests: Turn virFileWrapperAddPrefix to void

Michal Privoznik posted 3 patches 6 years, 11 months ago
[libvirt] [PATCH 1/3] tests: Turn virFileWrapperAddPrefix to void
Posted by Michal Privoznik 6 years, 11 months ago
In theory, it's nice to have virFileWrapperAddPrefix() return a
value that indicates if the function succeeded or not. But in
practice, nobody checks for that and in fact blindly believes
that the function succeeded. Therefore, make the function return
nothing and just abort() if it would fail.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tests/virfilewrapper.c | 13 +++++++------
 tests/virfilewrapper.h |  2 +-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c
index f7a7a931e1..497e91bd45 100644
--- a/tests/virfilewrapper.c
+++ b/tests/virfilewrapper.c
@@ -66,13 +66,15 @@ static void init_syms(void)
 }
 
 
-int
+void
 virFileWrapperAddPrefix(const char *prefix,
                         const char *override)
 {
     /* Both parameters are mandatory */
-    if (!prefix || !override)
-        return -1;
+    if (!prefix || !override) {
+        fprintf(stderr, "Attempt to add invalid path override\n");
+        abort();
+    }
 
     init_syms();
 
@@ -80,10 +82,9 @@ virFileWrapperAddPrefix(const char *prefix,
         VIR_APPEND_ELEMENT_QUIET(overrides, noverrides, override) < 0) {
         VIR_FREE(prefixes);
         VIR_FREE(overrides);
-        return -1;
+        fprintf(stderr, "Unable to add path override for '%s'\n", prefix);
+        abort();
     }
-
-    return 0;
 }
 
 
diff --git a/tests/virfilewrapper.h b/tests/virfilewrapper.h
index 044c532232..80fd6244ad 100644
--- a/tests/virfilewrapper.h
+++ b/tests/virfilewrapper.h
@@ -19,7 +19,7 @@
 #ifndef LIBVIRT_VIRFILEWRAPPER_H
 # define LIBVIRT_VIRFILEWRAPPER_H
 
-int
+void
 virFileWrapperAddPrefix(const char *prefix,
                         const char *override);
 
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] tests: Turn virFileWrapperAddPrefix to void
Posted by Martin Kletzander 6 years, 11 months ago
On Wed, Mar 13, 2019 at 11:13:07AM +0100, Michal Privoznik wrote:
>In theory, it's nice to have virFileWrapperAddPrefix() return a
>value that indicates if the function succeeded or not. But in
>practice, nobody checks for that and in fact blindly believes
>that the function succeeded. Therefore, make the function return
>nothing and just abort() if it would fail.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> tests/virfilewrapper.c | 13 +++++++------
> tests/virfilewrapper.h |  2 +-
> 2 files changed, 8 insertions(+), 7 deletions(-)
>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] tests: Turn virFileWrapperAddPrefix to void
Posted by Erik Skultety 6 years, 11 months ago
On Wed, Mar 13, 2019 at 11:13:07AM +0100, Michal Privoznik wrote:
> In theory, it's nice to have virFileWrapperAddPrefix() return a
> value that indicates if the function succeeded or not. But in
> practice, nobody checks for that and in fact blindly believes
> that the function succeeded. Therefore, make the function return
> nothing and just abort() if it would fail.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
Reviewed-by: Erik Skultety <eskultet@redhat.com>

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