Bug 436368 - Double close in dd
Summary: Double close in dd
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: coreutils
Version: rawhide
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: Ondrej Vasik
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-03-06 20:03 UTC by Ulrich Drepper
Modified: 2008-03-11 12:55 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-03-11 12:55:49 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Ulrich Drepper 2008-03-06 20:03:54 UTC
Description of problem:
Running

  strace -E LC_ALL=C dd if=/dev/zero of=/dev/null count=1 bs=1

shows that dd tries to close file descriptor 1 twice:

[...]
write(2, "1 byte (1 B) copied", 191 byte (1 B) copied)     = 19
write(2, ", 0.000151196 s, 6.6 kB/s\n", 26, 0.000151196 s, 6.6 kB/s
) = 26
close(1)                                = -1 EBADF (Bad file descriptor)
close(2)                                = 0



Version-Release number of selected component (if applicable):
coreutils-6.10-11.fc9
coreutils-6.9-13.fc8

How reproducible:
always

Steps to Reproduce:
1.run above command
2.
3.
  
Actual results:
double close

Expected results:
only one close

Additional info:

Comment 1 Ondrej Vasik 2008-03-07 08:13:22 UTC
Thanks for report.
Caused by atexit(close_stdout).
This atexit close is (from comments) because of possible exit in external
function for parsing long options.
Second one is in cleanup function (from comments) necessary for call from signal
handler. 
Maybe the easiest solution would be to differ between signal handling cleanup
and exit/quit cleanup (two functions or boolean for decision)...
Any other ideas?

Comment 2 Jim Meyering 2008-03-07 12:27:18 UTC
Thanks for the report.  For the record, there was no harm in that double close,
other than the negligible overhead of the failing close syscall. In spite of
that, I've changed dd.c to avoid the unnecessary close_stdout call when possible:
  http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/12901

Comment 3 Ondrej Vasik 2008-03-11 12:55:49 UTC
Built as coreutils-6.10-12.fc9 , closing RAWHIDE.


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