func (c *cwrapperImpl) init(msg *logger.Logger) error { var err error if spawnCwrapper { err = c.startCWrapper(msg) if err != nil { return err } } else { go func() { c.quit <- struct{}{} }() } msg.Infof("... starting tcp server ...\n") c.lst, err = net.Listen("tcp", fmt.Sprintf(":%d", c.port)) if err != nil { msg.Errorf("error starting tcp server: %v\n", err) return err } msg.Infof("... waiting for a connection ...\n") c.conn, err = c.lst.Accept() if err != nil { msg.Errorf("error accepting connection: %v\n", err) return err } return err }
func (c *cwrapperImpl) startCWrapper(msg *logger.Logger) error { host, err := c.host(msg) if err != nil { return err } msg.Infof("Starting c-wrapper on PC-104... (listen for %s:%d)\n", host, c.port) cmd := exec.Command( "ssh", "-X", "*****@*****.**", "/root/bin/startCWrapper --host="+host, fmt.Sprintf("--port=%d", c.port), ) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "TERM=vt100") //cmd.Stdin = os.Stdin //cmd.Stdout = os.Stderr //cmd.Stderr = os.Stderr cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} msg.Infof("c-wrapper command: %v\n", cmd.Args) c.proc = cmd err = c.proc.Start() if err != nil { msg.Errorf("error starting c-wrapper: %v\n", err) return err } go func() { select { case <-c.quit: c.errc <- c.proc.Process.Kill() } }() return err }