X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_rules.c;h=9fa2253e96e59afefc4bce2c73d733ec1583e34c;hp=8e9c1605bf8aeaf447a2c6eb101832c962cb3e05;hb=bee6e24fa94fced3a23115ca020f041ed9ed9143;hpb=9538b16d8b6086691dd01d76dea91ba73d13a630 diff --git a/udev_rules.c b/udev_rules.c index 8e9c1605b..9fa2253e9 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -342,23 +342,33 @@ out: #define WAIT_LOOP_PER_SECOND 50 static int wait_for_sysfs(struct udevice *udev, const char *file, int timeout) { - char filename[PATH_SIZE]; + char devicepath[PATH_SIZE]; + char filepath[PATH_SIZE]; struct stat stats; int loop = timeout * WAIT_LOOP_PER_SECOND; - snprintf(filename, sizeof(filename), "%s%s/%s", sysfs_path, udev->dev->devpath, file); - filename[sizeof(filename)-1] = '\0'; - dbg("will wait %i sec for '%s'", timeout, filename); + strlcpy(devicepath, sysfs_path, sizeof(devicepath)); + strlcat(devicepath, udev->dev->devpath, sizeof(devicepath)); + strlcpy(filepath, devicepath, sizeof(filepath)); + strlcat(filepath, "/", sizeof(filepath)); + strlcat(filepath, file, sizeof(filepath)); + dbg("will wait %i sec for '%s'", timeout, filepath); while (--loop) { - if (stat(filename, &stats) == 0) { - info("file '%s' appeared after %i loops", filename, (timeout * WAIT_LOOP_PER_SECOND) - loop-1); + /* lookup file */ + if (stat(filepath, &stats) == 0) { + info("file '%s' appeared after %i loops", filepath, (timeout * WAIT_LOOP_PER_SECOND) - loop-1); return 0; } - info("wait for '%s' for %i mseconds", filename, 1000 / WAIT_LOOP_PER_SECOND); + /* make sure the device does not have disappeared in the meantime */ + if (stat(devicepath, &stats) != 0) { + info("device disappeared while waiting for '%s'", filepath); + return -2; + } + info("wait for '%s' for %i mseconds", filepath, 1000 / WAIT_LOOP_PER_SECOND); usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND); } - err("waiting for '%s' failed", filename); + err("waiting for '%s' failed", filepath); return -1; } @@ -733,19 +743,13 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule) } if (rule->wait_for_sysfs.operation != KEY_OP_UNSET) { - int match; + int found; - match = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0); - if (match && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH)) { - dbg("WAIT_FOR_SYSFS is true (matching value)"); - return 0; - } - if (!match && (rule->wait_for_sysfs.operation == KEY_OP_NOMATCH)) { - dbg("WAIT_FOR_SYSFS is true, (non matching value)"); - return 0; + found = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0); + if (!found && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH)) { + dbg("WAIT_FOR_SYSFS failed"); + goto nomatch; } - dbg("WAIT_FOR_SYSFS is false"); - return -1; } /* walk up the chain of parent devices and find a match */