public inbox for trinity@vger.kernel.org
 help / color / mirror / Atom feed
From: Nico Golde <nico@ngolde.de>
To: trinity@vger.kernel.org
Subject: Re: minor trinity patch
Date: Wed, 22 May 2013 16:14:59 +0200	[thread overview]
Message-ID: <20130522141458.GA18931@ngolde.de> (raw)
In-Reply-To: <20121220201903.GA14944@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2684 bytes --]

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.

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];
        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

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

       reply	other threads:[~2013-05-22 14:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20121220165100.GA8748@ngolde.de>
     [not found] ` <20121220171726.GA7543@redhat.com>
     [not found]   ` <20121220172246.GA16285@ngolde.de>
     [not found]     ` <20121220172741.GA17760@redhat.com>
     [not found]       ` <20121220200255.GB16285@ngolde.de>
     [not found]         ` <20121220201903.GA14944@redhat.com>
2013-05-22 14:14           ` Nico Golde [this message]
2013-05-23 18:58             ` minor trinity patch Tommi Rantala
2013-05-23 23:47               ` Nico Golde
2013-06-03  5:55                 ` Tommi Rantala
2013-06-21 13:20                   ` Nico Golde
2013-06-24 16:03                     ` Nico Golde

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=20130522141458.GA18931@ngolde.de \
    --to=nico@ngolde.de \
    --cc=trinity@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox