Thread overview
[Issue 3157] New: [patch] Pipes should be closed with pclose
Sep 08, 2010
Brad Roberts
July 09, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3157

           Summary: [patch] Pipes should be closed with pclose
           Product: D
           Version: 2.031
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Keywords: patch
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bugzilla@kyllingen.net


Created an attachment (id=418)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=418)
Patch for stdio.d version 2.031

FILE*s opened with popen should be closed with pclose, not fclose. I've attached a patch (against stdio.d, version 2.031) which makes File.close do this automatically.

This bug causes problems with e.g. the std.process.shell function, which throws an exception whenever a program returns with a nonzero exit status. Example:

    import std.process;
    void main() { shell("dmd"); }

When DMD is run with no arguments it returns 1, so running the program above causes the following error:

    std.contracts.ErrnoException: std/stdio.d(397):
    Could not close file `dmd' (Success)

I've created a simple patch against stdio.d to fix this. (It's my first patch ever, so be gentle...) It adds the member "bool isPipe" to the File.Impl struct, which simply tells whether the file is opened with popen or not. The File.close() method checks isPipe and calls pclose if it is true. Note that pclose returns the exit status of the program, so I had to remove the errnoEnforce for that case.

Another solution is of course to add a method File.pclose, and require that all popen'ed Files must also be pclosed. However, I think it is better if File.close does this automatically.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3157


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3157


Lars T. Kyllingstad <bugzilla@kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator@gmail.com


--- Comment #1 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2010-04-26 00:14:41 PDT ---
*** Issue 4127 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3157



--- Comment #2 from Brad Roberts <braddr@puremagic.com> 2010-09-08 02:07:01 PDT ---
Created an attachment (id=750)
updated and slightly alternate implmentation

This patch makes me a little ill.. abusing an exception to propagate more data because the File abstraction around the pipe is a poor fit.

BUT, I really want to be able to get both the string output as well as it's result code.  So.. thoughts?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3157


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-09-26 18:12:08 PDT ---
http://www.dsource.org/projects/phobos/changeset/2066

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------