From 966f66517070731a3a67be6e73f22a73768b6e34 Mon Sep 17 00:00:00 2001 From: David Ng Date: Fri, 21 Nov 2014 18:01:08 -0800 Subject: ueventd: Fix bootdevice by-name/by-num link creation Create bootdevice by-name/by-num links only if the block device is the bootdevice. This fixes the issue of bootdevice path being created incorrectly if the first reported device with by-name/by-num is not the bootdevice. It also fixes devices in which the bootdevice property doesn't exist, or the symlink is created by a later step in the init sequence (such as init.rc itself) Change-Id: Ifb68080e3149917f9ee88a4a421007f29e8d83d2 --- init/devices.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/init/devices.cpp b/init/devices.cpp index d8de450..bb54cca 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -505,6 +505,7 @@ static char **get_block_device_symlinks(struct uevent *uevent) char link_path[256]; int link_num = 0; char *p; + int is_bootdevice = -1; int mtd_fd = -1; int nr; char mtd_name_path[256]; @@ -556,6 +557,13 @@ static char **get_block_device_symlinks(struct uevent *uevent) free(p); } + if (pdev && boot_device[0] != '\0' && strstr(device, boot_device)) { + make_link_init(link_path, "/dev/block/bootdevice"); + is_bootdevice = 1; + } else { + is_bootdevice = 0; + } + if (uevent->partition_name) { p = strdup(uevent->partition_name); sanitize(p); @@ -565,11 +573,13 @@ static char **get_block_device_symlinks(struct uevent *uevent) link_num++; else links[link_num] = NULL; - if (asprintf(&links[link_num], "/dev/block/bootdevice/by-name/%s", p) > 0) - link_num++; - else - links[link_num] = NULL; + if (is_bootdevice > 0) { + if (asprintf(&links[link_num], "/dev/block/bootdevice/by-name/%s", p) > 0) + link_num++; + else + links[link_num] = NULL; + } free(p); } @@ -579,10 +589,12 @@ static char **get_block_device_symlinks(struct uevent *uevent) else links[link_num] = NULL; - if (asprintf(&links[link_num], "/dev/block/bootdevice/by-num/p%d", uevent->partition_num) > 0) - link_num++; - else - links[link_num] = NULL; + if (is_bootdevice > 0) { + if (asprintf(&links[link_num], "/dev/block/bootdevice/by-num/p%d", uevent->partition_num) > 0) + link_num++; + else + links[link_num] = NULL; + } } slash = strrchr(uevent->path, '/'); @@ -591,11 +603,6 @@ static char **get_block_device_symlinks(struct uevent *uevent) else links[link_num] = NULL; - if (pdev && boot_device[0] != '\0' && strstr(device, boot_device)) { - /* Create bootdevice symlink for platform boot stroage device */ - make_link_init(link_path, "/dev/block/bootdevice"); - } - return links; } -- cgit v1.1