From 995bf76d17b8c8cdfa6cc3a30eb86cd8afb55d50 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Thu, 16 May 2013 09:50:58 -0400 Subject: [PATCH] shunloadtest: Resolve Coverity CHECKED_RETURN error The shunloadStart function didn't check the status of virInitialize which was flagged by Coverity. Adjust the function and shunloadtest in order to handle the situation. --- tests/shunloadhelper.c | 12 ++++++++---- tests/shunloadtest.c | 24 ++++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/shunloadhelper.c b/tests/shunloadhelper.c index a8f5aef4e9..f2afbe8872 100644 --- a/tests/shunloadhelper.c +++ b/tests/shunloadhelper.c @@ -36,16 +36,20 @@ static void shunloadError(void *userData ATTRIBUTE_UNUSED, { } -void shunloadStart(void); +int shunloadStart(void); -void shunloadStart(void) { +int shunloadStart(void) { virConnectPtr conn; virSetErrorFunc(NULL, shunloadError); - virInitialize(); + if (virInitialize() < 0) + return -1; conn = virConnectOpen("test:///default"); virDomainDestroy(NULL); - if (conn) + if (conn) { virConnectClose(conn); + return 0; + } + return -1; } diff --git a/tests/shunloadtest.c b/tests/shunloadtest.c index 8271b93647..8190e97a75 100644 --- a/tests/shunloadtest.c +++ b/tests/shunloadtest.c @@ -56,17 +56,22 @@ pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; bool running = false; +bool failstart = false; bool quit = false; static void *threadMain(void *arg) { - void (*startup)(void) = arg; + int (*startup)(void) = arg; - startup(); - - pthread_mutex_lock(&lock); - running = true; - pthread_cond_signal(&cond); + if (startup() < 0) { + pthread_mutex_lock(&lock); + failstart = true; + pthread_cond_signal(&cond); + } else { + pthread_mutex_lock(&lock); + running = true; + pthread_cond_signal(&cond); + } while (!quit) { pthread_cond_wait(&cond, &lock); @@ -119,7 +124,7 @@ int main(int argc ATTRIBUTE_UNUSED, char **argv) /* Wait for the thread to start and call libvirt */ pthread_mutex_lock(&lock); - while (!running) { + while (!running && !failstart) { pthread_cond_wait(&cond, &lock); } @@ -138,7 +143,10 @@ int main(int argc ATTRIBUTE_UNUSED, char **argv) * causing a SEGV ! */ - fprintf(stderr, "OK\n"); + if (failstart) + fprintf(stderr, "FAIL to initialize libvirt\n"); + else + fprintf(stderr, "OK\n"); return 0; }