Hi, I am using libvirt api to create an app, I am facing a problem. I can connect to connection object 20 number of times in programm after that it gives connection object null. Here is the sample code. Normally code should run 1000 times but it only runs 20 times Filename: list.cpp #include<pthread.h> #include<stdlib.h> #include<stdio.h> #include<malloc.h> #include <iostream> #include<string.h> #include <libvirt/libvirt.h> #include <libvirt/virterror.h> static int count; static void customErrorFunc(void *userdata, virErrorPtr err) { } int main() { virConnectPtr conn; for ( int i=0; i< 1000;i++) { conn = virConnectOpen("qemu:///system"); if (conn == NULL) { fprintf(stderr, "Failed to open connection to qemu:///system\n"); printf("Failed to open connection to qemu:///system\n"); virConnectClose(conn); return NULL; } printf("Hello %d\n",i); virError err; virSetErrorFunc(NULL, customErrorFunc); int j; int numDomains1,numDomains2,numDomains; int *activeDomains; numDomains1 = virConnectNumOfDomains(conn); activeDomains = (int*)malloc(sizeof(int) * numDomains1); numDomains1 = virConnectListDomains(conn, activeDomains, numDomains1); for (int j = 0 ; j < numDomains1 ; j++) { virDomainPtr dom; dom = virDomainLookupByID(conn,activeDomains[j]); free(dom); } free(activeDomains); count--; virConnectClose(conn); } } Output: Hello 0 Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6 Hello 7 Hello 8 Hello 9 Hello 10 Hello 11 Hello 12 Hello 13 Hello 14 Hello 15 Hello 16 Hello 17 Hello 18 Hello 19 Failed to open connection to qemu:///system Failed to open connection to qemu:///system Can any one tell me where I am going wrong. Regards, Pankaj Rawat NECHCL ST DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NECHCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NECHCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. . ----------------------------------------------------------------------------------------------------------------------- |
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list