From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1V31mi-0006bk-TF for mharc-grub-devel@gnu.org; Sat, 27 Jul 2013 06:31:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V31mf-0006Al-FL for grub-devel@gnu.org; Sat, 27 Jul 2013 06:31:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V31Rz-0003WK-5t for grub-devel@gnu.org; Sat, 27 Jul 2013 06:10:12 -0400 Received: from mail-lb0-x235.google.com ([2a00:1450:4010:c04::235]:32936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V31Ry-0003WB-UB for grub-devel@gnu.org; Sat, 27 Jul 2013 06:10:11 -0400 Received: by mail-lb0-f181.google.com with SMTP id o10so1950540lbi.12 for ; Sat, 27 Jul 2013 03:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; bh=UY6OBVVezY3BPq9T8twl/3SGRhQCOBTD9zbHYd+p13U=; b=TDCR5xFuMubaqd/BmshMsfxuiZ/Z/RUA77PnQP3mtNkLB9lpK4Nt2/yjjYvEOyON0Q g4QsQDz6PDLZhBGFwqoWTK78qj3Db5cB4ZqvTpc1XLQWZ/XBBOsDnNz14kHcU/jDpC+6 YBvItG+2mSfyJWWWcTCf3E5OCsL2NAhLLDIFb+IM/YgfFn8pqIp4evSQknQgFSERbQv5 a2MHxsfRXgfzwoKi2Gx16rs/GAmkAYFBYvSKqEz+lUTF/VOU/t/2uOThxKOMfcF6Za97 gv8cM9+ghbaGsrkNJDN9BU8kcZEzFlHu2RAU5r0MwkQoPzV32o1WCk5aJ/QqPBHD21KC 7bAA== X-Received: by 10.112.132.98 with SMTP id ot2mr7901828lbb.15.1374919809771; Sat, 27 Jul 2013 03:10:09 -0700 (PDT) Received: from localhost.localdomain (ppp79-139-160-84.pppoe.spdop.ru. [79.139.160.84]) by mx.google.com with ESMTPSA id p20sm2408308lbb.17.2013.07.27.03.10.08 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 27 Jul 2013 03:10:09 -0700 (PDT) From: Andrey Borzenkov To: grub-devel@gnu.org Subject: [PATCH] fix parsing of LVM PV names for short names Date: Sat, 27 Jul 2013 14:09:58 +0400 Message-Id: <1374919798-21531-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1374217896-21412-1-git-send-email-arvidjaar@gmail.com> References: <1374217896-21412-1-git-send-email-arvidjaar@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::235 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: Sat, 27 Jul 2013 10:31:35 -0000 Default format of vgs output is - two spaces as standard prefix - PV name left aligned to field width which is 10 characters This means that if PV name has less than 10 chacaters it has some spaces at the end. Example: linux-chxo:~ # vgs -o pv_name --noheadings | cat -E /dev/md1 $ /dev/md101$ linux-chxo:~ # There is no explicit option to turn off alignment; it is implicitly disabled if one of --separator or --nameprefixes option is used. --separator was added in 2007, --nameprefixes - in 2009. So let's use --separator to extend range of versions we are compatible with. Note that one or another must be used, current parsing is broken otherwise. Signed-off-by: Andrey Borzenkov --- util/getroot.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/util/getroot.c b/util/getroot.c index 2ad8a55..3afcf96 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[8]; int fd; pid_t pid; FILE *mdadm; @@ -1351,12 +1351,17 @@ pull_lvm_by_command (const char *os_dev) /* execvp has inconvenient types, hence the casts. None of these strings will actually be modified. */ + /* by default PV name is left aligned in 10 character field, meaning that + we do not know where name ends. Using dummy --separator disables + alignment. We have a single field, so separator itself is not output */ argv[0] = (char *) "vgs"; argv[1] = (char *) "--options"; argv[2] = (char *) "pv_name"; argv[3] = (char *) "--noheadings"; - argv[4] = vgname; - argv[5] = NULL; + argv[4] = (char *) "--separator"; + argv[5] = (char *) ":"; + argv[6] = vgname; + argv[7] = NULL; pid = exec_pipe (argv, &fd); free (vgname); @@ -1376,6 +1381,7 @@ pull_lvm_by_command (const char *os_dev) while (getline (&buf, &len, mdadm) > 0) { char *ptr; + /* LVM adds two spaces as standard prefix */ for (ptr = buf; ptr < buf + 2 && *ptr == ' '; ptr++); if (*ptr == '\0') continue; -- tg: (ebd40b6..) u/strip-pv-trailing-blanks (depends on: master)