[Pkg-libvirt-commits] [libguestfs] 16/26: p2v: Fix parsing of p2v.memory parameter (RHBZ#1229262).

Hilko Bengen bengen at moszumanska.debian.org
Sun Nov 1 17:11:28 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag upstream/1.28.12
in repository libguestfs.

commit f6b65c04492ff79bca14007a16ec5b2e55b4ee60
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Jun 10 13:38:11 2015 +0100

    p2v: Fix parsing of p2v.memory parameter (RHBZ#1229262).
    
    The sscanf call always failed because we checked for the wrong return
    code.
    
    We don't need to allocate two characters for the mem_code field since
    sscanf doesn't append a nul byte.
    
    This commit also allows you to use lowercase 'm' or 'g' as a memory
    unit.
    
    Also clarify the documentation: the memory unit must be given.
    
    (cherry picked from commit bb5b23c1519a3901909a5ed51ce2f88e0904cb85)
---
 p2v/kernel.c     | 12 +++++++-----
 p2v/virt-p2v.pod |  9 ++++++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/p2v/kernel.c b/p2v/kernel.c
index 8333cf3..1d01a59 100644
--- a/p2v/kernel.c
+++ b/p2v/kernel.c
@@ -108,20 +108,22 @@ kernel_configuration (struct config *config, const char *cmdline)
 
   r = strstr (cmdline, "p2v.memory=");
   if (r) {
-    char mem_code[2];
+    char mem_code;
 
     r += 5+6;
-    if (sscanf (r, "%" SCNu64 "%c", &config->memory, mem_code) != 1) {
+    if (sscanf (r, "%" SCNu64 "%c", &config->memory, &mem_code) != 2) {
       fprintf (stderr, "%s: cannot parse p2v.memory from kernel command line\n",
                guestfs___program_name);
       exit (EXIT_FAILURE);
     }
     config->memory *= 1024;
-    if (mem_code[0] == 'M' || mem_code[0] == 'G')
+    if (mem_code == 'M' || mem_code == 'm'
+        || mem_code == 'G' || mem_code == 'g')
       config->memory *= 1024;
-    if (mem_code[0] == 'G')
+    if (mem_code == 'G' || mem_code == 'g')
       config->memory *= 1024;
-    if (mem_code[0] != 'M' && mem_code[0] != 'G') {
+    if (mem_code != 'M' && mem_code != 'm'
+        && mem_code != 'G' && mem_code != 'g') {
       fprintf (stderr, "%s: p2v.memory on kernel command line must be followed by 'G' or 'M'\n",
                guestfs___program_name);
       exit (EXIT_FAILURE);
diff --git a/p2v/virt-p2v.pod b/p2v/virt-p2v.pod
index d950b7f..1b9df5f 100644
--- a/p2v/virt-p2v.pod
+++ b/p2v/virt-p2v.pod
@@ -338,9 +338,12 @@ use the same as the number of physical CPUs.
 
 =item B<p2v.memory=NN(M|G)>
 
-The size of the guest memory.  You can specify this in megabytes or
-gigabytes by using (eg) C<p2v.memory=1024M> or C<p2v.memory=1G>.  The
-default is to use the same amount of RAM as on the physical machine.
+The size of the guest memory.  You must specify the unit as either
+megabytes or gigabytes by using (eg) C<p2v.memory=1024M> or
+C<p2v.memory=1G>.
+
+The default is to use the same amount of RAM as on the physical
+machine.
 
 =item B<p2v.debug>
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list