Skip to content

Commit

Permalink
Merge "init: uevent: Add msm video symbolic link handling" into cm-10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio Cervera authored and Gerrit Code Review committed Sep 28, 2013
2 parents cb943b1 + 4188814 commit 1b96c7d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions init/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,41 @@ static void parse_event(const char *msg, struct uevent *uevent)
uevent->firmware, uevent->major, uevent->minor);
}

static char **get_v4l_device_symlinks(struct uevent *uevent)
{
char **links;
int fd = -1;
int nr;
char link_name_path[256];
char link_name[64];

if (strncmp(uevent->path, "/devices/virtual/video4linux/video", 34))
return NULL;

links = malloc(sizeof(char *) * 2);
if (!links)
return NULL;
memset(links, 0, sizeof(char *) * 2);

snprintf(link_name_path, sizeof(link_name_path), "%s%s%s",
SYSFS_PREFIX, uevent->path, "/link_name");
fd = open(link_name_path, O_RDONLY);
if (fd < 0)
goto err;
nr = read(fd, link_name, sizeof(link_name) - 1);
close(fd);
if (nr <= 0)
goto err;
link_name[nr] = '\0';
if (asprintf(&links[0], "/dev/video/%s", link_name) <= 0)
links[0] = NULL;

return links;
err:
free(links);
return NULL;
}

static char **get_character_device_symlinks(struct uevent *uevent)
{
const char *parent;
Expand Down Expand Up @@ -628,6 +663,8 @@ static void handle_generic_device_event(struct uevent *uevent)
} else
base = "/dev/";
links = get_character_device_symlinks(uevent);
if (!links)
links = get_v4l_device_symlinks(uevent);

if (!devpath[0])
snprintf(devpath, sizeof(devpath), "%s%s", base, name);
Expand Down

0 comments on commit 1b96c7d

Please sign in to comment.