===== 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 18:20:23 +02:00 @@ -56,7 +56,8 @@ void log_message(int level, const char * #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,11 +104,11 @@ static int wait_for_class_device_attribu struct stat stats; if (stat(class_dev->path, &stats) == -1) { - dbg("oops, the directory '%s' just disappeared.", class_dev->path); + dbg("'%s' now disappeared (probably remove has beaten us)", class_dev->path); return -ENODEV; } - if (stat(filename, &stats) == 0) { + if (stat(filename, &stats) == 0) { dbg("class '%s' specific file '%s' found", class_dev->classname, file); return 0; } @@ -116,6 +117,7 @@ static int wait_for_class_device_attribu } dbg("error: getting class '%s' specific file '%s'", class_dev->classname, file); + *error = "class specific file unavailable"; return -ENOENT; } @@ -226,7 +228,8 @@ static int class_device_expect_no_bus(st } /* 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; @@ -246,7 +249,7 @@ static int wait_for_bus_device(struct sy struct bus_file *busfile; int loop; - /* wait for the /bus-device link to the /device-device */ + /* wait for the /bus-device link to the /devices-device */ loop = WAIT_MAX_SECONDS * WAIT_LOOP_PER_SECOND; while (--loop) { if (sysfs_get_device_bus(device_dev) == 0) @@ -256,6 +259,7 @@ static int wait_for_bus_device(struct sy } 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 +280,7 @@ static int wait_for_bus_device(struct sy } } if (found == 0) { + *error = "unknown bus"; info("error: unknown bus, please report to " " '%s'", device_dev->bus); return -1; @@ -284,6 +289,7 @@ static int wait_for_bus_device(struct sy } dbg("error: getting bus '%s' specific file '%s'", device_dev->bus, busfile->file); + *error = "bus specific file unavailable"; return -1; } @@ -298,8 +304,7 @@ int main(int argc, char *argv[], char *e struct sysfs_class_device *class_dev_parent; struct sysfs_device *device_dev = NULL; int loop; - int retval; - int rc = 0; + const char *error = NULL; init_logging("wait_for_sysfs"); @@ -344,21 +349,15 @@ int main(int argc, char *argv[], char *e usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND); } if (class_dev == NULL) { - dbg("error: getting class_device"); - rc = 3; + dbg("error: class_device unavailable (probably remove has beaten us)"); goto exit; } dbg("class_device opened '%s'", filename); - retval = wait_for_class_device_attributes(class_dev); - if (retval == -ENODEV) + if (wait_for_class_device_attributes(class_dev, &error) != 0) goto exit_class; - if (retval != 0) { - rc = 4; - goto exit_class; - } - /* skip devices without /device-link */ + /* skip devices without devices-link */ if (class_device_expect_no_device_link(class_dev)) { dbg("no device symlink expected for '%s', ", class_dev->name); goto exit_class; @@ -369,8 +368,8 @@ int main(int argc, char *argv[], char *e if (class_dev_parent) dbg("looking at parent device for device link '%s'", class_dev_parent->path); - /* wait for the symlink to the /device-device */ - dbg("waiting for symlink to /device-device"); + /* wait for the symlink to the devices-device */ + dbg("waiting for symlink to devices-device"); loop = WAIT_MAX_SECONDS * WAIT_LOOP_PER_SECOND; while (--loop) { if (class_dev_parent) @@ -384,19 +383,17 @@ int main(int argc, char *argv[], char *e usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND); } if (device_dev == NULL) { - dbg("error: getting /device-device"); - rc = 5; + dbg(" error: no devices-device symlink found"); + error = "no device symlink"; goto exit_class; } dbg("device symlink found pointing to '%s'", device_dev->path); /* wait for the bus value */ - if (class_device_expect_no_bus(class_dev)) { + 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; - } + else + wait_for_bus_device(device_dev, &error); exit_class: sysfs_close_class_device(class_dev); @@ -415,15 +412,13 @@ exit_class: usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND); } if (device_dev == NULL) { - dbg("error: getting /device-device"); - rc = 7; + error = "devices-device unavailable"; goto exit; } - dbg("device_device opened '%s'", filename); + dbg("devices-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 +427,13 @@ exit_class: } 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; }