summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Wilson <msw@redhat.com>2002-09-26 18:00:05 +0000
committerMatt Wilson <msw@redhat.com>2002-09-26 18:00:05 +0000
commitbf19859e4857e979d4f6dfb12caf551968c520eb (patch)
treebfe310960e343fc7b8f1fd8f4464d1b6f6b5929c
parentc98ee7cde32d1f78795f848a3c080f1b42ba5903 (diff)
downloadanaconda-bf19859e4857e979d4f6dfb12caf551968c520eb.tar.gz
anaconda-bf19859e4857e979d4f6dfb12caf551968c520eb.tar.xz
anaconda-bf19859e4857e979d4f6dfb12caf551968c520eb.zip
wait for USB to become stable before inserting usb-storage driver
-rw-r--r--loader/loader.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/loader/loader.c b/loader/loader.c
index 7c20fd746..0a05ea68a 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -3092,6 +3092,32 @@ void setFloppyDevice(int flags) {
logMessage("system floppy device is %s", floppyDevice);
}
+
+static void sleepUntilUsbIsStable(void) {
+ struct stat sb;
+ time_t last = 0;
+ int i, count = 0;
+
+ /* sleep for a maximum of 20 seconds, minimum of 2 seconds */
+ logMessage("waiting for usb to become stable...");
+ for (i = 0; i < 20; i++) {
+ stat("/proc/bus/usb/devices", &sb);
+ if (last == sb.st_mtime) {
+ count++;
+ /* if we get the same mtime twice in a row, should be
+ good enough to use now */
+ if (count > 1)
+ break;
+ } else {
+ /* if we didn't match mtimes, reset the stability counter */
+ count = 0;
+ }
+ last = sb.st_mtime;
+ sleep(1);
+ }
+ logMessage("%d seconds.", i);
+}
+
static int usbInitialize(moduleList modLoaded, moduleDeps modDeps,
moduleInfoSet modInfo, int flags) {
struct device ** devices;
@@ -3124,8 +3150,10 @@ static int usbInitialize(moduleList modLoaded, moduleDeps modDeps,
NULL, NULL))
logMessage("failed to mount device usbdevfs: %s", strerror(errno));
- /* sleep so we make sure usb devices get properly initialized */
- sleep(2);
+ /* sleep so we make sure usb devices get properly enumerated.
+ that way we should block when initializing each usb driver until
+ the device is ready for use */
+ sleepUntilUsbIsStable();
buf = alloca(40);
sprintf(buf, "hid:keybdev%s",