Beam: debugging hooks for easy step-by-step inspection of the FD table
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
83adf99565
commit
24c09d0029
1 changed files with 25 additions and 1 deletions
26
beam/unix.go
26
beam/unix.go
|
@ -5,11 +5,28 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"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
|
// Send sends a new message on conn with data and f as payload and
|
||||||
// attachment, respectively.
|
// attachment, respectively.
|
||||||
func Send(conn *net.UnixConn, data []byte, f *os.File) error {
|
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
|
var fds []int
|
||||||
if f != nil {
|
if f != nil {
|
||||||
fds = append(fds, int(f.Fd()))
|
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
|
// If more than 1 file descriptor is sent in the message, they are all
|
||||||
// closed except for the first, which is the attachment.
|
// closed except for the first, which is the attachment.
|
||||||
// It is legal for a message to have no attachment or an empty payload.
|
// 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 {
|
for {
|
||||||
data, fds, err := receiveUnix(conn)
|
data, fds, err := receiveUnix(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue