Loading init/devices.c +22 −18 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,8 @@ #define FIRMWARE_DIR "/etc/firmware" #define FIRMWARE_DIR "/etc/firmware" #define MAX_QEMU_PERM 6 #define MAX_QEMU_PERM 6 static int device_fd = -1; struct uevent { struct uevent { const char *action; const char *action; const char *path; const char *path; Loading Loading @@ -569,12 +571,12 @@ static void handle_firmware_event(struct uevent *uevent) } } #define UEVENT_MSG_LEN 1024 #define UEVENT_MSG_LEN 1024 void handle_device_fd(int fd) void handle_device_fd() { { char msg[UEVENT_MSG_LEN+2]; char msg[UEVENT_MSG_LEN+2]; int n; int n; while((n = recv(fd, msg, UEVENT_MSG_LEN, 0)) > 0) { while((n = recv(device_fd, msg, UEVENT_MSG_LEN, 0)) > 0) { struct uevent uevent; struct uevent uevent; if(n == UEVENT_MSG_LEN) /* overflow -- discard */ if(n == UEVENT_MSG_LEN) /* overflow -- discard */ Loading @@ -599,7 +601,7 @@ void handle_device_fd(int fd) ** socket's buffer. ** socket's buffer. */ */ static void do_coldboot(int event_fd, DIR *d) static void do_coldboot(DIR *d) { { struct dirent *de; struct dirent *de; int dfd, fd; int dfd, fd; Loading @@ -610,7 +612,7 @@ static void do_coldboot(int event_fd, DIR *d) if(fd >= 0) { if(fd >= 0) { write(fd, "add\n", 4); write(fd, "add\n", 4); close(fd); close(fd); handle_device_fd(event_fd); handle_device_fd(); } } while((de = readdir(d))) { while((de = readdir(d))) { Loading @@ -627,40 +629,42 @@ static void do_coldboot(int event_fd, DIR *d) if(d2 == 0) if(d2 == 0) close(fd); close(fd); else { else { do_coldboot(event_fd, d2); do_coldboot(d2); closedir(d2); closedir(d2); } } } } } } static void coldboot(int event_fd, const char *path) static void coldboot(const char *path) { { DIR *d = opendir(path); DIR *d = opendir(path); if(d) { if(d) { do_coldboot(event_fd, d); do_coldboot(d); closedir(d); closedir(d); } } } } int device_init(void) void device_init(void) { { suseconds_t t0, t1; suseconds_t t0, t1; int fd; fd = open_uevent_socket(); device_fd = open_uevent_socket(); if(fd < 0) if(device_fd < 0) return -1; return; fcntl(fd, F_SETFD, FD_CLOEXEC); fcntl(device_fd, F_SETFD, FD_CLOEXEC); fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(device_fd, F_SETFL, O_NONBLOCK); t0 = get_usecs(); t0 = get_usecs(); coldboot(fd, "/sys/class"); coldboot("/sys/class"); coldboot(fd, "/sys/block"); coldboot("/sys/block"); coldboot(fd, "/sys/devices"); coldboot("/sys/devices"); t1 = get_usecs(); t1 = get_usecs(); log_event_print("coldboot %ld uS\n", ((long) (t1 - t0))); log_event_print("coldboot %ld uS\n", ((long) (t1 - t0))); } return fd; int get_device_fd() { return device_fd; } } init/devices.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -17,11 +17,11 @@ #ifndef _INIT_DEVICES_H #ifndef _INIT_DEVICES_H #define _INIT_DEVICES_H #define _INIT_DEVICES_H extern void handle_device_fd(int fd); extern void handle_device_fd(); extern int device_init(void); extern void device_init(void); extern void qemu_init(void); extern void qemu_init(void); extern void qemu_cmdline(const char* name, const char *value); extern void qemu_cmdline(const char* name, const char *value); extern int add_devperms_partners(const char *name, mode_t perm, unsigned int uid, extern int add_devperms_partners(const char *name, mode_t perm, unsigned int uid, unsigned int gid, unsigned short prefix); unsigned int gid, unsigned short prefix); int get_device_fd(); #endif /* _INIT_DEVICES_H */ #endif /* _INIT_DEVICES_H */ init/init.c +4 −4 Original line number Original line Diff line number Diff line Loading @@ -698,7 +698,7 @@ int main(int argc, char **argv) drain_action_queue(); drain_action_queue(); INFO("device init\n"); INFO("device init\n"); device_fd = device_init(); device_init(); property_init(); property_init(); Loading Loading @@ -784,7 +784,7 @@ int main(int argc, char **argv) } } /* make sure we actually have all the pieces we need */ /* make sure we actually have all the pieces we need */ if ((device_fd < 0) || if ((get_device_fd() < 0) || (property_set_fd < 0) || (property_set_fd < 0) || (signal_recv_fd < 0)) { (signal_recv_fd < 0)) { ERROR("init startup failure\n"); ERROR("init startup failure\n"); Loading @@ -803,7 +803,7 @@ int main(int argc, char **argv) /* enable property triggers */ /* enable property triggers */ property_triggers_enabled = 1; property_triggers_enabled = 1; ufds[0].fd = device_fd; ufds[0].fd = get_device_fd(); ufds[0].events = POLLIN; ufds[0].events = POLLIN; ufds[1].fd = property_set_fd; ufds[1].fd = property_set_fd; ufds[1].events = POLLIN; ufds[1].events = POLLIN; Loading Loading @@ -869,7 +869,7 @@ int main(int argc, char **argv) } } if (ufds[0].revents == POLLIN) if (ufds[0].revents == POLLIN) handle_device_fd(device_fd); handle_device_fd(); if (ufds[1].revents == POLLIN) if (ufds[1].revents == POLLIN) handle_property_set_fd(property_set_fd); handle_property_set_fd(property_set_fd); Loading Loading
init/devices.c +22 −18 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,8 @@ #define FIRMWARE_DIR "/etc/firmware" #define FIRMWARE_DIR "/etc/firmware" #define MAX_QEMU_PERM 6 #define MAX_QEMU_PERM 6 static int device_fd = -1; struct uevent { struct uevent { const char *action; const char *action; const char *path; const char *path; Loading Loading @@ -569,12 +571,12 @@ static void handle_firmware_event(struct uevent *uevent) } } #define UEVENT_MSG_LEN 1024 #define UEVENT_MSG_LEN 1024 void handle_device_fd(int fd) void handle_device_fd() { { char msg[UEVENT_MSG_LEN+2]; char msg[UEVENT_MSG_LEN+2]; int n; int n; while((n = recv(fd, msg, UEVENT_MSG_LEN, 0)) > 0) { while((n = recv(device_fd, msg, UEVENT_MSG_LEN, 0)) > 0) { struct uevent uevent; struct uevent uevent; if(n == UEVENT_MSG_LEN) /* overflow -- discard */ if(n == UEVENT_MSG_LEN) /* overflow -- discard */ Loading @@ -599,7 +601,7 @@ void handle_device_fd(int fd) ** socket's buffer. ** socket's buffer. */ */ static void do_coldboot(int event_fd, DIR *d) static void do_coldboot(DIR *d) { { struct dirent *de; struct dirent *de; int dfd, fd; int dfd, fd; Loading @@ -610,7 +612,7 @@ static void do_coldboot(int event_fd, DIR *d) if(fd >= 0) { if(fd >= 0) { write(fd, "add\n", 4); write(fd, "add\n", 4); close(fd); close(fd); handle_device_fd(event_fd); handle_device_fd(); } } while((de = readdir(d))) { while((de = readdir(d))) { Loading @@ -627,40 +629,42 @@ static void do_coldboot(int event_fd, DIR *d) if(d2 == 0) if(d2 == 0) close(fd); close(fd); else { else { do_coldboot(event_fd, d2); do_coldboot(d2); closedir(d2); closedir(d2); } } } } } } static void coldboot(int event_fd, const char *path) static void coldboot(const char *path) { { DIR *d = opendir(path); DIR *d = opendir(path); if(d) { if(d) { do_coldboot(event_fd, d); do_coldboot(d); closedir(d); closedir(d); } } } } int device_init(void) void device_init(void) { { suseconds_t t0, t1; suseconds_t t0, t1; int fd; fd = open_uevent_socket(); device_fd = open_uevent_socket(); if(fd < 0) if(device_fd < 0) return -1; return; fcntl(fd, F_SETFD, FD_CLOEXEC); fcntl(device_fd, F_SETFD, FD_CLOEXEC); fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(device_fd, F_SETFL, O_NONBLOCK); t0 = get_usecs(); t0 = get_usecs(); coldboot(fd, "/sys/class"); coldboot("/sys/class"); coldboot(fd, "/sys/block"); coldboot("/sys/block"); coldboot(fd, "/sys/devices"); coldboot("/sys/devices"); t1 = get_usecs(); t1 = get_usecs(); log_event_print("coldboot %ld uS\n", ((long) (t1 - t0))); log_event_print("coldboot %ld uS\n", ((long) (t1 - t0))); } return fd; int get_device_fd() { return device_fd; } }
init/devices.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -17,11 +17,11 @@ #ifndef _INIT_DEVICES_H #ifndef _INIT_DEVICES_H #define _INIT_DEVICES_H #define _INIT_DEVICES_H extern void handle_device_fd(int fd); extern void handle_device_fd(); extern int device_init(void); extern void device_init(void); extern void qemu_init(void); extern void qemu_init(void); extern void qemu_cmdline(const char* name, const char *value); extern void qemu_cmdline(const char* name, const char *value); extern int add_devperms_partners(const char *name, mode_t perm, unsigned int uid, extern int add_devperms_partners(const char *name, mode_t perm, unsigned int uid, unsigned int gid, unsigned short prefix); unsigned int gid, unsigned short prefix); int get_device_fd(); #endif /* _INIT_DEVICES_H */ #endif /* _INIT_DEVICES_H */
init/init.c +4 −4 Original line number Original line Diff line number Diff line Loading @@ -698,7 +698,7 @@ int main(int argc, char **argv) drain_action_queue(); drain_action_queue(); INFO("device init\n"); INFO("device init\n"); device_fd = device_init(); device_init(); property_init(); property_init(); Loading Loading @@ -784,7 +784,7 @@ int main(int argc, char **argv) } } /* make sure we actually have all the pieces we need */ /* make sure we actually have all the pieces we need */ if ((device_fd < 0) || if ((get_device_fd() < 0) || (property_set_fd < 0) || (property_set_fd < 0) || (signal_recv_fd < 0)) { (signal_recv_fd < 0)) { ERROR("init startup failure\n"); ERROR("init startup failure\n"); Loading @@ -803,7 +803,7 @@ int main(int argc, char **argv) /* enable property triggers */ /* enable property triggers */ property_triggers_enabled = 1; property_triggers_enabled = 1; ufds[0].fd = device_fd; ufds[0].fd = get_device_fd(); ufds[0].events = POLLIN; ufds[0].events = POLLIN; ufds[1].fd = property_set_fd; ufds[1].fd = property_set_fd; ufds[1].events = POLLIN; ufds[1].events = POLLIN; Loading Loading @@ -869,7 +869,7 @@ int main(int argc, char **argv) } } if (ufds[0].revents == POLLIN) if (ufds[0].revents == POLLIN) handle_device_fd(device_fd); handle_device_fd(); if (ufds[1].revents == POLLIN) if (ufds[1].revents == POLLIN) handle_property_set_fd(property_set_fd); handle_property_set_fd(property_set_fd); Loading