mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0127-environment-Use-guestfs___is_true-when-parsing-vario.patch

ffd6ed
From 05105da1347d3d7e9fbc41e0a14b8cd18905b60b Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Wed, 17 Dec 2014 12:52:46 +0000
ffd6ed
Subject: [PATCH] environment: Use guestfs___is_true when parsing various
ffd6ed
 boolean environment variables (RHBZ#1175196).
ffd6ed
ffd6ed
You can now use LIBGUESTFS_DEBUG=true (etc.)
ffd6ed
ffd6ed
You can disable debugging/tracing by setting LIBGUESTFS_DEBUG=0 (etc.)
ffd6ed
ffd6ed
(cherry picked from commit 5f6677ebd0fd6f6712de808ca27eab4468f966bc)
ffd6ed
---
ffd6ed
 fuse/test-guestmount-fd.c                     |  2 +-
ffd6ed
 src/handle.c                                  | 30 ++++++++++++++++++++-------
ffd6ed
 tests/charsets/test-charset-fidelity.c        |  4 ++--
ffd6ed
 tests/mount-local/test-parallel-mount-local.c |  2 +-
ffd6ed
 tests/parallel/Makefile.am                    |  1 +
ffd6ed
 tests/parallel/test-parallel.c                |  2 +-
ffd6ed
 tests/regressions/Makefile.am                 |  1 +
ffd6ed
 tests/regressions/rhbz914931.c                |  2 +-
ffd6ed
 8 files changed, 30 insertions(+), 14 deletions(-)
ffd6ed
ffd6ed
diff --git a/fuse/test-guestmount-fd.c b/fuse/test-guestmount-fd.c
ffd6ed
index 00eab0c..2b3ce5b 100644
ffd6ed
--- a/fuse/test-guestmount-fd.c
ffd6ed
+++ b/fuse/test-guestmount-fd.c
ffd6ed
@@ -50,7 +50,7 @@ main (int argc, char *argv[])
ffd6ed
 
ffd6ed
   /* Allow the test to be skipped. */
ffd6ed
   skip = getenv ("SKIP_TEST_GUESTMOUNT_FD");
ffd6ed
-  if (skip && STREQ (skip, "1")) {
ffd6ed
+  if (skip && guestfs___is_true (skip) > 0) {
ffd6ed
     fprintf (stderr, "%s: test skipped because environment variable set.\n",
ffd6ed
              program_name);
ffd6ed
     exit (77);
ffd6ed
diff --git a/src/handle.c b/src/handle.c
ffd6ed
index 141ba7d..0990082 100644
ffd6ed
--- a/src/handle.c
ffd6ed
+++ b/src/handle.c
ffd6ed
@@ -176,7 +176,7 @@ parse_environment (guestfs_h *g,
ffd6ed
                    char *(*do_getenv) (const void *data, const char *),
ffd6ed
                    const void *data)
ffd6ed
 {
ffd6ed
-  int memsize;
ffd6ed
+  int memsize, b;
ffd6ed
   char *str;
ffd6ed
 
ffd6ed
   /* Don't bother checking the return values of functions
ffd6ed
@@ -184,12 +184,24 @@ parse_environment (guestfs_h *g,
ffd6ed
    */
ffd6ed
 
ffd6ed
   str = do_getenv (data, "LIBGUESTFS_TRACE");
ffd6ed
-  if (str != NULL && STREQ (str, "1"))
ffd6ed
-    guestfs_set_trace (g, 1);
ffd6ed
+  if (str) {
ffd6ed
+    b = guestfs___is_true (str);
ffd6ed
+    if (b == -1) {
ffd6ed
+      error (g, _("%s=%s: non-boolean value"), "LIBGUESTFS_TRACE", str);
ffd6ed
+      return -1;
ffd6ed
+    }
ffd6ed
+    guestfs_set_trace (g, b);
ffd6ed
+  }
ffd6ed
 
ffd6ed
   str = do_getenv (data, "LIBGUESTFS_DEBUG");
ffd6ed
-  if (str != NULL && STREQ (str, "1"))
ffd6ed
-    guestfs_set_verbose (g, 1);
ffd6ed
+  if (str) {
ffd6ed
+    b = guestfs___is_true (str);
ffd6ed
+    if (b == -1) {
ffd6ed
+      error (g, _("%s=%s: non-boolean value"), "LIBGUESTFS_TRACE", str);
ffd6ed
+      return -1;
ffd6ed
+    }
ffd6ed
+    guestfs_set_verbose (g, b);
ffd6ed
+  }
ffd6ed
 
ffd6ed
   str = do_getenv (data, "LIBGUESTFS_TMPDIR");
ffd6ed
   if (str && STRNEQ (str, "")) {
ffd6ed
@@ -816,6 +828,7 @@ int
ffd6ed
 guestfs___get_backend_setting_bool (guestfs_h *g, const char *name)
ffd6ed
 {
ffd6ed
   CLEANUP_FREE char *value = NULL;
ffd6ed
+  int b;
ffd6ed
 
ffd6ed
   guestfs_push_error_handler (g, NULL, NULL);
ffd6ed
   value = guestfs_get_backend_setting (g, name);
ffd6ed
@@ -827,10 +840,11 @@ guestfs___get_backend_setting_bool (guestfs_h *g, const char *name)
ffd6ed
   if (value == NULL)
ffd6ed
     return -1;
ffd6ed
 
ffd6ed
-  if (STREQ (value, "1"))
ffd6ed
-    return 1;
ffd6ed
+  b = guestfs___is_true (value);
ffd6ed
+  if (b == -1)
ffd6ed
+    return -1;
ffd6ed
 
ffd6ed
-  return 0;
ffd6ed
+  return b;
ffd6ed
 }
ffd6ed
 
ffd6ed
 int
ffd6ed
diff --git a/tests/charsets/test-charset-fidelity.c b/tests/charsets/test-charset-fidelity.c
ffd6ed
index 4b34b0e..7ce7d94 100644
ffd6ed
--- a/tests/charsets/test-charset-fidelity.c
ffd6ed
+++ b/tests/charsets/test-charset-fidelity.c
ffd6ed
@@ -81,7 +81,7 @@ main (int argc, char *argv[])
ffd6ed
 
ffd6ed
   /* Allow this test to be skipped. */
ffd6ed
   str = getenv (ourenvvar);
ffd6ed
-  if (str && STREQ (str, "1")) {
ffd6ed
+  if (str && guestfs___is_true (str) > 0) {
ffd6ed
     printf ("%s: test skipped because environment variable is set.\n",
ffd6ed
             program_name);
ffd6ed
     exit (77);
ffd6ed
@@ -126,7 +126,7 @@ test_filesystem (guestfs_h *g, const struct filesystem *fs)
ffd6ed
 
ffd6ed
   snprintf (envvar, sizeof envvar, "%s_%s", ourenvvar, fs->fs_name);
ffd6ed
   str = getenv (envvar);
ffd6ed
-  if (str && STREQ (str, "1")) {
ffd6ed
+  if (str && guestfs___is_true (str) > 0) {
ffd6ed
     printf ("skipped test of %s because environment variable is set\n",
ffd6ed
             fs->fs_name);
ffd6ed
     return;
ffd6ed
diff --git a/tests/mount-local/test-parallel-mount-local.c b/tests/mount-local/test-parallel-mount-local.c
ffd6ed
index fa6cd79..88ca2d3 100644
ffd6ed
--- a/tests/mount-local/test-parallel-mount-local.c
ffd6ed
+++ b/tests/mount-local/test-parallel-mount-local.c
ffd6ed
@@ -94,7 +94,7 @@ main (int argc, char *argv[])
ffd6ed
 
ffd6ed
   /* Allow the test to be skipped by setting an environment variable. */
ffd6ed
   skip = getenv ("SKIP_TEST_PARALLEL_MOUNT_LOCAL");
ffd6ed
-  if (skip && STREQ (skip, "1")) {
ffd6ed
+  if (skip && guestfs___is_true (skip) > 0) {
ffd6ed
     fprintf (stderr, "%s: test skipped because environment variable set.\n",
ffd6ed
              program_name);
ffd6ed
     exit (77);
ffd6ed
diff --git a/tests/parallel/Makefile.am b/tests/parallel/Makefile.am
ffd6ed
index be63256..9421bfc 100644
ffd6ed
--- a/tests/parallel/Makefile.am
ffd6ed
+++ b/tests/parallel/Makefile.am
ffd6ed
@@ -34,6 +34,7 @@ test_parallel_CFLAGS = \
ffd6ed
 	-pthread \
ffd6ed
 	$(WARN_CFLAGS) $(WERROR_CFLAGS)
ffd6ed
 test_parallel_LDADD = \
ffd6ed
+	$(top_builddir)/src/libutils.la \
ffd6ed
 	$(top_builddir)/src/libguestfs.la \
ffd6ed
 	$(top_builddir)/gnulib/lib/libgnu.la
ffd6ed
 
ffd6ed
diff --git a/tests/parallel/test-parallel.c b/tests/parallel/test-parallel.c
ffd6ed
index edd87d9..e412143 100644
ffd6ed
--- a/tests/parallel/test-parallel.c
ffd6ed
+++ b/tests/parallel/test-parallel.c
ffd6ed
@@ -76,7 +76,7 @@ main (int argc, char *argv[])
ffd6ed
 
ffd6ed
   /* Allow the test to be skipped by setting an environment variable. */
ffd6ed
   skip = getenv ("SKIP_TEST_PARALLEL");
ffd6ed
-  if (skip && STREQ (skip, "1")) {
ffd6ed
+  if (skip && guestfs___is_true (skip) > 0) {
ffd6ed
     fprintf (stderr, "%s: test skipped because environment variable set.\n",
ffd6ed
              program_name);
ffd6ed
     exit (77);
ffd6ed
diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am
ffd6ed
index a5e7cfc..de97526 100644
ffd6ed
--- a/tests/regressions/Makefile.am
ffd6ed
+++ b/tests/regressions/Makefile.am
ffd6ed
@@ -111,6 +111,7 @@ rhbz914931_CFLAGS = \
ffd6ed
 	-pthread \
ffd6ed
 	$(WARN_CFLAGS) $(WERROR_CFLAGS)
ffd6ed
 rhbz914931_LDADD = \
ffd6ed
+	$(top_builddir)/src/libutils.la \
ffd6ed
 	$(top_builddir)/src/libguestfs.la
ffd6ed
 
ffd6ed
 rhbz1055452_SOURCES = rhbz1055452.c
ffd6ed
diff --git a/tests/regressions/rhbz914931.c b/tests/regressions/rhbz914931.c
ffd6ed
index faa3dd2..569e261 100644
ffd6ed
--- a/tests/regressions/rhbz914931.c
ffd6ed
+++ b/tests/regressions/rhbz914931.c
ffd6ed
@@ -41,7 +41,7 @@ main (int argc, char *argv[])
ffd6ed
 
ffd6ed
   /* Allow this test to be skipped. */
ffd6ed
   str = getenv ("SKIP_TEST_RHBZ914931");
ffd6ed
-  if (str && STREQ (str, "1")) {
ffd6ed
+  if (str && guestfs___is_true (str) > 0) {
ffd6ed
     printf ("%s: test skipped because environment variable is set.\n",
ffd6ed
             program_name);
ffd6ed
     exit (77);
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed