commit df403c19cc5f4c61dcd10dbc4530051755b56172
parent 23f3fb721b6ad37fff484ffd859596c7f9c77c5b
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 7 Apr 2014 17:36:56 +0200
smdev: use basename of device for making a path
in parsepath() use basename of device (basedevname) to avoid paths like /dev/dri/dri/card0 when for a rule "dri/.*", "=dri"
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
Diffstat:
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/smdev.c b/smdev.c
@@ -166,11 +166,14 @@ static void
parsepath(struct rule *rule, struct rulepath *rpath,
const char *devname)
{
- char buf[PATH_MAX], *path;
- char *dirc;
+ char buf[PATH_MAX], *path, *dirc;
+ const char *basedevname;
+
+ if(!(basedevname = strrchr(devname, '/')))
+ basedevname = devname;
if (!rule->path) {
- strlcpy(rpath->name, devname, sizeof(rpath->name));
+ strlcpy(rpath->name, basedevname, sizeof(rpath->name));
snprintf(rpath->path, sizeof(rpath->path), "/dev/%s",
rpath->name);
return;
@@ -186,8 +189,8 @@ parsepath(struct rule *rule, struct rulepath *rpath,
/* No need to rename the device node */
if (rule->path[strlen(rule->path) - 1] == '/') {
snprintf(rpath->path, sizeof(rpath->path), "/dev/%s%s",
- path, devname);
- strlcpy(rpath->name, devname, sizeof(rpath->name));
+ path, basedevname);
+ strlcpy(rpath->name, basedevname, sizeof(rpath->name));
free(path);
return;
}