Example #1
0
func readData(conn net.Conn) (*container_daemon.ResponseMessage, error) {
	var b [2048]byte
	var oob [2048]byte
	var response container_daemon.ResponseMessage

	n, oobn, _, _, err := conn.(*net.UnixConn).ReadMsgUnix(b[:], oob[:])
	if err != nil {
		return nil, fmt.Errorf("unix_socket: failed to read unix msg: %s (read: %d, %d)", err, n, oobn)
	}

	if n > 0 {
		err := json.Unmarshal(b[:n], &response)
		if err != nil {
			return nil, fmt.Errorf("unix_socket: Unmarshal failed: %s", err)
		}
		if response.ErrMessage != "" {
			return nil, errors.New(response.ErrMessage)
		}
	} else {
		return nil, errors.New("unix_socket: No response received")
	}

	scms, err := syscall.ParseSocketControlMessage(oob[:oobn])
	if err != nil {
		return nil, fmt.Errorf("unix_socket: failed to parse socket control message: %s", err)
	}

	if len(scms) > 0 {
		scm := scms[0]
		fds, err := syscall.ParseUnixRights(&scm)
		if err != nil {
			return nil, fmt.Errorf("unix_socket: failed to parse unix rights: %s", err)
		}

		response.Files = make([]container_daemon.StreamingFile, len(fds))
		for i, fd := range fds {
			response.Files[i] = os.NewFile(uintptr(fd), fmt.Sprintf("/dev/fake-fd-%d", i))
		}
	}

	return &response, nil
}
Example #2
0
	"github.com/cloudfoundry-incubator/garden-linux/container_daemon/fake_connector"
	"github.com/cloudfoundry-incubator/garden-linux/container_daemon/fake_term"
	"github.com/cloudfoundry-incubator/garden-linux/iodaemon/link"
	"github.com/docker/docker/pkg/term"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("Process", func() {
	var socketConnector *fake_connector.FakeConnector
	var fakeTerm *fake_term.FakeTerm
	var sigwinchCh chan os.Signal
	var signalReader io.Reader
	var signalWriter io.Writer
	var response *container_daemon.ResponseMessage
	var process *container_daemon.Process

	BeforeEach(func() {
		var err error

		fakeTerm = new(fake_term.FakeTerm)
		socketConnector = new(fake_connector.FakeConnector)
		response = &container_daemon.ResponseMessage{
			Type:  container_daemon.ProcessResponse,
			Files: []container_daemon.StreamingFile{nil, nil, nil, FakeFd(0)},
			Pid:   0,
		}

		socketConnector.ConnectReturns(response, nil)