Skip to contentSkip to conversation

Problem about usleep function in tools/hotplug/Linux/xendomains.in

DISCUSSION Fabio Fantoni 2 participants 2 messages Mar 16, 2015

lore
Share & tools
lore
#0 lore raw

If usleep binary is missed in dom0 xendomains script use its function instead but as it is done now always rounds down to the nearest integer number, and in case it is less than 1 becomes 0. So for example in dom0 like those I use (debian) withoutusleep binaryall small usleep in the script are null.

A solution can be to replace:

Quoted 7 lines
  usleep()
  {
    if [ -n "$1" ]
    then
      sleep $(( $1 / 1000000 ))
    fi
  }

with:

Quoted 7 lines
  usleep()
  {
    if [ -n "$1" ]
    then
      sleep $(printf %f "$1e-6")
    fi
  }

This case is ok with sleep from gnu coreutils but if there are other cases with different sleep command only integer and also without usleep that I don't know will be not working.

Can This solution be better that the actual and I must do a patch or someone have a better solution?

Thanks for any reply and sorry for my bad english.

#1 lore raw
Quoted 23 lines · Fabio Fantoni

If usleep binary is missed in dom0 xendomains script use its function instead but as it is done now always rounds down to the nearest integer number, and in case it is less than 1 becomes 0.
So for example in dom0 like those I use (debian) withoutusleep binaryall small usleep in the script are null.

A solution can be to replace:

Quoted 7 lines
  usleep()
  {
    if [ -n "$1" ]
    then
      sleep $(( $1 / 1000000 ))
    fi
  }

with:

Quoted 7 lines
  usleep()
  {
    if [ -n "$1" ]
    then
      sleep $(printf %f "$1e-6")
    fi
  }
Quoted 6 lines

This case is ok with sleep from gnu coreutils but if there are other cases with different sleep command only integer and also without usleep that I don't know will be not working.

Can This solution be better that the actual and I must do a patch or someone have a better solution?

sleep $(( ( ($1 + 999999) / 1000000 ))

Should do the right thing (i.e. round up), I think.

Ian.

Quoted 2 lines

Thanks for any reply and sorry for my bad english.