init: Move device_fd to devices.c
Change-Id: I11ed0f3e1b95d2cff4fdbd80b915c01572f76b0e
diff --git a/init/devices.c b/init/devices.c
index bde906b..a9ed141 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -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 @@
}
#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 @@
** 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 @@
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 @@
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;
}
diff --git a/init/devices.h b/init/devices.h
index b484da4..e14f4c8 100644
--- a/init/devices.h
+++ b/init/devices.h
@@ -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 */
diff --git a/init/init.c b/init/init.c
index 03656e9..4e1accf 100755
--- a/init/init.c
+++ b/init/init.c
@@ -698,7 +698,7 @@
drain_action_queue();
INFO("device init\n");
- device_fd = device_init();
+ device_init();
property_init();
@@ -784,7 +784,7 @@
}
/* 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 @@
/* 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 @@
}
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);