This is an archive of the discontinued LLVM Phabricator instance.

Fix descriptor leak in multi-target debugging
ClosedPublic

Authored by labath on Feb 6 2015, 6:21 AM.

Details

Summary

When debugging two targets concurrently, the pseude terminal master fd from the first one would
leak into the second. This fixes the problem by setting O_CLOEXEC on the master fd. Test
included.

Diff Detail

Repository
rL LLVM

Event Timeline

labath updated this revision to Diff 19482.Feb 6 2015, 6:21 AM
labath retitled this revision from to Fix descriptor leak in multi-target debugging.
labath updated this object.
labath edited the test plan for this revision. (Show Details)
labath added reviewers: clayborg, vharron.
labath added a subscriber: Unknown Object (MLST).
emaste added a subscriber: emaste.Feb 6 2015, 8:39 AM
emaste added a comment.Feb 6 2015, 8:44 AM

I can't fully confirm the fix on FreeBSD at the moment due to python leaking an fd, but LGTM.

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=197376 but

source/Utility/PseudoTerminal.cpp
262 ↗(On Diff #19482)

in case O_CLOEXEC fails or is unsupported?

clayborg edited edge metadata.Feb 6 2015, 9:44 AM

Looks good.

This revision was automatically updated to reflect the committed changes.

Hi, please be careful with O_CLOEXEC in the future. I've had to fix two
patches on Windows in the past week because of it. It's not the end of the
world, but just keep in mind next time using it that it doesn't exist on
Windows so you'll need to wrap its use in an #if defined(_MSC_VER)

I'm sorry about that.

I _was_ thinking about windows, but I was like: the function is called Terminal::Fork, there is no way that can be used on windows... :)

Anyway, I should be done with this now. Thanks for fixing it up.

Heh. Sooner or later this entire file needs to be compiled out on Windows,
so your thinking was pretty close :)