suite for cross compile

ws
dingjun 4 years ago
parent c8c4161bb4
commit 650abc6734

@ -168,20 +168,8 @@ func (cc *Client) Shell() error {
return err return err
} }
ch := make(chan os.Signal, 2) // register console change signal
signal.Notify(ch, syscall.SIGWINCH) consoleChange(_console, session)
go func() {
for {
select {
case <-ch:
ws, _ := _console.Size()
_winCh := windowChange{Rows: uint32(ws.Height), Columns: uint32(ws.Width)}
d := ssh.Marshal(_winCh)
ok, err := session.SendRequest("window-change", true, d)
log.Debugf("send window change request %+v %+v", ok, err)
}
}
}()
session.Stdin = _console session.Stdin = _console
session.Stdout = os.Stdout session.Stdout = os.Stdout

@ -0,0 +1,22 @@
// +build windows
package obfssh
import (
"errors"
"syscall"
"github.com/containerd/console"
"golang.org/x/crypto/ssh"
)
func consoleChange(_console console.Console, session *ssh.Session) {
}
func newPty() (console.Console, string, error) {
return nil, "", errors.New("not supported")
}
func setProcAttr(attr *syscall.SysProcAttr) {
}

@ -0,0 +1,39 @@
// +build darwin freebsd linux openbsd solaris
package obfssh
import (
"os"
"os/signal"
"syscall"
"github.com/containerd/console"
"github.com/fangdingjun/go-log/v5"
"golang.org/x/crypto/ssh"
)
func consoleChange(_console console.Console, session *ssh.Session) {
ch := make(chan os.Signal, 2)
signal.Notify(ch, syscall.SIGWINCH)
go func() {
for {
select {
case <-ch:
ws, _ := _console.Size()
_winCh := windowChange{Rows: uint32(ws.Height), Columns: uint32(ws.Width)}
d := ssh.Marshal(_winCh)
ok, err := session.SendRequest("window-change", true, d)
log.Debugf("send window change request %+v %+v", ok, err)
}
}
}()
}
func newPty() (console.Console, string, error) {
return console.NewPty()
}
func setProcAttr(attr *syscall.SysProcAttr) {
attr.Setsid = true
attr.Setctty = true
}

@ -234,7 +234,7 @@ func (sc *Server) handleSession(newch ssh.NewChannel) {
} }
log.Debugf("pty req %+v", _ptyReq) log.Debugf("pty req %+v", _ptyReq)
if err == nil && (runtime.GOOS == "unix" || runtime.GOOS == "linux") { if err == nil && (runtime.GOOS == "unix" || runtime.GOOS == "linux") {
_console, ptsname, err = console.NewPty() _console, ptsname, err = newPty()
if err == nil { if err == nil {
log.Debugf("allocate pty %s", ptsname) log.Debugf("allocate pty %s", ptsname)
env = append(env, fmt.Sprintf("SSH_TTY=%s", ptsname)) env = append(env, fmt.Sprintf("SSH_TTY=%s", ptsname))
@ -321,9 +321,8 @@ func handleShell(cmd *exec.Cmd, ch ssh.Channel, _console console.Console, ptsnam
if cmd.SysProcAttr == nil { if cmd.SysProcAttr == nil {
cmd.SysProcAttr = &syscall.SysProcAttr{} cmd.SysProcAttr = &syscall.SysProcAttr{}
} }
cmd.SysProcAttr.Setsid = true
cmd.SysProcAttr.Setctty = true setProcAttr(cmd.SysProcAttr)
// cmd.SysProcAttr.Ctty = int(_tty.Fd())
go io.Copy(ch, _console) go io.Copy(ch, _console)
go io.Copy(_console, ch) go io.Copy(_console, ch)

Loading…
Cancel
Save