]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_conf.c: use new function, virFileReadLimFD
authorJim Meyering <meyering@redhat.com>
Tue, 2 Sep 2008 10:30:40 +0000 (10:30 +0000)
committerJim Meyering <meyering@redhat.com>
Tue, 2 Sep 2008 10:30:40 +0000 (10:30 +0000)
* src/qemu_conf.c (qemudExtractVersionInfo): Use virFileReadLimFD
and VIR_FREE in place of an open-coded loop and a static buffer.

ChangeLog
src/qemu_conf.c

index b21088840d6d9596a59ef131023eb465de7cb3ef..87c3c684bc2e1a4a48d2790b13339dbd999b61c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 Tue Sep  2 12:28:54 CEST 2008 Jim Meyering <meyering@redhat.com>
 
+       qemu_conf.c: use new function, virFileReadLimFD
+       * src/qemu_conf.c (qemudExtractVersionInfo): Use virFileReadLimFD
+       and VIR_FREE in place of an open-coded loop and a static buffer.
+
        util.c: add a file-descriptor-based wrapper for fread_file_lim
        * src/util.c (virFileReadLimFP): New function.
        (__virFileReadLimFD): New function.
index bab2092747793b0f918903e2d36c4479cee3502a..0686978aad86fe8b64cb7f9b6be6f7168d665729 100644 (file)
@@ -401,8 +401,7 @@ int qemudExtractVersionInfo(const char *qemu,
     const char *const qemuenv[] = { "LC_ALL=C", NULL };
     pid_t child;
     int newstdout = -1;
-    char help[8192]; /* Ought to be enough to hold QEMU help screen */
-    int got = 0, ret = -1, status;
+    int ret = -1, status;
     unsigned int major, minor, micro;
     unsigned int version;
     unsigned int flags = 0;
@@ -416,16 +415,11 @@ int qemudExtractVersionInfo(const char *qemu,
                 &child, -1, &newstdout, NULL, VIR_EXEC_NONE) < 0)
         return -1;
 
-
-    while (got < (sizeof(help)-1)) {
-        int len;
-        if ((len = saferead(newstdout, help+got, sizeof(help)-got-1)) < 0)
-            goto cleanup2;
-        if (!len)
-            break;
-        got += len;
-    }
-    help[got] = '\0';
+    char *help = NULL;
+    enum { MAX_HELP_OUTPUT_SIZE = 8192 };
+    int len = virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help);
+    if (len < 0)
+        goto cleanup2;
 
     if (sscanf(help, "QEMU PC emulator version %u.%u.%u",
                &major, &minor, &micro) != 3) {
@@ -447,7 +441,6 @@ int qemudExtractVersionInfo(const char *qemu,
     if (version >= 9000)
         flags |= QEMUD_CMD_FLAG_VNC_COLON;
 
-
     if (retversion)
         *retversion = version;
     if (retflags)
@@ -459,6 +452,7 @@ int qemudExtractVersionInfo(const char *qemu,
                major, minor, micro, version, flags);
 
 cleanup2:
+    VIR_FREE(help);
     if (close(newstdout) < 0)
         ret = -1;
 
@@ -1229,4 +1223,3 @@ int qemudBuildCommandLine(virConnectPtr conn,
 #undef ADD_ARG_LIT
 #undef ADD_ARG_SPACE
 }
-