From 24c09d0029c5e5fd002cbcb4e7b1da0158e9c39b Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sun, 23 Mar 2014 20:41:28 -0700 Subject: [PATCH] Beam: debugging hooks for easy step-by-step inspection of the FD table Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- beam/unix.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/beam/unix.go b/beam/unix.go index 0cb568a..42358dc 100644 --- a/beam/unix.go +++ b/beam/unix.go @@ -5,11 +5,28 @@ import ( "net" "os" "syscall" + "bufio" ) +func debugCheckpoint(msg string, args ...interface{}) { + return + os.Stdout.Sync() + tty,_ := os.OpenFile("/dev/tty", os.O_RDWR, 0700) + fmt.Fprintf(tty, msg, args...) + bufio.NewScanner(tty).Scan() + tty.Close() +} + // Send sends a new message on conn with data and f as payload and // attachment, respectively. func Send(conn *net.UnixConn, data []byte, f *os.File) error { + { + var fd int = -1 + if f != nil { + fd = int(f.Fd()) + } + debugCheckpoint("===DEBUG=== about to send '%s'[%d]. Hit enter to confirm: ", data, fd) + } var fds []int if f != nil { fds = append(fds, int(f.Fd())) @@ -23,7 +40,14 @@ func Send(conn *net.UnixConn, data []byte, f *os.File) error { // If more than 1 file descriptor is sent in the message, they are all // closed except for the first, which is the attachment. // It is legal for a message to have no attachment or an empty payload. -func Receive(conn *net.UnixConn) ([]byte, *os.File, error) { +func Receive(conn *net.UnixConn) (rdata []byte, rf *os.File, rerr error) { + defer func() { + var fd int = -1 + if rf != nil { + fd = int(rf.Fd()) + } + debugCheckpoint("===DEBUG=== Receive() -> '%s'[%d]. Hit enter to continue.\n", rdata, fd) + }() for { data, fds, err := receiveUnix(conn) if err != nil {