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: nob...@puremagic.com
        ReportedBy: bugzi...@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: -------

Reply via email to