Skip to content

Commit

Permalink
selftests: timers: set-timer-lat: fix hang when std out/err are redir…
Browse files Browse the repository at this point in the history
…ected

do_timer_oneshot() uses select() as a timer with FD_SETSIZE and readfs
is cleared with FD_ZERO without FD_SET.

When stdout and stderr are redirected, the test hangs in select forever.
Fix the problem calling select() with readfds empty and nfds zero. This
is sufficient for using select() for timer.

With this fix "./set-timer-lat > /dev/null 2>&1" no longer hangs.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Acked-by: Greg Hackmann <ghackmann@google.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
  • Loading branch information
Shuah Khan committed Sep 25, 2017
1 parent 21aadfa commit 01db7fb
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions tools/testing/selftests/timers/set-timer-lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ int do_timer_oneshot(int clock_id, int flags)
timer_t tm1;
const int interval = 0;
struct timeval timeout;
fd_set fds;
int err;

err = setup_timer(clock_id, flags, interval, &tm1);
Expand All @@ -237,9 +236,8 @@ int do_timer_oneshot(int clock_id, int flags)

memset(&timeout, 0, sizeof(timeout));
timeout.tv_sec = 5;
FD_ZERO(&fds);
do {
err = select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
err = select(0, NULL, NULL, NULL, &timeout);
} while (err == -1 && errno == EINTR);

timer_delete(tm1);
Expand Down

0 comments on commit 01db7fb

Please sign in to comment.