init: Move device_fd to devices.c

Change-Id: I11ed0f3e1b95d2cff4fdbd80b915c01572f76b0e
This commit is contained in:
Colin Cross 2010-04-13 19:25:51 -07:00
parent a866695ebe
commit 0dd7ca6e87
3 changed files with 30 additions and 26 deletions

View file

@ -40,6 +40,8 @@
#define FIRMWARE_DIR "/etc/firmware"
#define MAX_QEMU_PERM 6
static int device_fd = -1;
struct uevent {
const char *action;
const char *path;
@ -569,12 +571,12 @@ static void handle_firmware_event(struct uevent *uevent)
}
#define UEVENT_MSG_LEN 1024
void handle_device_fd(int fd)
void handle_device_fd()
{
char msg[UEVENT_MSG_LEN+2];
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;
if(n == UEVENT_MSG_LEN) /* overflow -- discard */
@ -599,7 +601,7 @@ void handle_device_fd(int fd)
** socket's buffer.
*/
static void do_coldboot(int event_fd, DIR *d)
static void do_coldboot(DIR *d)
{
struct dirent *de;
int dfd, fd;
@ -610,7 +612,7 @@ static void do_coldboot(int event_fd, DIR *d)
if(fd >= 0) {
write(fd, "add\n", 4);
close(fd);
handle_device_fd(event_fd);
handle_device_fd();
}
while((de = readdir(d))) {
@ -627,40 +629,42 @@ static void do_coldboot(int event_fd, DIR *d)
if(d2 == 0)
close(fd);
else {
do_coldboot(event_fd, d2);
do_coldboot(d2);
closedir(d2);
}
}
}
static void coldboot(int event_fd, const char *path)
static void coldboot(const char *path)
{
DIR *d = opendir(path);
if(d) {
do_coldboot(event_fd, d);
do_coldboot(d);
closedir(d);
}
}
int device_init(void)
void device_init(void)
{
suseconds_t t0, t1;
int fd;
fd = open_uevent_socket();
if(fd < 0)
return -1;
device_fd = open_uevent_socket();
if(device_fd < 0)
return;
fcntl(fd, F_SETFD, FD_CLOEXEC);
fcntl(fd, F_SETFL, O_NONBLOCK);
fcntl(device_fd, F_SETFD, FD_CLOEXEC);
fcntl(device_fd, F_SETFL, O_NONBLOCK);
t0 = get_usecs();
coldboot(fd, "/sys/class");
coldboot(fd, "/sys/block");
coldboot(fd, "/sys/devices");
coldboot("/sys/class");
coldboot("/sys/block");
coldboot("/sys/devices");
t1 = get_usecs();
log_event_print("coldboot %ld uS\n", ((long) (t1 - t0)));
return fd;
}
int get_device_fd()
{
return device_fd;
}

View file

@ -17,11 +17,11 @@
#ifndef _INIT_DEVICES_H
#define _INIT_DEVICES_H
extern void handle_device_fd(int fd);
extern int device_init(void);
extern void handle_device_fd();
extern void device_init(void);
extern void qemu_init(void);
extern void qemu_cmdline(const char* name, const char *value);
extern int add_devperms_partners(const char *name, mode_t perm, unsigned int uid,
unsigned int gid, unsigned short prefix);
int get_device_fd();
#endif /* _INIT_DEVICES_H */

View file

@ -698,7 +698,7 @@ int main(int argc, char **argv)
drain_action_queue();
INFO("device init\n");
device_fd = device_init();
device_init();
property_init();
@ -784,7 +784,7 @@ int main(int argc, char **argv)
}
/* make sure we actually have all the pieces we need */
if ((device_fd < 0) ||
if ((get_device_fd() < 0) ||
(property_set_fd < 0) ||
(signal_recv_fd < 0)) {
ERROR("init startup failure\n");
@ -803,7 +803,7 @@ int main(int argc, char **argv)
/* enable property triggers */
property_triggers_enabled = 1;
ufds[0].fd = device_fd;
ufds[0].fd = get_device_fd();
ufds[0].events = POLLIN;
ufds[1].fd = property_set_fd;
ufds[1].events = POLLIN;
@ -869,7 +869,7 @@ int main(int argc, char **argv)
}
if (ufds[0].revents == POLLIN)
handle_device_fd(device_fd);
handle_device_fd();
if (ufds[1].revents == POLLIN)
handle_property_set_fd(property_set_fd);