summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorMihai Parparita <mihai@tailscale.com>2022-05-19 17:40:01 -0700
committerMihai Parparita <mihai.parparita@gmail.com>2022-05-19 20:49:34 -0700
commiteda647cb47dc0f8dea58cb6127944fdd071990fd (patch)
treee09d4a43f6a94682d64e67bf25f31471f95d309f /cmd
parentcc91a05686e0212584562d6886df4fcb3421d38f (diff)
downloadtailscale-eda647cb47dc0f8dea58cb6127944fdd071990fd.tar.xz
tailscale-eda647cb47dc0f8dea58cb6127944fdd071990fd.zip
cmd/tailscale/cli: fix ssh CLI command breaking the Wasm build
Adds a stub for syscall.Exec when GOOS=js. We also had a separate branch for Windows, might as well use the same mechanism there too. For #3157 Signed-off-by: Mihai Parparita <mihai@tailscale.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/tailscale/cli/ssh.go20
-rw-r--r--cmd/tailscale/cli/ssh_exec.go21
-rw-r--r--cmd/tailscale/cli/ssh_exec_js.go13
-rw-r--r--cmd/tailscale/cli/ssh_exec_windows.go25
4 files changed, 60 insertions, 19 deletions
diff --git a/cmd/tailscale/cli/ssh.go b/cmd/tailscale/cli/ssh.go
index d1d0c2b78..703385ab2 100644
--- a/cmd/tailscale/cli/ssh.go
+++ b/cmd/tailscale/cli/ssh.go
@@ -16,7 +16,6 @@ import (
"path/filepath"
"runtime"
"strings"
- "syscall"
"github.com/peterbourgon/ff/v3/ffcli"
"inet.af/netaddr"
@@ -116,24 +115,7 @@ func runSSH(ctx context.Context, args []string) error {
log.Printf("Running: %q, %q ...", ssh, argv)
}
- if runtime.GOOS == "windows" {
- // Don't use syscall.Exec on Windows.
- cmd := exec.Command(ssh, argv[1:]...)
- cmd.Stdin = os.Stdin
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- var ee *exec.ExitError
- err := cmd.Run()
- if errors.As(err, &ee) {
- os.Exit(ee.ExitCode())
- }
- return err
- }
-
- if err := syscall.Exec(ssh, argv, os.Environ()); err != nil {
- return err
- }
- return errors.New("unreachable")
+ return execSSH(ssh, argv)
}
func writeKnownHosts(st *ipnstate.Status) (knownHostsFile string, err error) {
diff --git a/cmd/tailscale/cli/ssh_exec.go b/cmd/tailscale/cli/ssh_exec.go
new file mode 100644
index 000000000..02fbde61f
--- /dev/null
+++ b/cmd/tailscale/cli/ssh_exec.go
@@ -0,0 +1,21 @@
+// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build !js && !windows
+// +build !js,!windows
+
+package cli
+
+import (
+ "errors"
+ "os"
+ "syscall"
+)
+
+func execSSH(ssh string, argv []string) error {
+ if err := syscall.Exec(ssh, argv, os.Environ()); err != nil {
+ return err
+ }
+ return errors.New("unreachable")
+}
diff --git a/cmd/tailscale/cli/ssh_exec_js.go b/cmd/tailscale/cli/ssh_exec_js.go
new file mode 100644
index 000000000..bc1a97e7c
--- /dev/null
+++ b/cmd/tailscale/cli/ssh_exec_js.go
@@ -0,0 +1,13 @@
+// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cli
+
+import (
+ "errors"
+)
+
+func execSSH(ssh string, argv []string) error {
+ return errors.New("Not implemented")
+}
diff --git a/cmd/tailscale/cli/ssh_exec_windows.go b/cmd/tailscale/cli/ssh_exec_windows.go
new file mode 100644
index 000000000..1905fff39
--- /dev/null
+++ b/cmd/tailscale/cli/ssh_exec_windows.go
@@ -0,0 +1,25 @@
+// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cli
+
+import (
+ "errors"
+ "os"
+ "os/exec"
+)
+
+func execSSH(ssh string, argv []string) error {
+ // Don't use syscall.Exec on Windows, it's not fully implemented.
+ cmd := exec.Command(ssh, argv[1:]...)
+ cmd.Stdin = os.Stdin
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ var ee *exec.ExitError
+ err := cmd.Run()
+ if errors.As(err, &ee) {
+ os.Exit(ee.ExitCode())
+ }
+ return err
+}