bug-gawk
[Top][All Lists]
Advanced

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

Re: fflush & close behavior not well-defined


From: Andrew J. Schorr
Subject: Re: fflush & close behavior not well-defined
Date: Wed, 30 Sep 2020 14:43:55 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Wed, Sep 30, 2020 at 12:08:01PM -0600, arnold@skeeve.com wrote:
> Ugh.  We may need to have 2 .ok files.  Can you debug why you
> get that status?  The value I got is death by signal for SIGPIPE
> (128 + signal number).  You're getting something else...

One line reproducer:

bash-4.2$ ./gawk --lint 'BEGIN {print "hello" |& "cat"; print close("cat")}'
gawk: cmd. line:1: warning: failure status (269) on two-way pipe close of 
`cat': Success
269

strace shows:

--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=3899, si_uid=300, 
si_status=SIGPIPE, si_utime=0, si_stime=0} ---

> It may be due to differences in glibc.
> 
> See sanitize_exit_status in builtin.c.

The argument to sanitize_exit_status is 13, so it adds 256.
Why is your system adding 128? The code says:

int sanitize_exit_status(int status)
{
        int ret = 0;

        if (WIFEXITED(status))
                ret = WEXITSTATUS(status); /* normal exit */
        else if (WIFSIGNALED(status)) {
                bool coredumped = false;
#ifdef WCOREDUMP
                coredumped = WCOREDUMP(status);
#endif
                /* use 256 since exit values are 8 bits */
                ret = WTERMSIG(status) + (coredumped ? 512 : 256);
        } else
                ret = 0;        /* shouldn't get here */

        return ret;
}

How can adding 128 possibly make sense? The code says 256...

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]