Menu

#6 usleep return value check

v1.0 (example)
closed-fixed
nobody
None
5
2015-07-26
2010-04-21
No

OS: linux mandriva 2009.0
Project version: bwm-ng-0.6
bwm-ng.c:216 if (EINVAL==usleep(delay*1000))
/* there seems to be systems where 1million usecs is max */
usleep(999999);

According to man usleep() possible return values are 0 on success and -1 on error. If the error occures errno is set to EINVAL or EINTR. Linux man seems a bit ambiguity on the case but posix and freebsd man pages states explicitely: "If any of the following conditions occur, the usleep() function shall return -1 and set errno to the corresponding value."

Solution:
if (usleep(delay*1000) != 0)
{
if (errno == EINVAL)
{
errno = 0;
/* there seems to be systems where 1million usecs is max */
usleep(999999);
}
else
{
exit(-1);
}
}

Discussion

  • vgropp

    vgropp - 2015-07-26
    • status: open --> closed-fixed
    • Group: --> v1.0 (example)
     
  • vgropp

    vgropp - 2015-07-26

    should be fixed in 0.6.1

     

Log in to post a comment.

MongoDB Logo MongoDB