[systemd-devel] [PATCH v2] Bootchart: allow parse LABEL, UUID, PARTUUID for svg info

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Tue Oct 28 05:37:51 PDT 2014


On Tue, Oct 28, 2014 at 07:56:32AM +0300, Timofey Titovets wrote:
> Good time of day, list.
> I try to fix "Fixme" in svg.c:
> /* FIXME: this works only in the simple case */
> 
> By default function try to get only root=/dev/*
> 
> I also attach patch. Thanks.
> 
> v2:
> 	Rewrited with use fstab_node_to_udev_node() and
> canonicalize_file_name() functions.
There's infrastracture to do this properly: see
parse_proc_cmdline_item, e.g. in cryptsetup-generator.c.

Nevertheless, I'm wondering if this couldn't be done better by checking
what is mounted on /. Seems that it would work in more cases.

Zbyszek


> 
> From 4d14e78977df92e010ea488f97acd6a5e8e30e97 Mon Sep 17 00:00:00 2001
> From: Timofey Titovets <nefelim4ag at gmail.com>
> Date: Tue, 28 Oct 2014 07:42:26 +0300
> Subject: [PATCH] Bootchart: allow parse LABEL, UUID, PARTUUID for svg info
> 
> ---
>  src/bootchart/svg.c | 24 ++++++++++++++++++++----
>  1 file changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
> index faf377e..81d3da9 100644
> --- a/src/bootchart/svg.c
> +++ b/src/bootchart/svg.c
> @@ -151,6 +151,24 @@ static void svg_header(void) {
>          svg("    ]]>\n   </style>\n</defs>\n\n");
>  }
> 
> +static void get_root_disk(const char *cmdline, char *rootbdev) {
> +        char *ptr = strstr(cmdline, "root=");
> +
> +        if (!ptr)
> +                return;
> +
> +        ptr = &ptr[5];
> +        ptr = strtok(ptr," ");
> +
> +        if (ptr[0] != '/') {
> +                ptr = fstab_node_to_udev_node(ptr);
> +                ptr = canonicalize_file_name(ptr);
> +        }
> +
> +        strncpy(rootbdev, &ptr[5], 3);
> +        rootbdev[3] = '\0';
> +}
> +
>  static void svg_title(const char *build) {
>          char cmdline[256] = "";
>          char filename[PATH_MAX];
> @@ -175,11 +193,9 @@ static void svg_title(const char *build) {
>          }
> 
>          /* extract root fs so we can find disk model name in sysfs */
> -        /* FIXME: this works only in the simple case */
> -        c = strstr(cmdline, "root=/dev/");
> +        c = strstr(cmdline, "root=");
>          if (c) {
> -                strncpy(rootbdev, &c[10], 3);
> -                rootbdev[3] = '\0';
> +                get_root_disk(cmdline, rootbdev);
>                  sprintf(filename, "block/%s/device/model", rootbdev);
>                  fd = openat(sysfd, filename, O_RDONLY);
>                  f = fdopen(fd, "r");
> -- 
> 2.1.2
> 

> From 4d14e78977df92e010ea488f97acd6a5e8e30e97 Mon Sep 17 00:00:00 2001
> From: Timofey Titovets <nefelim4ag at gmail.com>
> Date: Tue, 28 Oct 2014 07:42:26 +0300
> Subject: [PATCH] Bootchart: allow parse LABEL, UUID, PARTUUID for svg info
> 
> ---
>  src/bootchart/svg.c | 24 ++++++++++++++++++++----
>  1 file changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
> index faf377e..81d3da9 100644
> --- a/src/bootchart/svg.c
> +++ b/src/bootchart/svg.c
> @@ -151,6 +151,24 @@ static void svg_header(void) {
>          svg("    ]]>\n   </style>\n</defs>\n\n");
>  }
>  
> +static void get_root_disk(const char *cmdline, char *rootbdev) {
> +        char *ptr = strstr(cmdline, "root=");
> +
> +        if (!ptr)
> +                return;
> +
> +        ptr = &ptr[5];
> +        ptr = strtok(ptr," ");
> +
> +        if (ptr[0] != '/') {
> +                ptr = fstab_node_to_udev_node(ptr);
> +                ptr = canonicalize_file_name(ptr);
> +        }
> +
> +        strncpy(rootbdev, &ptr[5], 3);
> +        rootbdev[3] = '\0';
> +}
> +
>  static void svg_title(const char *build) {
>          char cmdline[256] = "";
>          char filename[PATH_MAX];
> @@ -175,11 +193,9 @@ static void svg_title(const char *build) {
>          }
>  
>          /* extract root fs so we can find disk model name in sysfs */
> -        /* FIXME: this works only in the simple case */
> -        c = strstr(cmdline, "root=/dev/");
> +        c = strstr(cmdline, "root=");
>          if (c) {
> -                strncpy(rootbdev, &c[10], 3);
> -                rootbdev[3] = '\0';
> +                get_root_disk(cmdline, rootbdev);
>                  sprintf(filename, "block/%s/device/model", rootbdev);
>                  fd = openat(sysfd, filename, O_RDONLY);
>                  f = fdopen(fd, "r");
> -- 
> 2.1.2
> 

> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel



More information about the systemd-devel mailing list