Skip to content

Commit 942b57d

Browse files
cristi-iacobcommodo
authored andcommitted
tests: iio_writedev: don't close the buffer on path with EXIT_SUCCESS
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]>
1 parent d957407 commit 942b57d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tests/iio_writedev.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void quit_all(int sig)
9191
{
9292
exit_code = sig;
9393
app_running = false;
94-
if (buffer)
94+
if (buffer && exit_code != EXIT_SUCCESS)
9595
iio_buffer_cancel(buffer);
9696
}
9797

@@ -457,8 +457,9 @@ int main(int argc, char **argv)
457457

458458
if (num_samples) {
459459
num_samples -= write_len / sample_size;
460-
if (!num_samples)
460+
if (!num_samples && !cyclic_buffer) {
461461
quit_all(EXIT_SUCCESS);
462+
}
462463
}
463464
} else {
464465
ret = iio_buffer_foreach_sample(buffer, read_sample, NULL);

0 commit comments

Comments
 (0)