From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1V9dl4-00065O-U4 for mharc-grub-devel@gnu.org; Wed, 14 Aug 2013 12:17:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9dku-00064f-HW for grub-devel@gnu.org; Wed, 14 Aug 2013 12:17:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V9dkl-0001bV-DD for grub-devel@gnu.org; Wed, 14 Aug 2013 12:17:04 -0400 Received: from mail-we0-x232.google.com ([2a00:1450:400c:c03::232]:52152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9dkl-0001b5-5a for grub-devel@gnu.org; Wed, 14 Aug 2013 12:16:55 -0400 Received: by mail-we0-f178.google.com with SMTP id u57so7775952wes.23 for ; Wed, 14 Aug 2013 09:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=RNX/xRk9mdTWv32JKjuoAuBV5ZrZPrt+HynNpXb9z2s=; b=GryUK69DHI+Wg/98kAd4HA75K1Vp22lKHMpYqnZpATCP6zUlL4/TbLU3bC9O8Zk2mo luwRTsxbbqmnpgTdxusE0jAliCPrzQWZX/nrBKrEz5rK+qDX9E9U2P2QddOio1cPKdlS a5i+zxHDqsICejXRxml9p/Fm7bVfYZ1rc1P75pX3A+mmghNjc6jVAIfZBd5BYmJI+fyZ X3ND7etWI9XVDS0WdwU39LHD2pDhWPIT26nu/5SnYgQxXpOJO29DBIyecD3S8lApCi8R IhXFqkjUAyeuG3Dcli7oxidzyLRGbNaBzNKUFPUYB5uHiFj03uuzkFA3zcYZyPuiExGI dIIQ== X-Received: by 10.180.82.5 with SMTP id e5mr2631090wiy.15.1376497014433; Wed, 14 Aug 2013 09:16:54 -0700 (PDT) Received: from [192.168.42.216] (223-226.197-178.cust.bluewin.ch. [178.197.226.223]) by mx.google.com with ESMTPSA id jc18sm2431510wic.5.2013.08.14.09.16.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 Aug 2013 09:16:53 -0700 (PDT) Message-ID: <520BAD6A.1040801@gmail.com> Date: Wed, 14 Aug 2013 18:16:42 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130630 Icedove/17.0.7 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH] use vgs --nameprefixes to protect against whitespace changes References: <1374217896-21412-1-git-send-email-arvidjaar@gmail.com> In-Reply-To: <1374217896-21412-1-git-send-email-arvidjaar@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::232 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 16:17:13 -0000 On 19.07.2013 09:11, Andrey Borzenkov wrote: > Do not assume single blank at the end of PV name. At least > lvm2-2.02.98-24.3 (openSUSE 13.1 M3) puts exra blank at the end. > > linux-chxo:~ # grub2-probe -t abstraction /lib > mdadm: cannot open /dev/md1 : No such file or directory > grub2-probe: error: cannot open `/dev/md1 ': No such file or directory. > linux-chxo:~ # : Update grub with patch > linux-chxo:~ # grub2-probe -t abstraction /lib > diskfilter mdraid1x lvm > linux-chxo:~ # vgs --options pv_name --noheadings | xxd > 0000000: 2020 2f64 6576 2f6d 6431 2020 0a /dev/md1 . > linux-chxo:~ # rpm -q lvm2 > lvm2-2.02.98-24.3.i586 > > This patch changes it to use --nameprefixes which returns each PV name as > LVM2_PV_NAME='xxx' > This code wouldn't handle name containing \n correctly but it's a subject for another patch as issue is already present. Go ahead. > Signed-off-by: Andrey Borzenkov > > --- > util/getroot.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/util/getroot.c b/util/getroot.c > index 2ad8a55..479ab78 100644 > --- a/util/getroot.c > +++ b/util/getroot.c > @@ -1322,7 +1322,7 @@ grub_util_get_dev_abstraction (const char *os_dev) > static void > pull_lvm_by_command (const char *os_dev) > { > - char *argv[6]; > + char *argv[7]; > int fd; > pid_t pid; > FILE *mdadm; > @@ -1355,8 +1355,9 @@ pull_lvm_by_command (const char *os_dev) > argv[1] = (char *) "--options"; > argv[2] = (char *) "pv_name"; > argv[3] = (char *) "--noheadings"; > - argv[4] = vgname; > - argv[5] = NULL; > + argv[4] = (char *) "--nameprefixes"; > + argv[5] = vgname; > + argv[6] = NULL; > > pid = exec_pipe (argv, &fd); > free (vgname); > @@ -1376,10 +1377,19 @@ pull_lvm_by_command (const char *os_dev) > while (getline (&buf, &len, mdadm) > 0) > { > char *ptr; > - for (ptr = buf; ptr < buf + 2 && *ptr == ' '; ptr++); > + > + grub_util_info ("vgs returned PV: %s", buf); > + > + for (ptr = buf; *ptr == ' '; ptr++); > if (*ptr == '\0') > continue; > - *(ptr + strlen (ptr) - 1) = '\0'; > + if (strncmp (buf, "LVM2_PV_NAME='", sizeof ("LVM2_PV_NAME='") - 1)) > + continue; > + ptr = buf + sizeof ("LVM2_PV_NAME='") - 1; > + if (*(buf + len - 1) != '\'') > + continue; > + *(buf + len - 1) = '\0'; > + /* FIXME can PV name contain "'"? */ > grub_util_pull_device (ptr); > } > >