diff options
author | Kay Sievers <kay.sievers@suse.de> | 2006-02-15 20:43:28 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2006-02-15 20:43:28 +0100 |
commit | 656ba91ee111308b53938b0f518ccbfadada9aa0 (patch) | |
tree | 7a6ebcafea07ac58c9ac0894ccb8cd1aa0ce0db1 /udev_rules.c | |
parent | 42878445d73b19096e068e50a0ab86c9fa047c63 (diff) |
exit WAIT_FOR_SYSFS if the whole device goes away
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Diffstat (limited to 'udev_rules.c')
-rw-r--r-- | udev_rules.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/udev_rules.c b/udev_rules.c index e9b32df1c6..9fa2253e96 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; } |