Re: [Bug 702602] [PATCH] OpenVZ configuration files parsing

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

 



Hi.

As reported by Diego Blanco in

- https://bugzilla.redhat.com/show_bug.cgi?id=702602

commit f0443765 which replaced openvz_readline to getline(3)
broke OpenVZ driver as it changed semantics of EOF-handling
when parsing OpenVZ configuration.

There're several other issues reported with current OpenVZ driver:

  #1: unclear error message when parsing "CPUS=" line
  #2: openvz driver goes into crashing loop
  #3: "NETIF=" line in configuration is not parsed correctly
  #4: aborts even when optional parameter is missing
  #5: there's a potential memory leak

In this email, I'm sending in updated patch to fix #[145].
This patch does not fix #[23] as I haven't verified these yet,
but this at least got me to run OpenVZ on libvirt once again.

This patch applies to latest git, and I verified that both
"make check" and "make syntax-check" passes (except
for check_author_list check).

Best Regards,

> --- Comment #3 from Cole Robinson <crobinso@xxxxxxxxxx> 2011-05-18 09:34:21 EDT ---
> Thanks for the report and the patch. However, libvirt devs generally don't
> review patches in bugzilla. Can you please send your patch to
> libvirt-list@xxxxxxxxxx, and ensure that it applied against latest upstream,
> and that make check  and make syntax-check both pass?
>
> When the patch is applied, we can close this bug. Thanks!
>
> --
> Configure bugmail: https://bugzilla.redhat.com/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug.
>
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index cfb6917..3e4844a 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -642,53 +642,45 @@ openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value)
 /*
  * value will be freed before a new value is assigned to it, the caller is
  * responsible for freeing it afterwards.
+ *
+ * Returns <0 on error, 0 if not found, 1 if found.
  */
 static int
 openvzReadConfigParam(const char *conf_file, const char *param, char **value)
 {
     char *line = NULL;
     size_t line_size = 0;
-    ssize_t ret;
     FILE *fp;
-    int found = 0;
-    char *sf, *token;
-    char *saveptr = NULL;
-
-    value[0] = 0;
+    int err = 0;
+    char *sf, *token, *saveptr;
 
     fp = fopen(conf_file, "r");
     if (fp == NULL)
         return -1;
 
-    while (1) {
-        ret = getline(&line, &line_size, fp);
-        if (ret <= 0)
-            break;
+    VIR_FREE(*value);
+    while (getline(&line, &line_size, fp) >= 0) {
+        if (! STREQLEN(line, param, strlen(param)))
+            continue;
+
+        sf = line + strlen(param);
+        if (*sf++ != '=') continue;
+
         saveptr = NULL;
-        if (STREQLEN(line, param, strlen(param))) {
-            sf = line;
-            sf += strlen(param);
-            if (sf[0] == '=' && sf[1] != '\0' ) {
-                sf++;
-                if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) {
-                    VIR_FREE(*value);
-                    *value = strdup(token);
-                    if (value == NULL) {
-                        ret = -1;
-                        break;
-                    }
-                    found = 1;
-                }
+        if ((token = strtok_r(sf, "\"\t\n", &saveptr)) != NULL) {
+            VIR_FREE(*value);
+            *value = strdup(token);
+            if (*value == NULL) {
+                err = 1;
+                break;
             }
-       }
+            /* keep going - last entry wins */
+        }
     }
     VIR_FREE(line);
     VIR_FORCE_FCLOSE(fp);
 
-    if (ret == 0 && found)
-        ret = 1;
-
-    return ret;
+    return err ? -1 : *value ? 1 : 0;
 }
 
 /*
--
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]