Skip to content

Commit

Permalink
tests: iio_writedev: don't close the buffer on path with EXIT_SUCCESS
Browse files Browse the repository at this point in the history
The quit_all() routine has a nasty side-effect, in that it closes the
buffer regardless of whether the exit-code is succesfull or not.

This is bad as it can close a socket before the iio_buffer_push() is
called resulting in an -EBADF error code.

Also, we don't want to set 'app_running' to false for the cyclic
context.

This change makes quit_all() close the buffer only on calls with a signal different from EXIT_SUCCESS.

Signed-off-by: Cristi Iacob <[email protected]>
  • Loading branch information
cristi-iacob authored and commodo committed Apr 16, 2020
1 parent d957407 commit 942b57d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/iio_writedev.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void quit_all(int sig)
{
exit_code = sig;
app_running = false;
if (buffer)
if (buffer && exit_code != EXIT_SUCCESS)
iio_buffer_cancel(buffer);
}

Expand Down Expand Up @@ -457,8 +457,9 @@ int main(int argc, char **argv)

if (num_samples) {
num_samples -= write_len / sample_size;
if (!num_samples)
if (!num_samples && !cyclic_buffer) {
quit_all(EXIT_SUCCESS);
}
}
} else {
ret = iio_buffer_foreach_sample(buffer, read_sample, NULL);
Expand Down

0 comments on commit 942b57d

Please sign in to comment.