===== wait_for_sysfs.c 1.20 vs edited ===== --- 1.20/wait_for_sysfs.c 2004-10-15 23:54:11 +02:00 +++ edited/wait_for_sysfs.c 2004-10-16 04:36:42 +02:00 @@ -56,7 +56,8 @@ #define WAIT_LOOP_PER_SECOND 20 /* wait for specific file to show up, normally the "dev"-file */ -static int wait_for_class_device_attributes(struct sysfs_class_device *class_dev) +static int wait_for_class_device_attributes(struct sysfs_class_device *class_dev, + const char **error) { static struct class_file { char *subsystem; @@ -103,7 +104,8 @@ struct stat stats; if (stat(class_dev->path, &stats) == -1) { - dbg("oops, the directory '%s' just disappeared.", class_dev->path); + dbg("we've opened the device '%s' but now it disappeared", class_dev->path); + *error = "device directory unavailable"; return -ENODEV; } @@ -116,6 +118,7 @@ } dbg("error: getting class '%s' specific file '%s'", class_dev->classname, file); + *error = "class specific file unavailable"; return -ENOENT; } @@ -226,7 +229,8 @@ } /* wait for the bus and for a bus specific file to show up */ -static int wait_for_bus_device(struct sysfs_device *device_dev) +static int wait_for_bus_device(struct sysfs_device *device_dev, + const char **error) { static struct bus_file { char *bus; @@ -256,6 +260,7 @@ } if (loop == 0) { dbg("error: getting /bus-device link"); + *error = "no /bus-device link"; return -1; } dbg("/bus-device link found for bus '%s'", device_dev->bus); @@ -276,6 +281,7 @@ } } if (found == 0) { + *error = "unknown bus"; info("error: unknown bus, please report to " " '%s'", device_dev->bus); return -1; @@ -284,6 +290,7 @@ } dbg("error: getting bus '%s' specific file '%s'", device_dev->bus, busfile->file); + *error = "bus specific file unavailable"; return -1; } @@ -299,7 +306,7 @@ struct sysfs_device *device_dev = NULL; int loop; int retval; - int rc = 0; + const char *error = NULL; init_logging("wait_for_sysfs"); @@ -345,22 +352,19 @@ } if (class_dev == NULL) { dbg("error: getting class_device"); - rc = 3; + error = "device unavailable"; goto exit; } dbg("class_device opened '%s'", filename); - retval = wait_for_class_device_attributes(class_dev); - if (retval == -ENODEV) + retval = wait_for_class_device_attributes(class_dev, &error); + if (retval != 0) goto exit_class; - if (retval != 0) { - rc = 4; - goto exit_class; - } /* skip devices without /device-link */ if (class_device_expect_no_device_link(class_dev)) { dbg("no device symlink expected for '%s', ", class_dev->name); + error = "no device symlink"; goto exit_class; } @@ -384,8 +388,7 @@ usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND); } if (device_dev == NULL) { - dbg("error: getting /device-device"); - rc = 5; + error = "error: /device-device symlink"; goto exit_class; } dbg("device symlink found pointing to '%s'", device_dev->path); @@ -394,8 +397,7 @@ if (class_device_expect_no_bus(class_dev)) { dbg("no bus device expected for '%s', ", class_dev->classname); } else { - if (wait_for_bus_device(device_dev) != 0) - rc = 6; + wait_for_bus_device(device_dev, &error); } exit_class: @@ -415,15 +417,13 @@ usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND); } if (device_dev == NULL) { - dbg("error: getting /device-device"); - rc = 7; + error = "error: opening /device-device"; goto exit; } dbg("device_device opened '%s'", filename); /* wait for the bus value */ - if (wait_for_bus_device(device_dev) != 0) - rc = 8; + wait_for_bus_device(device_dev, &error); sysfs_close_device(device_dev); @@ -432,13 +432,13 @@ } exit: - if (rc == 0) + if (error == NULL) dbg("result: waiting for sysfs successful '%s'", devpath); else info("either wait_for_sysfs (udev %s) needs an update to handle the device '%s' " - "properly (%d) or the sysfs-support of your device's driver needs to be fixed, " + "properly (%s) or the sysfs-support of your device's driver needs to be fixed, " "please report to ", - UDEV_VERSION, devpath, rc); + UDEV_VERSION, devpath, error); - return rc; + return 3; }