Bug 122558 - tcsh redirection misbehaving with echo builtin
tcsh redirection misbehaving with echo builtin
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: tcsh (Show other bugs)
3.0
ia64 Linux
medium Severity medium
: ---
: ---
Assigned To: Miloslav Trmač
Bill Huang
:
: IT_52172 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-05-05 15:18 EDT by Tony Ernst
Modified: 2007-11-30 17:07 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-12-21 10:02:40 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Tony Ernst 2004-05-05 15:18:50 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2)
Gecko/20040220

Description of problem:
Using scripts similar to "configure" scripts which generate other
smaller sub-scripts and then execute them, we are seeing that the
sub-scripts fail to execute with the error "Text file busy".
It appears that a file descriptor is being left open after the
redirection.


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

How reproducible:
Always

Steps to Reproduce:
% cat ./mytest
#!/bin/tcsh -f

rm -f ./mysubscript
echo "#\!/bin/tcsh" > ./mysubscript
echo "ls -l" >> ./mysubscript
chmod a+x ./mysubscript

./mysubscript 
exit 0

% chmod u+x ./mytest
% ./mytest
./mysubscript: Text file busy.
% 


Actual Results:  % ./mytest
./mysubscript: Text file busy.
% 

Expected Results:  % ./mytest
total 128
-rwxr-xr-x    1 tee      os1            18 May  5 13:57 mysubscript
-rwxr--r--    1 tee      os1           150 May  5 13:54 mytest
% 

Additional info:


If you replace the first 'echo' with '/bin/echo', it works.

% diff mytest mytest.good
4c4
< echo "#\!/bin/tcsh" > ./mysubscript
---
> /bin/echo "#\!/bin/tcsh" > ./mysubscript
% 
% ./mytest.good
total 72
-rwxr-xr-x    1 tee      os1            18 May  5 14:04 mysubscript
-rwxr--r--    1 tee      os1           150 May  5 13:54 mytest
-rwxr--r--    1 tee      os1           155 May  5 13:59 mytest.good
% 

Also, if you only use redirection to append ('>>' instead of '>'), it
works.

% diff mytest mytest.append
4c4,5
< echo "#\!/bin/tcsh" > ./mysubscript
---
> touch ./mysubscript
> echo "#\!/bin/tcsh" >> ./mysubscript
% 
% ./mytest.append
total 136
-rwxr-xr-x    1 tee      os1            18 May  5 14:14 mysubscript
-rwxr--r--    1 tee      os1           150 May  5 13:54 mytest
-rwxr--r--    1 tee      os1           171 May  5 14:11 mytest.append
-rwxr--r--    1 tee      os1           155 May  5 13:59 mytest.good
%
Comment 1 Tony Ernst 2004-05-05 15:49:50 EDT
I looked at traces of both the failing case (mytest) and the appending
case (mytest.append).

The difference seems to be that in the failing case there's an
additional 'fcntl(3, F_DUPFD, 0)' being called after the
'open("./mysubscript", ...)'.  This seems likely to be the cause of
the problem.

mytest trace:
=============
open("./mysubscript", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fcntl(3, F_DUPFD, 0)                    = 4
dup2(3, 1)                              = 1
close(3)                                = 0
ioctl(1, TCGETS or SNDCTL_TMR_TIMEBASE, 0x60000ffffffef880) = -1
ENOTTY (Inappropriate ioctl for device)
close(2)                                = 0
dup(18)                                 = 2
fcntl(2, F_SETFD, 0)                    = 0
rt_sigprocmask(SIG_BLOCK, [], [INT], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], [INT], 8) = 0
write(1, "#!/bin/tcsh\n", 12)           = 12
rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0

mytrace.append trace:
=====================
open("./mysubscript", O_WRONLY|O_APPEND) = 3
dup2(3, 1)                              = 1
close(3)                                = 0
ioctl(1, TCGETS or SNDCTL_TMR_TIMEBASE, 0x60000ffffffef870) = -1
ENOTTY (Inappropriate ioctl for device)
close(2)                                = 0
dup(18)                                 = 2
fcntl(2, F_SETFD, 0)                    = 0
rt_sigprocmask(SIG_BLOCK, [], [INT], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], [INT], 8) = 0
write(1, "#!/bin/tcsh\n", 12)           = 12
rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0
Comment 2 Miloslav Trmač 2004-10-19 17:29:30 EDT
*** Bug 136418 has been marked as a duplicate of this bug. ***
Comment 3 John Flanagan 2004-12-21 10:02:40 EST
An advisory has been issued which should help the problem 
described in this bug report. This report is therefore being 
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files, 
please follow the link below. You may reopen this bug report 
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2004-524.html

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