public inbox for passt-user@passt.top
 help / color / mirror / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: "John Radley (jradxl2)" <jradxl2@gmail.com>,
	"passt-user@passt.top" <passt-user@passt.top>,
	Paul Holzinger <pholzing@redhat.com>
Subject: Re: Can't pipe output of pasta --version
Date: Wed, 28 May 2025 09:45:33 +0200	[thread overview]
Message-ID: <20250528094533.1bd932e8@elisabeth> (raw)
In-Reply-To: <aDZ0BtUnwA71MOzo@zatzit>

[Cc: Paul as author of d0006fa78]

On Wed, 28 May 2025 12:25:10 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Tue, May 27, 2025 at 05:21:19PM +0000, John Radley (jradxl2) wrote:
> > Hello,I can't pipe output like this:-
> > $ pasta --version | grep pasta<blank!>
> > but this works:-
> > $ sudo apt install expect
> > $ unbuffer pasta --version | grep pasta
> > pasta 2025_05_12.8ec1341-9-g3262c9b
> > 
> > If this is the intended action, please can you tell me why?  
> 
> Ouch.  No, that's not intended.
> 
> I initially assumed this was because we were sending the version
> information to stderr instead of stdout, but that's not the case.
> 
> This is a bug introduced by d0006fa78 ("treewide: use _exit() over
> exit()").  For --version we're displaying the information with
> fprintf(), then immediately exiting with _exit().  When writing to a
> pipe, stdout is buffered.  Normally the buffer would be flushed before
> exiting, but using _exit() bypasses that.
> 
> We could fix this specific problem by adding an fflush(stdout) before
> the _exit().  However, I worry that there might be other bugs we have
> because we're not running libc installed exit handlers here and
> elsewhere.  I was already a bit dubious about using _exit() by
> default, and now I really don't think it was a good idea.

Well, that's something we looked into (of course...), and (I?) concluded
that we never needed to flush stdio, which is the only otherwise useful
thing glibc handlers would do for us, and which kind of holds... except
for this case. And maybe for --help or any "early" exit.

So we could fflush() as well in those cases, and just in those
cases, with the added benefit that we don't need to add additional
system calls to the permitted seccomp set, because if we exit early, we
didn't install the seccomp filter yet.

> That said, I don't immediately have a better idea of how to address
> the problem d0006fa78 was aiming to fix in the first place.
> 
> Well... I'm on holiday at the moment, so I won't be fixing it.
> Laurent & Stefano, I hope the analysis above is helpful.

I'm on holiday too, I'll fix this later this week or next week, unless
Paul is particularly inspired (or John wants to look into the issue a
bit further and contribute a patch...?).

-- 
Stefano


  reply	other threads:[~2025-05-28  7:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1378983862.3469095.1748366479602.ref@mail.yahoo.com>
     [not found] ` <1378983862.3469095.1748366479602@mail.yahoo.com>
2025-05-28  2:25   ` Can't pipe output of pasta --version David Gibson
2025-05-28  7:45     ` Stefano Brivio [this message]
     [not found]     ` <174841834113.3062894.7293539982980796043@maja>
2025-05-28 23:31       ` Jon Maloy
2025-05-30  8:10         ` Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250528094533.1bd932e8@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=jradxl2@gmail.com \
    --cc=passt-user@passt.top \
    --cc=pholzing@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).