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: | ksh | Assignee: | Michal Hlavinka <mhlavink> | |
| Status: | CLOSED ERRATA | QA Contact: | Martin Kyral <mkyral> | |
| Severity: | unspecified | Docs Contact: | ||
| Priority: | unspecified | |||
| Version: | 6.5 | CC: | 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
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:
reproducible 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 |