All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH] fix parsing of LVM PV names for short names
Date: Wed, 14 Aug 2013 17:24:33 +0200	[thread overview]
Message-ID: <520BA131.5000308@gmail.com> (raw)
In-Reply-To: <1374919798-21531-1-git-send-email-arvidjaar@gmail.com>

Go ahead
On 27.07.2013 12:09, Andrey Borzenkov wrote:
> 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 <arvidjaar@gmail.com>
>
> ---
>   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;
>



  reply	other threads:[~2013-08-14 15:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-19  7:11 [PATCH] use vgs --nameprefixes to protect against whitespace changes Andrey Borzenkov
2013-07-27 10:09 ` [PATCH] fix parsing of LVM PV names for short names Andrey Borzenkov
2013-08-14 15:24   ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2013-08-14 16:16 ` [PATCH] use vgs --nameprefixes to protect against whitespace changes Vladimir 'φ-coder/phcoder' Serbinenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=520BA131.5000308@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.