{
}
-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;
}
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;
-
- startup();
-
- pthread_mutex_lock(&lock);
- running = true;
- pthread_cond_signal(&cond);
+ int (*startup)(void) = arg;
+
+ 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);
/* Wait for the thread to start and call libvirt */
pthread_mutex_lock(&lock);
- while (!running) {
+ while (!running && !failstart) {
pthread_cond_wait(&cond, &lock);
}
* causing a SEGV !
*/
- fprintf(stderr, "OK\n");
+ if (failstart)
+ fprintf(stderr, "FAIL to initialize libvirt\n");
+ else
+ fprintf(stderr, "OK\n");
return 0;
}