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

Commit 971a460c authored by Sandeep Patil's avatar Sandeep Patil
Browse files

init: refactor to allow successive device_init calls



device_init opens the uevent socket and sehandle when called.
For early_mount however, depending on the fs_mgr flags we may call this
in order to run coldboot for device mapper, dm-verity devices etc.
So the change makes sure we don't try to re-open the uevent socket,
file context handle and selinux status on successive calls to
device_init from within the same process.

b/27805372

Test: Boot saifish successfully

Change-Id: Ifa0e665403211684183efb9be66e4e8d0d86a206
Signed-off-by: default avatarSandeep Patil <sspatil@google.com>
parent 56f9ada9
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -999,15 +999,20 @@ static coldboot_action_t coldboot(const char *path, coldboot_callback fn)
}

void device_init(const char* path, coldboot_callback fn) {
    if (!sehandle) {
        sehandle = selinux_android_file_context_handle();
    selinux_status_open(true);

    }
    // open uevent socket and selinux status only if it hasn't been
    // done before
    if (device_fd == -1) {
        /* is 256K enough? udev uses 16MB! */
        device_fd.reset(uevent_open_socket(256 * 1024, true));
        if (device_fd == -1) {
            return;
        }
        fcntl(device_fd, F_SETFL, O_NONBLOCK);
        selinux_status_open(true);
    }

    if (access(COLDBOOT_DONE, F_OK) == 0) {
        LOG(VERBOSE) << "Skipping coldboot, already done!";
@@ -1040,6 +1045,7 @@ void device_init(const char* path, coldboot_callback fn) {
void device_close() {
    destroy_platform_devices();
    device_fd.reset();
    selinux_status_close();
}

int get_device_fd() {