Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d89b1977 authored by David Ng's avatar David Ng Committed by Steve Kondik
Browse files

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.

Change-Id: Ifb68080e3149917f9ee88a4a421007f29e8d83d2
parent e419108a
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -585,6 +585,7 @@ static char **get_block_device_symlinks(struct uevent *uevent)
    int ret;
    char *p;
    unsigned int size;
    int is_bootdevice = 0;
    struct stat info;
    int mtd_fd = -1;
    int nr;
@@ -637,6 +638,11 @@ static char **get_block_device_symlinks(struct uevent *uevent)
        free(p);
    }

    if (bootdevice[0] != '\0' && !strncmp(device, bootdevice, sizeof(bootdevice))) {
        make_link(link_path, "/dev/block/bootdevice");
        is_bootdevice = 1;
    }

    if (uevent->partition_name) {
        p = strdup(uevent->partition_name);
        sanitize(p);
@@ -646,11 +652,13 @@ static char **get_block_device_symlinks(struct uevent *uevent)
            link_num++;
        else
            links[link_num] = NULL;

        if (is_bootdevice) {
            if (asprintf(&links[link_num], "/dev/block/bootdevice/by-name/%s", p) > 0)
                link_num++;
            else
                links[link_num] = NULL;

        }
        free(p);
    }

@@ -660,11 +668,13 @@ static char **get_block_device_symlinks(struct uevent *uevent)
        else
            links[link_num] = NULL;

        if (is_bootdevice) {
            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, '/');
    if (asprintf(&links[link_num], "%s/%s", link_path, slash + 1) > 0)
@@ -672,10 +682,6 @@ static char **get_block_device_symlinks(struct uevent *uevent)
    else
        links[link_num] = NULL;

    if (!strncmp(device, bootdevice, sizeof(bootdevice))) {
        make_link(link_path, "/dev/block/bootdevice");
    }

    return links;
}