# HG changeset patch
# User Jay Gagnon <grendel(a)linux.vnet.ibm.com>
# Date 1201201667 18000
# Node ID 1d9cbc7cfb1f39a08dbf43070d0f1a140faa8fe4
# Parent adf18661f7948a0287a4586d97572793e8e03826
Protect CSI from transient domains
Testing has revealed a couple of ways to segfault the CSI provider. One is a domain that
is undefined immediately after being defined, the other is a domain that is listed as
defined by libvirt but has not actually been fully defined by xend. In either case, the
problem boils down to CSI trying to get an XML description of a domain that isn't
there. This eventually results in a segfault.
Signed-off-by: Jay Gagnon <grendel(a)linux.vnet.ibm.com>
diff -r adf18661f794 -r 1d9cbc7cfb1f src/Virt_ComputerSystemIndication.c
--- a/src/Virt_ComputerSystemIndication.c Thu Jan 24 12:56:45 2008 +0100
+++ b/src/Virt_ComputerSystemIndication.c Thu Jan 24 14:07:47 2008 -0500
@@ -54,6 +54,9 @@ static pthread_cond_t lifecycle_cond = P
static pthread_cond_t lifecycle_cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t lifecycle_mutex = PTHREAD_MUTEX_INITIALIZER;
static bool lifecycle_enabled = 0;
+
+#define WAIT_TIME 3
+#define FAIL_WAIT_TIME 2
#ifdef CMPI_EI_VOID
# define _EI_RTYPE void
@@ -224,14 +227,14 @@ static bool _do_indication(const CMPIBro
return ret;
}
-static bool wait_for_event(void)
+static bool wait_for_event(int wait_time)
{
struct timespec timeout;
int ret;
clock_gettime(CLOCK_REALTIME, &timeout);
- timeout.tv_sec += 3;
+ timeout.tv_sec += wait_time;
ret = pthread_cond_timedwait(&lifecycle_cond,
&lifecycle_mutex,
@@ -336,11 +339,17 @@ static CMPI_THREAD_RETURN lifecycle_thre
while (lifecycle_enabled) {
int i;
bool res;
+ bool failure = false;
cur_count = get_domain_list(conn, &tmp_list);
s = doms_to_xml(&cur_xml, tmp_list, cur_count);
- if (s.rc != CMPI_RC_OK)
- CU_DEBUG("doms_to_xml failed.");
+ if (s.rc != CMPI_RC_OK) {
+ CU_DEBUG("doms_to_xml failed. retry in %d seconds",
+ FAIL_WAIT_TIME);
+ failure = true;
+ goto fail;
+ }
+
free_domain_list(tmp_list, cur_count);
free(tmp_list);
@@ -369,11 +378,16 @@ static CMPI_THREAD_RETURN lifecycle_thre
free_dom_xml(prev_xml[i]);
}
- free(prev_xml);
- prev_xml = cur_xml;
- prev_count = cur_count;
+ fail:
+ if (failure) {
+ wait_for_event(FAIL_WAIT_TIME);
+ } else {
+ free(prev_xml);
+ prev_xml = cur_xml;
+ prev_count = cur_count;
- wait_for_event();
+ wait_for_event(WAIT_TIME);
+ }
}
out: