Daniel Veillard wrote:
On Mon, Apr 03, 2006 at 12:01:17PM -0400, Bryan D. Payne wrote:
I just updated to the latest CVS version of libvir. It looks like
there's a bug in virDomainLookupByID. The behavior that I'm seeing
is that the path variable is set and so the code never enters the
block to find the value for name. Therefore, at the end of the
function, the condition (ret->name == NULL) is true and it jumps into
the error code and returns NULL.
If I comment out the code that sets the path variable, things seem to
work normally. Although, I presume that the idea was to extract the
name from the path information...
Right, that's a bug I introduced in the refactoring. Even if trivial
sending a small patch (cvs diff -u) is always a good idea :-)
AFAIK, name is not contained in the domain's home path. Here is a patch
I have been using for virDomainLookupByID().
Regards,
Jim
Index: libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.18
diff -u -r1.18 libvirt.c
--- libvirt.c 3 Apr 2006 13:46:43 -0000 1.18
+++ libvirt.c 4 Apr 2006 21:27:41 -0000
@@ -610,6 +610,9 @@
virDomainLookupByID(virConnectPtr conn, int id)
{
char *path = NULL;
+ char **names;
+ char **tmp;
+ int ident;
virDomainPtr ret;
char *name = NULL;
unsigned char uuid[16];
@@ -623,27 +626,25 @@
return (NULL);
}
- /* lookup is easier with the Xen store so try it first */
+ /* retrieve home path of the domain */
if (conn->xshandle != NULL) {
path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
}
- /* fallback to xend API then */
- if (path == NULL) {
- char **names = xenDaemonListDomains(conn);
- char **tmp = names;
- int ident;
-
- if (names != NULL) {
- while (*tmp != NULL) {
- ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]);
- if (ident == id) {
- name = strdup(*tmp);
- break;
- }
- tmp++;
- }
- free(names);
- }
+
+ /* path does not contain name, use xend API to retrieve name */
+ names = xenDaemonListDomains(conn);
+ tmp = names;
+
+ if (names != NULL) {
+ while (*tmp != NULL) {
+ ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]);
+ if (ident == id) {
+ name = strdup(*tmp);
+ break;
+ }
+ tmp++;
+ }
+ free(names);
}
ret = (virDomainPtr) malloc(sizeof(virDomain));