Repository navigation
libtailscale: do not close the caller's fd in tailscale_set_logfd - #68
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
TsnetSetLogFD wrapped the caller's fd in os.NewFile. An *os.File closes its fd when it is garbage collected, so once the logger was replaced (another tailscale_set_logfd call) or the server was closed, the next GC cycle closed an fd that belongs to the C caller. With tailscale_set_logfd(sd, 2) that closes the process's stderr, and if the number has since been reused, an unrelated file or socket. Write to the fd with write(2) through a small io.Writer instead, which never closes it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TsnetSetLogFDwraps the caller's fd inos.NewFile. An*os.Filecloses its fd when it is garbage collected, so after the logger is replaced (a secondtailscale_set_logfdcall, for example with-1) or the server is closed, the next GC cycle closes an fd that belongs to the C caller. Withtailscale_set_logfd(sd, 2)this closes the process's stderr; if the fd number has been reused in the meantime, it closes an unrelated file or socket.Change
TsnetSetLogFDwrites to the fd withwrite(2)through a smallfdWritertype, which never closes it. Log output is unchanged.TestSetLogFD(intsnetctest) passes one end of a pipe totailscale_set_logfd, resets the logger with-1, closes the server, runs GC, and checks that the fd is still open.Testing