First, thank you for the response.

On Jun 24, 2010, at 3:11 AM, Jim Meyering wrote:
> You might want to try "udevadm settle" (aka the deprecated udevsettle 
> command).

I don't think busybox's mdev has such a command. I think the problem is in the 
kernel, though, so the settle command probably wouldn't work. I'll explain 
below.

> At worst, do something like I've done in parted's tests:
> poll with a subsecond interval, checking for the existence
> of a device file that you expect to be created.

I ended up doing exactly this. I sprinkled wait_for_partition() calls 
throughout my script in key places.

> Not everyone has a version of sleep that can handle
> a subsecond interval, so I wrote a portable shell function
> that degrades gracefully:

Wow, this is very similar to what I wrote. Some differences:

- I know that my device is a partition, so I read the first sector rather than 
ls.
- I had to move the sleep before the test, because parted + the test were both 
finishing before the kernel issued the device removal to mdev. I don't have 
this problem with an earlier kernel, but I want all of the updated drivers, etc.
- I'm going to add your sleep logic to my code just in case sub-second sleep 
ever becomes available. Although, I'm not sure how long I have to wait 
initially as a minimum value.

> 
> # Helper function: wait 2s (via .1s increments) for FILE to appear.
> # Usage: wait_for_dev_to_appear_ /dev/sdg
> # Return 0 upon success, 1 upon failure.
> wait_for_dev_to_appear_()
> {
>  local file=$1
>  local i=0
>  local incr=1
>  while :; do
>    ls "$file" > /dev/null 2>&1 && return 0
>    sleep .1 2>/dev/null || { sleep 1; incr=10; }
>    i=$(expr $i + $incr); test $i = 20 && break
>  done
>  return 1
> }


_______________________________________________
bug-parted mailing list
bug-parted@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-parted

Reply via email to