In the init initialization process, how does one initialize the device? To understand this, you need to carefully analyze the following code:
#001 int device_init (void)
#002 {
#003 suseconds_t t0, t1;
#004 int fd;
#005
#006 fd = open_uevent_socket ();
#007 if (fd <0)
#008 return-1;
This Code calls the open_uevent_socket function to create a socket for the user's event space.
#009
#010 fcntl (fd, F_SETFD, FD_CLOEXEC );
#011 fcntl (fd, F_SETFL, O_NONBLOCK );
This Code sets the socket attribute. FD_CLOEXEC is used to set the close-on-exec Status standard of the file. When the close-on-exec flag is 0 after exec () is called, this file is not closed. If it is not zero, it is disabled after exec. The default close-on-exec Status is 0 and needs to be set through FD_CLOEXEC. O_NONBLOCK sets this socket as an asynchronous communication method.
#012
#013 t0 = get_usecs ();
This line of code is used to obtain the time of the current user.
#014 coldboot (fd, "/sys/class ");
#015 coldboot (fd, "/sys/block ");
#016 coldboot (fd, "/sys/devices ");
This code is used to traverse all the devices that have been created before the init process and find the device Event file to send event notifications.
#017 t1 = get_usecs ();
This line of code is used to obtain the time of the current user.
#018
#019 log_event_print ("coldboot % ld uS", (long) (t1-t0 )));
This line of code is used to print the number of seconds of the output cold start.
#020
#021 return fd;
#022}
#023