[libvirt] [PATCH] OpenVZ driver: fix openvzGetVPSUUID()

openvzGetUUID did not work since openvz_readline() was replaced by getline() --- src/openvz/openvz_conf.c | 13 ++----------- 1 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 2cccd81..7b939b2 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -863,7 +863,6 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len) char *conf_file; char *line = NULL; size_t line_size = 0; - ssize_t ret; char *saveptr = NULL; char *uuidbuf; char *iden; @@ -877,16 +876,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len) if (fp == NULL) goto cleanup; - while (1) { - ret = getline(&line, &line_size, fp); - if (ret == -1) - goto cleanup; - - if (ret == 0) { /* EoF, UUID was not found */ - uuidstr[0] = 0; - break; - } - + uuidstr[0] = 0; + while (getline(&line, &line_size, fp) >= 0) { iden = strtok_r(line, " ", &saveptr); uuidbuf = strtok_r(NULL, "\n", &saveptr); -- 1.7.1

2011/5/27 Jean-Baptiste Rouault <jean-baptiste.rouault@diateam.net>:
openvzGetUUID did not work since openvz_readline() was replaced by getline() --- src/openvz/openvz_conf.c | 13 ++----------- 1 files changed, 2 insertions(+), 11 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 2cccd81..7b939b2 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -863,7 +863,6 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len) char *conf_file; char *line = NULL; size_t line_size = 0; - ssize_t ret; char *saveptr = NULL; char *uuidbuf; char *iden; @@ -877,16 +876,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len) if (fp == NULL) goto cleanup;
- while (1) { - ret = getline(&line, &line_size, fp); - if (ret == -1) - goto cleanup; - - if (ret == 0) { /* EoF, UUID was not found */ - uuidstr[0] = 0; - break; - } - + uuidstr[0] = 0; + while (getline(&line, &line_size, fp) >= 0) { iden = strtok_r(line, " ", &saveptr); uuidbuf = strtok_r(NULL, "\n", &saveptr);
We need distinguish between getline returning -1 because of EOF and because of another error. I missed this problem in the other regression fix and posted a follow up patch [1] for this. I propose the attached patch as v2 for you patch. I assume you have an OpenVZ setup at hand, could you test this patch? [1] https://www.redhat.com/archives/libvir-list/2011-May/msg01788.html Matthias

On Friday 27 May 2011 13:51:05 Matthias Bolte wrote:
We need distinguish between getline returning -1 because of EOF and because of another error. I missed this problem in the other regression fix and posted a follow up patch [1] for this.
I propose the attached patch as v2 for you patch. I assume you have an OpenVZ setup at hand, could you test this patch?
[1] https://www.redhat.com/archives/libvir-list/2011-May/msg01788.html
Matthias
I tested your patch and it seems to work fine. Regards, Jean-Baptiste -- Jean-Baptiste ROUAULT Ingénieur R&D - Diateam : Architectes de l'information Phone : +33 (0)9 53 16 02 70 Fax : +33 (0)2 98 050 051

On Fri, May 27, 2011 at 03:12:26PM +0200, Jean-Baptiste Rouault wrote:
On Friday 27 May 2011 13:51:05 Matthias Bolte wrote:
We need distinguish between getline returning -1 because of EOF and because of another error. I missed this problem in the other regression fix and posted a follow up patch [1] for this.
I propose the attached patch as v2 for you patch. I assume you have an OpenVZ setup at hand, could you test this patch?
[1] https://www.redhat.com/archives/libvir-list/2011-May/msg01788.html
Matthias
I tested your patch and it seems to work fine.
ACK then :-) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

2011/5/27 Daniel Veillard <veillard@redhat.com>:
On Fri, May 27, 2011 at 03:12:26PM +0200, Jean-Baptiste Rouault wrote:
On Friday 27 May 2011 13:51:05 Matthias Bolte wrote:
We need distinguish between getline returning -1 because of EOF and because of another error. I missed this problem in the other regression fix and posted a follow up patch [1] for this.
I propose the attached patch as v2 for you patch. I assume you have an OpenVZ setup at hand, could you test this patch?
[1] https://www.redhat.com/archives/libvir-list/2011-May/msg01788.html
Matthias
I tested your patch and it seems to work fine.
ACK then :-)
Daniel
Thanks, pushed then. There are other usages of getline in the OpenVZ driver, but they should all be safe because they don't distinguish between 0 and -1, except openvzGetProcessInfo. Jean-Baptiste could you test virsh dominfo of a running OpenVZ domain? I expect it to currently fail and will post a patch for it. Matthias

On Friday 27 May 2011 16:01:32 Matthias Bolte wrote:
Thanks, pushed then.
There are other usages of getline in the OpenVZ driver, but they should all be safe because they don't distinguish between 0 and -1, except openvzGetProcessInfo.
Jean-Baptiste could you test virsh dominfo of a running OpenVZ domain? I expect it to currently fail and will post a patch for it.
Matthias
virsh dominfo on a running domain doesn't fail here :
virsh # dominfo 100 ID : 100 Nom : 100 UUID : 0a0cf7cb-efb4-4065-ac2d-e63ad51e72cf Type de SE : exe État : en cours d'exécution CPU : 1 Temps CPU : 2,3s Mémoire Max : 262144 kB Mémoire utilisée : 262144 kB Persistent: yes Autostart: disable
I tried it on a stopped domain and it doesn't fail either. Jean-Baptiste -- Jean-Baptiste ROUAULT Ingénieur R&D - Diateam : Architectes de l'information Phone : +33 (0)9 53 16 02 70 Fax : +33 (0)2 98 050 051

2011/5/27 Jean-Baptiste Rouault <jean-baptiste.rouault@diateam.net>:
On Friday 27 May 2011 16:01:32 Matthias Bolte wrote:
Thanks, pushed then.
There are other usages of getline in the OpenVZ driver, but they should all be safe because they don't distinguish between 0 and -1, except openvzGetProcessInfo.
Jean-Baptiste could you test virsh dominfo of a running OpenVZ domain? I expect it to currently fail and will post a patch for it.
Matthias
virsh dominfo on a running domain doesn't fail here :
virsh # dominfo 100 ID : 100 Nom : 100 UUID : 0a0cf7cb-efb4-4065-ac2d-e63ad51e72cf Type de SE : exe État : en cours d'exécution CPU : 1 Temps CPU : 2,3s Mémoire Max : 262144 kB Mémoire utilisée : 262144 kB Persistent: yes Autostart: disable
I tried it on a stopped domain and it doesn't fail either.
Jean-Baptiste
Ah, makes sense, openvzGetProcessInfo doesn't normally run in the situation where getline hits EOF because the loop will find the appropriate line and exit the loop. Thanks for testing. I'll post a patch to restore the original EOF handling even if it's not critical. Matthias
participants (3)
-
Daniel Veillard
-
Jean-Baptiste Rouault
-
Matthias Bolte