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: Sandeep Patil <sspatil@google.com>
This commit is contained in:
Sandeep Patil 2017-02-15 13:37:52 -08:00
parent 56f9ada93d
commit 971a460c5b

View file

@ -999,15 +999,20 @@ static coldboot_action_t coldboot(const char *path, coldboot_callback fn)
}
void device_init(const char* path, coldboot_callback fn) {
sehandle = selinux_android_file_context_handle();
selinux_status_open(true);
/* is 256K enough? udev uses 16MB! */
device_fd.reset(uevent_open_socket(256*1024, true));
if (device_fd == -1) {
return;
if (!sehandle) {
sehandle = selinux_android_file_context_handle();
}
// 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);
}
fcntl(device_fd, F_SETFL, O_NONBLOCK);
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() {