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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/5/27 Jean-Baptiste Rouault <jean-baptiste.rouault@xxxxxxxxxxx>:
> 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
From 553610ca59753d036d75792ff5900280a1296c37 Mon Sep 17 00:00:00 2001
From: Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
Date: Fri, 27 May 2011 13:50:13 +0200
Subject: [PATCH] openvz: Fix regression in openvzGetVPSUUID

Commit f044376530f313a replaced openvz_readline with getline and
changed EOF-handling in the openvzGetVPSUUID.

This patch restores original EOF-handling.

Reported by Jean-Baptiste Rouault.
---
 src/openvz/openvz_conf.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 2cccd81..5f33f75 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;
@@ -878,13 +877,13 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
         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;
+        if (getline(&line, &line_size, fp) < 0) {
+            if (feof(fp)) { /* EOF, UUID was not found */
+                uuidstr[0] = 0;
+                break;
+            } else {
+                goto cleanup;
+            }
         }
 
         iden = strtok_r(line, " ", &saveptr);
-- 
1.7.0.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]