-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: agent support for windows (#1741)
Signed-off-by: ANS-UXI <[email protected]> Signed-off-by: Rutik7066 <[email protected]> Co-authored-by: ANS-UXI <[email protected]>
- Loading branch information
Showing
14 changed files
with
288 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,9 @@ DEV_WORKSPACES | |
./daytona | ||
.DS_Store | ||
|
||
tmp | ||
tmp | ||
|
||
|
||
*.exe | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//go:build !windows | ||
|
||
// Copyright 2024 Daytona Platforms Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package ssh | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
"unsafe" | ||
|
||
"golang.org/x/sys/unix" | ||
|
||
"github.com/creack/pty" | ||
"github.com/gliderlabs/ssh" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func Start(cmd interface{}) (*os.File, error) { | ||
if command, ok := cmd.(*exec.Cmd); ok { | ||
f, err := pty.Start(command) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unable to start PTY: %v", err) | ||
} | ||
return f, nil | ||
} | ||
return nil, fmt.Errorf("Unable to start PTY") | ||
} | ||
|
||
func SetPtySize(f interface{}, win ssh.Window) { | ||
if file, ok := f.(*os.File); ok { | ||
syscall.Syscall(syscall.SYS_IOCTL, file.Fd(), uintptr(syscall.TIOCSWINSZ), | ||
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(win.Height), uint16(win.Width), 0, 0}))) | ||
} else { | ||
log.Errorf("Unable to resize PTY") | ||
} | ||
} | ||
|
||
func OsSignalFrom(sig ssh.Signal) os.Signal { | ||
switch sig { | ||
case ssh.SIGABRT: | ||
return unix.SIGABRT | ||
case ssh.SIGALRM: | ||
return unix.SIGALRM | ||
case ssh.SIGFPE: | ||
return unix.SIGFPE | ||
case ssh.SIGHUP: | ||
return unix.SIGHUP | ||
case ssh.SIGILL: | ||
return unix.SIGILL | ||
case ssh.SIGINT: | ||
return unix.SIGINT | ||
case ssh.SIGKILL: | ||
return unix.SIGKILL | ||
case ssh.SIGPIPE: | ||
return unix.SIGPIPE | ||
case ssh.SIGQUIT: | ||
return unix.SIGQUIT | ||
case ssh.SIGSEGV: | ||
return unix.SIGSEGV | ||
case ssh.SIGTERM: | ||
return unix.SIGTERM | ||
case ssh.SIGUSR1: | ||
return unix.SIGUSR1 | ||
case ssh.SIGUSR2: | ||
return unix.SIGUSR2 | ||
|
||
// Unhandled, use sane fallback. | ||
default: | ||
return unix.SIGKILL | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build windows | ||
|
||
// Copyright 2024 Daytona Platforms Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package ssh | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
|
||
"github.com/UserExistsError/conpty" | ||
"github.com/gliderlabs/ssh" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
kernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
setConsoleWindowInfo = kernel32.NewProc("SetConsoleWindowInfo") | ||
) | ||
|
||
func Start(cmd interface{}) (*conpty.ConPty, error) { | ||
if shell, ok := cmd.(*exec.Cmd); ok { | ||
f, err := conpty.Start(`c:\windows\system32\cmd.exe`, conpty.ConPtyEnv(shell.Env), conpty.ConPtyWorkDir(shell.Dir)) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unable to start ConPTY: %v", err) | ||
} | ||
return f, nil | ||
} | ||
return nil, fmt.Errorf("Unable to start ConPTY") | ||
} | ||
|
||
func SetPtySize(f interface{}, win ssh.Window) { | ||
if cpty, ok := f.(*conpty.ConPty); ok { | ||
cpty.Resize(win.Width, win.Height) | ||
} else { | ||
log.Errorf("Unable to resize ConPTY") | ||
} | ||
} | ||
|
||
func OsSignalFrom(sig ssh.Signal) os.Signal { | ||
switch sig { | ||
case ssh.SIGINT: | ||
return os.Interrupt | ||
case ssh.SIGTERM: | ||
return os.Kill | ||
case ssh.SIGKILL: | ||
return os.Kill | ||
default: | ||
return os.Kill | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.