Skip to content

Commit

Permalink
Add helper programs for console support
Browse files Browse the repository at this point in the history
recvtty is needed to trick runc into thinking it has a console and
doesn't err out and serial_fd_handler passes off the tty fd to
containerd.  Both support being cross compiled.

Signed-off-by: Brian Woods <brian.woods@xilinx.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
  • Loading branch information
Brian Woods authored and sstabellini committed Mar 5, 2020
1 parent 4531c06 commit d287a87
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
13 changes: 12 additions & 1 deletion build.sh
Expand Up @@ -17,7 +17,7 @@
set -e
set -o pipefail

execs="start delete"
execs="start delete serial_bridge serial_start"

# Clean the repo, but save the vendor area
if [ "x${1:-}" != "x" ] && [ "clean" == "$1" ]; then
Expand Down Expand Up @@ -53,6 +53,17 @@ for i in $execs; do
cp files/$i target/usr/share/runX
done

cd gobuild
if [[ $ARCH = "x86" ]]
then
make GOARCH=amd64
else
make GOARCH=$ARCH
fi
cd -
cp gobuild/serial_fd_handler target/usr/share/runX/
cp gobuild/recvtty target/usr/share/runX/

mkdir -p target/usr/sbin
cp runX target/usr/sbin

Expand Down
31 changes: 31 additions & 0 deletions gobuild/Makefile
@@ -0,0 +1,31 @@
GOPATH=$(shell pwd)/go
GOSRC=${GOPATH}/src
GODEPS=github.com/opencontainers/runc
GODEPPATHS=$(addprefix ${GOSRC}/,${GODEPS})
MAIN=src/serial_fd_handler.go go/src/github.com/opencontainers/runc/contrib/cmd/recvtty/recvtty.go
BIN=$(basename $(notdir ${MAIN}))

ifdef GOARCH
ARCH=GOARCH=${GOARCH}
else
ARCH=
endif

.PHONY: clean all dep

all: ${BIN}

dep: ${GODEPPATHS}

${GODEPPATHS}:
mkdir -p ${GOSRC}
GOPATH=${GOPATH} go get $(subst ${GOSRC}/,,$@)

${BIN}: ${GODEPPATHS} $(filter %/$@.go, ${MAIN})
GOPATH=${GOPATH} ${ARCH} go build $(filter %/$@.go, ${MAIN})

clean:
rm -f ${BIN}

distclean:
rm -rf ${BIN} ${GOPATH}
51 changes: 51 additions & 0 deletions gobuild/src/serial_fd_handler.go
@@ -0,0 +1,51 @@
package main

import (
"fmt"
"time"
"net"
"os"
"github.com/opencontainers/runc/libcontainer/utils"
)

func main() {

//socket_file, err := os.Open(os.Args[1])
socket_conn, err := net.Dial("unix", os.Args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}

socket_fd, ok := socket_conn.(*net.UnixConn)
if !ok {
fmt.Errorf("failed to cast to fd")
os.Exit(1)
}

socket_file, err := socket_fd.File()
if err != nil {
fmt.Errorf("failed to cast to file")
os.Exit(1)
}

xen_file, err := os.OpenFile(os.Args[2], os.O_RDWR, 0755)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
xen_fd := xen_file.Fd()

//need FD? Name?

err = utils.SendFd(socket_file, os.Args[2], xen_fd);
if err != nil {
fmt.Println(err)
os.Exit(1)
}

//give containerd enough to get the info and then exit
time.Sleep(20 * time.Second)

return
}

0 comments on commit d287a87

Please sign in to comment.