Re: [PATCH 3/3] Improve parsing and pass the devel flag to loader through the command line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/14/2010 07:36 AM, Martin Sivak wrote:
> This gets rid of ugly checking for this in /proc/cmdline in loader and init checks if devel is actually a single word to avoid conflicts
> ---
>  loader/init.c   |   36 +++++++++++++++++++++++++++++++++---
>  loader/loader.c |   28 +++++++++++++---------------
>  2 files changed, 46 insertions(+), 18 deletions(-)
> 
> diff --git a/loader/init.c b/loader/init.c
> index d824390..cdba95e 100644
> --- a/loader/init.c
> +++ b/loader/init.c
> @@ -494,11 +494,37 @@ int main(int argc, char **argv) {
>      /* check for development mode early */
>      int fdn;
>      if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {
> +
> +        /* get cmdline info */
>          int len = read(fdn, buf, sizeof(buf) - 1);
> +        char *develstart;
>          close(fdn);
> -        if (len > 0 && strstr(buf, "devel")) {
> -            printf("Enabling development mode - cores will be dumped\n");
> -            isDevelMode = 1;
> +
> +        /* check the arguments */
> +        if (len > 0) {
> +            develstart = buf;
> +            while (develstart && (*develstart) != '\0') {
> +                
> +                /* strip spaces */
> +		while(*develstart == ' ') develstart++;
> +		if(*develstart == '\0') break;
> +                
> +                /* not the word we are looking for */
> +                if (strncmp(develstart, "devel", 5)) {
> +                    develstart = strchr(develstart, ' ');
> +                    continue;
> +		}
> +                
> +                /* is it isolated? */
> +                if(((*(develstart+5)) == ' ' || (*(develstart+5)) == '\0')) {
> +                    printf("Enabling development mode - cores will be dumped\n");
> +                    isDevelMode++;
> +                    break;
> +                }
> +                
> +                /* Find next argument */
> +                develstart = strchr(develstart, ' ');
> +            }
>          }
>      }


I think you could simplify this by using strstr(develstart, " devel"),
that would eliminate the need to strip spaces and do a strncmp on every
word of the command line.

devel is always going to have a space in front of it, so you only have
to confirm that it is a single word.

Also, it looks like there may be some tabs mixed in there.

- -- 
Brian C. Lane <bcl@xxxxxxxxxx>
Red Hat / Port Orchard, WA
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEVAwUBTD3tqxF+jBaO/jp/AQJVKgf/XvYEj8twmZfd6cnRR2B9i3C5k/6BQnzm
i0ffokv7jcxpkJ8X6C6wmIZQELyB/TJB2uyTou5auzbMgjnEwHDnIIBI1RG1b7+L
EcZIom3BDhWBNhrTaqzqDezlkyzP1QrgvV3gSRAqFPGmq3qs1baIXf4ZuCXodEp6
7xjJ7QpbuIRlfS4X5EkkTXEGZ9By9CNGw3tq+Sdv+KzlC05sWC1roVFxJFXLg+jm
w13947VHL7mbM6YMN4MI4BEgzX2V38dOn38/aFJFH4Hb4agWZNXyPxXrLYggN0FO
oP72ptbv8cRb3D5ugvoIpuT/+caeoTlXeIdqC1EJhlY2oGhDqoe0mw==
=Vdp8
-----END PGP SIGNATURE-----

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux