Re: [BUG] failure to push/restore closed file descriptor

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

 



Op 27-04-18 om 17:51 schreef Herbert Xu:
On Fri, Apr 27, 2018 at 05:47:27PM +0200, Martijn Dekker wrote:

No, because step 1 doesn't merely close fd 8. It enters a curly braces block
(a compound command) that locally closes fd 8 using a redirection, just like
any other redirection would be local to that compound command. Thus,
restoring the fd state when leaving that block must undo the effect of the
'exec'.

Note that dash already does this correctly if the '8<&-' is replaced by any
other redirection such as '8>/dev/tty'.

That's different as 8 was previously closed and is now open.

POSIX 2.7 Redirection says: "Redirection is used to open and close files for
the current shell execution environment [...] or for any command". Note that
"any command" includes compound commands such as curly braces blocks.

Well, I don't see anything in POSIX that requires us to close fd 8.
Can you please point it out to me please?

I will ask more authoritative people on the Austin Group for clarification and get back to you.

Even if it turns out it's not "required", though, I would think the current behaviour breaks obvious expectations.

To guarantee the expected behaviour of pushing that fd onto the shell's internal stack for restoring when leaving the compound command, you'd need to push it twice in two different states in two nested compound command blocks, for instance:

  { { exec 8</some/file; stuff using fd 8; } 8<&-; } 8>/dev/null

The need for that workaround seems like evidence of a bug to me.

- M.
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux