Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Coldboot walks parts of the /sys tree and pokes the uevent files
- ** to cause the kernel to regenerate device add events that happened
- ** before init's device manager was started
- **
- ** We drain any pending events from the netlink socket every time
- ** we poke another uevent file to make sure we don't overrun the
- ** socket's buffer.
- */
- static void do_coldboot(DIR *d)
- {
- struct dirent *de;
- int dfd, fd;
- dfd = dirfd(d);
- fd = openat(dfd, "uevent", O_WRONLY);
- if(fd >= 0) {
- write(fd, "add\n", 4);
- close(fd);
- handle_device_fd();
- }
- while((de = readdir(d))) {
- DIR *d2;
- if(de->d_type != DT_DIR || de->d_name[0] == '.')
- continue;
- fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
- if(fd < 0)
- continue;
- d2 = fdopendir(fd);
- if(d2 == 0)
- close(fd);
- else {
- do_coldboot(d2);
- closedir(d2);
- }
- }
- }
- static void coldboot(const char *path)
- {
- DIR *d = opendir(path);
- if(d) {
- do_coldboot(d);
- closedir(d);
- }
- }
- void device_init(void)
- {
- suseconds_t t0, t1;
- struct stat info;
- int fd;
- sehandle = NULL;
- if (is_selinux_enabled() > 0) {
- sehandle = selinux_android_file_context_handle();
- selinux_status_open(true);
- }
- /* is 256K enough? udev uses 16MB! */
- device_fd = uevent_open_socket(256*1024, true);
- if(device_fd < 0)
- return;
- fcntl(device_fd, F_SETFD, FD_CLOEXEC);
- fcntl(device_fd, F_SETFL, O_NONBLOCK);
- if (stat(coldboot_done, &info) < 0) {
- t0 = get_usecs();
- coldboot("/sys/class");
- coldboot("/sys/block");
- coldboot("/sys/devices");
- t1 = get_usecs();
- fd = open(coldboot_done, O_WRONLY|O_CREAT, 0000);
- close(fd);
- log_event_print("coldboot %ld uS\n", ((long) (t1 - t0)));
- } else {
- log_event_print("skipping coldboot, already done\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement