9 "github.com/docker/go-p9p"
10 "golang.org/x/net/context"
19 flag.StringVar(&root, "root", "~/", "root of filesystem to serve over 9p")
20 flag.StringVar(&addr, "addr", ":5640", "bind addr for 9p server, prefix with unix: for unix socket")
24 ctx := context.Background()
29 if strings.HasPrefix(addr, "unix:") {
34 listener, err := net.Listen(proto, addr)
36 log.Fatalln("error listening:", err)
38 defer listener.Close()
41 c, err := listener.Accept()
43 log.Fatalln("error accepting:", err)
47 go func(conn net.Conn) {
50 ctx := context.WithValue(ctx, "conn", conn)
51 log.Println("connected", conn.RemoteAddr())
52 session, err := newLocalSession(ctx, root)
54 log.Println("error creating session")
58 if err := p9p.ServeConn(ctx, conn, p9p.Dispatch(session)); err != nil {
59 log.Printf("serving conn: %v", err)
65 // newLocalSession returns a session to serve the local filesystem, restricted
66 // to the provided root.
67 func newLocalSession(ctx context.Context, root string) (p9p.Session, error) {
68 // silly, just connect to ufs for now! replace this with real code later!
69 log.Println("dialing", ":5640", "for", ctx.Value("conn"))
70 conn, err := net.Dial("tcp", ":5640")
75 session, err := p9p.NewSession(ctx, conn)