tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

nawk file descriptor handling bug (was: grafana hits pkgsrc limits again)



On Tue, 6 Aug 2024 17:44:56 +0100
Jonathan Perkin <jperkin%mnx.io@localhost> wrote:

> I've been revisiting this today, and I hit a problem during testing that 
> might be related.  It seems the awk on NetBSD behaves differently when 
> reading from stdin, at least compared to other OS that I have handy that 
> also ship one-true-awk.
> 
> Simple reproducible testcase:
> 
>    $ uname -rsm
>    NetBSD 10.0 amd64
>    $ awk --version
>    awk version 20200218
>    $ echo foo | awk 'BEGIN { while(getline < "-") }'; echo $?
>    2
> 
>    $ uname -rsm
>    Darwin 23.5.0 arm64
>    $ awk --version
>    awk version 20200816
>    $ echo foo | awk 'BEGIN { while(getline < "-") }'; echo $?
>    0
> 
>    $ uname -rsv
>    SunOS 5.11 joyent_20210826T002459Z
>    $ awk --version
>    awk version Aug 27, 2018
>    $ echo foo | awk 'BEGIN { while(getline < "-") }'; echo $?
>    0
>    $ nawk --version
>    awk version 20121220
>    $ echo foo | nawk 'BEGIN { while(getline < "-") }'; echo $?
>    0
> 
> Unfortunately this breaks the behaviour of the "distinfo" target when 
> nothing has changed.  Annoyingly you can't even override it:
> 
>    $ echo foo | awk 'BEGIN { while(getline < "-"); print "hi"; exit 0; }'; echo $?
>    hi
>    2
> 
> I don't really know what to do about this, unless there's some esoteric 
> workaround ... which I just found while writing this!  If you specify 
> "/dev/stdin" instead then it does work.  I'll send this anyway as I feel 
> it's a bug that should be fixed, and it probably explains the behaviour 
> difference you were seeing compared to me.

So, I investigated this. It turns out to be a a bug that was fixed in
one true awk a while back. But NetBSD does not have the fix.

https://github.com/onetrueawk/awk/commit/99f6a432969cd42aa1dcba580eefe9d23601e51b

I tried to apply the patch to src/external/historical/nawk, but it did
not apply cleanly. I'll copy in christos@ to the thread since he has
worked with nawk upstream and might know the status. From what I
understand the bug was introduced in nawk in 2020 and fixed in 2023.

-Tobias


Home | Main Index | Thread Index | Old Index