Bug 1116072 - Close of file descriptor in function called from command substitution prevents return of output
Summary: Close of file descriptor in function called from command substitution prevent...
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: ksh
Version: 6.5
Hardware: x86_64
OS: Linux
Target Milestone: rc
: ---
Assignee: Michal Hlavinka
QA Contact: Martin Kyral
Depends On:
Blocks: 1202439
TreeView+ depends on / blocked
Reported: 2014-07-03 16:51 UTC by Mike Jetzer
Modified: 2019-05-20 11:13 UTC (History)
5 users (show)

Fixed In Version: ksh-20120801-26.el6
Doc Type: Bug Fix
Doc Text:
Prior to this update, the result of a command substitution was lost if a file descriptor used for the substituion was previously explicitly closed. With this update, ksh no longer reuses file descriptors that were closed during the execution of a command substitution. Now, command substitutions work as expected in the described situation.
Clone Of:
: 1202439 (view as bug list)
Last Closed: 2015-07-22 06:55:50 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:1450 normal SHIPPED_LIVE ksh bug fix update 2015-07-20 18:43:49 UTC

Description Mike Jetzer 2014-07-03 16:51:37 UTC
Description of problem:

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:

Actual results:

Expected results:

Additional info:

Comment 1 Mike Jetzer 2014-07-03 16:58:32 UTC
Sorry about that ... apparently hit "return" at an inopportune time.

Description of problem:

When calling a function inside of command substitution and the function both opens and closes the file descriptor "3", the output generated by the function is not returned as a result of the command substitution.

Sample code:


function get_value
    # Bug is not exhibited for empty files or files like
    # /etc/passwd, so create a file here.
    ls > $tmpfile

    # Bug is not exhibited if choosing a higher-numbered file
    # descriptor (e.g., 4).  However, since we don't know if we'll
    # be called from within command substitutions, or the number of
    # levels of command substitution, this is not a general solution.
    exec 3< $tmpfile

    # My actual program performs some "read -u3" statments, but that
    # is not necessary to exercise bug.

    if [[ $1 = close_fd ]]
        exec 3<&-

    print return-value

value=$(get_value close_fd)
print ${value:-error: no return value}
rm $tmpfile

value=$(get_value noclose_fd)
print ${value:-no value}
rm $tmpfile

exit 0

Version-Release number of selected component (if applicable):
This appears to have been introduced sometime between ast-ksh.2012-01-01 (works correctly) and ast-ksh.2012-02-02 (exhibits bug).  The bug persists in ast-ksh.2012-08-01, the last stable version on the AT&T Website at this time.  The bug is still present in ast-ksh.2013-10-10 but is fixed in ast-ksh.2014-06-25 (these are the only two releases after ast-ksh.2012-08-01 that I can find).

How reproducible:

Steps to Reproduce:
1.  Run sample code above
2.  There is no #2.

Actual results:
error: no return value

Expected results:

Additional info:

Comment 3 Michal Hlavinka 2014-12-12 19:10:36 UTC

Comment 10 errata-xmlrpc 2015-07-22 06:55:50 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.