Re: Issues with sndioctl -m output

From: Alexandre Ratchov <alex_at_caoua.org>
Date: Sun, 6 Sep 2020 10:54:18 +0200
On Sat, Sep 05, 2020 at 08:55:23PM -0300, Érico Nogueira wrote:
> Hi!
> 
> As a stopgap measure before I try to integrate sndioctl into my status
> bar using libsndio, I decided to try and write a simple parsing script
> using sndioctl. Calling `sndioctl -m` and sed'ing around that to get a
> number seemed like a straightforward approach that would avoid having to
> run `sndioctl` in a loop, but unfortunately `sndioctl -m` behaves
> weirdly when its output is piped into some other program. This can be
> reproduced by comparing the outputs of:
> 
>     sndioctl -m
> 
> and
> 
>     sndioctl -m | cat
> 
> Not only is the initial output different, but the second case doesn't
> output new messages for changes such as output level. I tried looking
> into how these values are printed, but couldn't find anything obvious in
> the code that would lead to this. If there are any suggestions for where
> this error could be happening, I would be happy to try and fix it myself
> and submit a patch.

Hi,

The "setlinebuf(stdout)" call is missing when the loop correstponding
to -m starts. Does this works for you?

diff --git a/sndioctl/sndioctl.c b/sndioctl/sndioctl.c
index 4c4a85a..71ae298 100644
--- a/sndioctl/sndioctl.c
+++ b/sndioctl/sndioctl.c
_at_@ -1014,6 +1014,7 @@ main(int argc, char **argv)
 			perror("malloc");
 			exit(1);
 		}
+		setlinebuf(stdout);
 		for (;;) {
 			nfds = sioctl_pollfd(hdl, pfds, POLLIN);
 			if (nfds == 0)
Received on Sun Sep 06 2020 - 10:54:18 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 09 2022 - 16:23:49 CEST