[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] POSIX mode "system" returing invalid exit status
From: |
Steven Penny |
Subject: |
Re: [bug-gawk] POSIX mode "system" returing invalid exit status |
Date: |
Sun, 25 Mar 2018 13:25:08 -0500 |
On Sun, Mar 25, 2018 at 12:45 AM, arnold wrote:
> The upshot is that gawk's --posix behavior is correct, if not terribly
> useful.
The issue with `system` is we have 6 possible inputs:
1. posix exit, first: 0, last: 65280, step: 256
2. posix signal, first: 1, last: 64, step: 1
3. posix dump, first: 129, last: 192, step: 1
4. normal exit, first: 0, last: 255, step: 1
5. normal signal, first: 257, last: 320, step: 1
6. normal dump, first: 513, last: 576, step: 1
Note dump numbers are not exactly right as SIGQUIT (3) is the first dump
signal, but they are close enough.
- http://man7.org/linux/man-pages/man7/signal.7.html
- http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html
- http://wikipedia.org/wiki/Signal_(IPC)
and 2 possible outputs:
1. exit, first: 0, last: 128, step: 1
2. signal or dump, first: 129, last: 255, step: 1
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_21_18
For anyone interested, I wrote a function that should produce sane output
regardless is "--posix" is chosen:
function o_posix() {
return 010 == 8 ? 0 : 1
}
function k_system(stn, z) {
z = system(stn)
if (o_posix()) {
return z % 256 ? z < 128 ? z + 128 : z : z / 256
}
return z > 256 ? z > 512 ? z - 384 : z - 128 : z
}