Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1116072

Summary: Close of file descriptor in function called from command substitution prevents return of output
Product: Red Hat Enterprise Linux 6 Reporter: Mike Jetzer <mjetzer.cdc>
Component: kshAssignee: Michal Hlavinka <mhlavink>
Status: CLOSED ERRATA QA Contact: Martin Kyral <mkyral>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.5CC: kdudka, mhlavink, mkyral, ovasik, ykinoshi
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
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.
Story Points: ---
Clone Of:
: 1202439 (view as bug list) Environment:
Last Closed: 2015-07-22 06:55:50 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1202439    

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:
1.
2.
3.

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:
------------------------------------------------------------------------------
#!/bin/ksh

tmpfile=/tmp/bug.$$

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 ]]
    then
        exec 3<&-
    fi

    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:
Always.

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

Actual results:
error: no return value
return-value

Expected results:
return-value
return-value

Additional info:

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

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.

https://rhn.redhat.com/errata/RHBA-2015-1450.html