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

 



2013/5/22 Nico Golde <nico@xxxxxxxxx>:
> Hi,
> I'm not sure if you would like to change this....
> In devices.c you scan for the device name in /proc/devices using the %as
> string.
> On bionic this doesn't seem to work and therefore no devices are found and
> because of this no ioctl group ever matches.

No objections to changing this.

> I changed the code the following way:
> @@ -21,7 +22,8 @@ static size_t bldevs, chrdevs, miscdevs;
>  static void parse_proc_devices(void)
>  {
>         FILE *fp;
> -       char *name, *line = NULL;
> +       char *line = NULL;
> +       char name[32];

It would be IMO preferable to not hardcode the max length.

>         size_t n = 0;
>         int block, major;
>         void *new;
> @@ -33,30 +35,31 @@ static void parse_proc_devices(void)
>         block = 0;
>
>         while (getline(&line, &n, fp) >= 0) {
> +               memset(name, 0, sizeof(name));
>                 if (strcmp("Block devices:\n", line) == 0)
>                         block = 1;
> -               else if (sscanf(line, "%d %as", &major, &name) == 2) {
> +               else if (strcmp("Character devices:\n", line) == 0)
> +                       block = 0;
> +               else if (sscanf(line, "%d %s", &major, &name) == 2) {
>                         if (block) {
>                                 new = realloc(block_devs, (bldevs+1)*sizeof(*block_devs));
>                                 if (!new) {
> -                                       free(name);
>                                         continue;
>                                 }
>                                 block_devs = new;
>                                 block_devs[bldevs].major = major;
>                                 block_devs[bldevs].minor = 0;
> -                               block_devs[bldevs].name = name;
> +                               block_devs[bldevs].name = strdup(name);
>                                 bldevs++;
>                         } else {
>                                 new = realloc(char_devs, (chrdevs+1)*sizeof(*char_devs));
>                                 if (!new) {
> -                                       free(name);
>                                         continue;
>                                 }
>                                 char_devs = new;
>                                 char_devs[chrdevs].major = major;
>                                 char_devs[chrdevs].minor = 0;
> -                               char_devs[chrdevs].name = name;
> +                               char_devs[chrdevs].name = strdup(name);
>                                 chrdevs++;
>                         }
>                 }
>
>
> I also added the additional strcmp just to make sure that the code works also
> if the order of character devices/block devices in /proc/devices changes at
> some point.
>
> Cheers
> Nico
--
To unsubscribe from this list: send the line "unsubscribe trinity" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SCSI]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux