[libvirt] [PATCH] tests: avoid crash when run under gcov

Running ./autobuild.sh failed when gcov is installed, because commandtest ended up crashing during gcov's getenv() call after exit() had already started. I traced this nasty bug back to a scoping issue present since the test introduction. * tests/commandtest.c (mymain): Move newenv... (newenv): ...to a scope that is still useful during exit(). --- Pushing under the build-breaker rule. tests/commandtest.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index caad698..429a026 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -748,6 +748,18 @@ cleanup: return ret; } +static const char *const newenv[] = { + "PATH=/usr/bin:/bin", + "HOSTNAME=test", + "LANG=C", + "HOME=/home/test", + "USER=test", + "LOGNAME=test" + "TMPDIR=/tmp", + "DISPLAY=:0.0", + NULL +}; + static int mymain(void) { @@ -771,18 +783,9 @@ mymain(void) virInitialize(); - const char *const newenv[] = { - "PATH=/usr/bin:/bin", - "HOSTNAME=test", - "LANG=C", - "HOME=/home/test", - "USER=test", - "LOGNAME=test" - "TMPDIR=/tmp", - "DISPLAY=:0.0", - NULL - }; environ = (char **)newenv; # define DO_TEST(NAME) \ if (virtTestRun("Command Exec " #NAME " test", \ -- 1.7.4.4

On Wed, May 11, 2011 at 09:57:46AM -0600, Eric Blake wrote:
Running ./autobuild.sh failed when gcov is installed, because commandtest ended up crashing during gcov's getenv() call after exit() had already started. I traced this nasty bug back to a scoping issue present since the test introduction.
* tests/commandtest.c (mymain): Move newenv... (newenv): ...to a scope that is still useful during exit(). ---
Pushing under the build-breaker rule.
tests/commandtest.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/tests/commandtest.c b/tests/commandtest.c index caad698..429a026 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -748,6 +748,18 @@ cleanup: return ret; }
+static const char *const newenv[] = { + "PATH=/usr/bin:/bin", + "HOSTNAME=test", + "LANG=C", + "HOME=/home/test", + "USER=test", + "LOGNAME=test" + "TMPDIR=/tmp", + "DISPLAY=:0.0", + NULL +}; + static int mymain(void) { @@ -771,18 +783,9 @@ mymain(void)
virInitialize();
- const char *const newenv[] = { - "PATH=/usr/bin:/bin", - "HOSTNAME=test", - "LANG=C", - "HOME=/home/test", - "USER=test", - "LOGNAME=test" - "TMPDIR=/tmp", - "DISPLAY=:0.0", - NULL - }; environ = (char **)newenv;
# define DO_TEST(NAME) \ if (virtTestRun("Command Exec " #NAME " test", \ --
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 05/11/2011 09:57 AM, Eric Blake wrote:
Running ./autobuild.sh failed when gcov is installed, because commandtest ended up crashing during gcov's getenv() call after exit() had already started. I traced this nasty bug back to a scoping issue present since the test introduction.
* tests/commandtest.c (mymain): Move newenv... (newenv): ...to a scope that is still useful during exit().
P.S. I think that's a bug in gcov for calling getenv("GCOV_PREFIX") multiple times during the program. Since the program can change it's own environment, gcov should only be calling getenv() once during startup and caching the results for the life of the program. So I filed: https://bugzilla.redhat.com/show_bug.cgi?id=703919 -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel P. Berrange
-
Eric Blake