Bug 736195

Summary: Apparent race condition when using pipes in KSH scripts.
Product: Red Hat Enterprise Linux 5 Reporter: Eric Sammons <esammons>
Component: kshAssignee: Michal Hlavinka <mhlavink>
Status: CLOSED ERRATA QA Contact: qe-baseos-tools-bugs
Severity: urgent Docs Contact:
Priority: urgent    
Version: 5.7CC: cww, dsulliva, kvolny, mfranc, ovasik, prc, svashisht
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: ksh-20100621-1.el5 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 739669 1243895 1243896 1243897 (view as bug list) Environment:
Last Closed: 2012-02-21 05:51:07 UTC Type: ---
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: 668957, 739669    

Description Eric Sammons 2011-09-07 00:06:37 UTC
Description of problem:

When running ksh scripts on RHEL 5 (and RHEL 6) multiple processes are reported running when $(ps -ef |grep $BNAME|grep -v grep |wc -l).  Expect only "1" to be returned but often times see 2+ returned.

[code]
#!/bin/ksh93

BNAME=`basename $0`
OUT="`ps -ef|grep ${BNAME} | grep -v grep |wc -l`"
if [ ${OUT} -ge "2" ];then
   echo "FAIL"
   exit 1
else
   echo "SUCCESS"
fi
[/code]

Version-Release number of selected component (if applicable):
<= ksh-20100202-1.el5_5.1 (RHEL5)
<= ksh-20100621-6.el6.x86_64 (RHEL6)


How reproducible:

Every time, use code snippet above.


Steps to Reproduce:
1. Create a ksh script as noted above.
2. Run script
  
Actual results:
FAIL
(indicating 2+ pids returned)

Expected results:
SUCESS
(indicating 1 pid returned)

Additional info:

RHEL 5.6 (ksh-20100202-1.el5_5.1)
# ./test5.6.ksh 
+ basename ./test5.6.ksh
+ BNAME=test5.6.ksh
+ ps -ef
+ grep test5.6.ksh
+ grep -v grep
+ wc -l
+ OUT=2
+ [ 2 -ge 2 ]
+ echo FAIL
FAIL
+ exit 1

Fedora 15 (ksh-20110505-2.fc15.x86_64)
# ./test.ksh
+ basename ./test.ksh
+ BNAME=test.ksh
+ ps -ef
+ grep test.ksh
+ grep -v grep
+ wc -l
+ OUT=1
+ [ 1 -ge 2 ]
+ echo SUCCESS
SUCCESS

I feel the following patch may have provided the fix; however, I can not get the patch into the RHEL 5 version of ksh.

* Wed Jun 08 2011 Michal Hlavinka <mhlavink> - 20110505-2
- fix: resume of suspended process using pipes does not work (#708909)

Comment 2 Michal Hlavinka 2011-09-09 09:50:51 UTC
> When running ksh scripts on RHEL 5 (and RHEL 6) multiple processes
> are reported running when $(ps -ef |grep $BNAME|grep -v grep |wc -l).  
> Expect only "1" to be returned but often times see 2+ returned.

Are you sure with that? I can reproduce this in RHEL 5, but it works for me in RHEL 6 (both ksh-20100621-6.el6.x86_64 = rhel-6.1 and update-to-be ksh-20100621-9.el6.x86_64).

I've tested all versions I have and it seems fixed between 2010-05-27 (last broken) and 2010-06-21 (first working) which is scheduled as update in rhel 5.8. So please retest RHEL6 version.

Comment 15 Michal Hlavinka 2011-10-25 12:24:29 UTC
*** Bug 709774 has been marked as a duplicate of this bug. ***

Comment 17 errata-xmlrpc 2012-02-21 05:51:07 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.

http://rhn.redhat.com/errata/RHBA-2012-0159.html