From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: Yumei Huang <yuhuang@redhat.com>, passt-dev@passt.top
Subject: Re: [PATCH] test: Fix printf error when debug is enabled
Date: Tue, 30 Sep 2025 13:13:44 +0200 [thread overview]
Message-ID: <20250930131344.14de16d9@elisabeth> (raw)
In-Reply-To: <aNsjC6f_lV7PoXjd@zatzit>
On Tue, 30 Sep 2025 10:23:39 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:
> On Tue, Sep 30, 2025 at 12:24:17AM +0200, Stefano Brivio wrote:
> > On Mon, 29 Sep 2025 14:30:14 +0800
> > Yumei Huang <yuhuang@redhat.com> wrote:
> >
> > > Running test pasta/tcp with debug enabled would get stuck with
> > > below error:
> > >
> > > + printf 'DEBUG: ns socat -u OPEN:__BASEPATH__/big.bin TCP6:[__GW6__%__IFNAME__]:10003\n'
> > > lib/term: line 38: printf: `_': invalid format character
> > >
> > > The error occurs because printf interprets the % character as the
> > > start of a format specifier, and the following '_' isn't one of
> > > them.
> > >
> > > Fix it by replacing 'printf "${*}\n"' with 'printf "%s\n" "$*"'.
> >
> > I'm not sure why, but this breaks colour highlights for me. Instead of
> > seeing a part of this message in blue, now I get:
> >
> > Test layout: \033[1;34msingle passt instance with guest\033[0m.\n
> >
> > I can look into it if it only happens for me, or if needed.
>
> Oh, that's interesting. I believe the colouring has been broken
> forever on Fedora, but I never got around to looking into it.
> Figuring this out might reveal why. Maybe.
>
> I realised I think I know why: those colour codes rely on turning
> "\033" into a terminal escape. printf(1) will do that in the format
> string, but not in %s parameters
>
> $ printf "a\tb%sc\n " "\t"
> a b\tc
>
> We can fix this either by moving the escape codes back into the format
> string, or using %b instead of %s, which explicitly interprets string
> escape codes.
Oh, I didn't know about %b, nice. It's also in POSIX.1-2024, see point
7. here:
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/printf.html#tag_20_96_13
...side note for Yumei: the whole test suite _should_ be POSIX shell,
that is, it doesn't rely on specific shell (e.g. Bash) implementations.
For example, on Debian, Ubuntu, and others, the default shell for
non-interactive usage (not what you have on terminal, but what executes
scripts) is dash:
https://wiki.ubuntu.com/DashAsBinSh
https://wiki.archlinux.org/title/Dash
So, if it's described in the POSIX specification (the one I just
linked) it will almost certainly work everywhere. If not, it might
break (but not necessarily).
--
Stefano
prev parent reply other threads:[~2025-09-30 11:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 6:30 Yumei Huang
2025-09-29 6:41 ` David Gibson
2025-09-29 22:24 ` Stefano Brivio
2025-09-30 0:23 ` David Gibson
2025-09-30 1:32 ` Yumei Huang
2025-09-30 11:13 ` Stefano Brivio [this message]
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=20250930131344.14de16d9@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=yuhuang@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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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).