net/tstun, tsnet: make happier on WASI
Also fix a js/wasm issue with tsnet in the process. (same issue as WASI) Updates #8320 Fixes #8315 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>pull/8327/head
parent
167e154bcc
commit
1543e233e6
|
@ -1,7 +1,7 @@
|
||||||
// Copyright (c) Tailscale Inc & AUTHORS
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
//go:build !js
|
//go:build !wasm
|
||||||
|
|
||||||
// Package tun creates a tuntap device, working around OS-specific
|
// Package tun creates a tuntap device, working around OS-specific
|
||||||
// quirks if necessary.
|
// quirks if necessary.
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -441,7 +442,16 @@ func (s *Server) start() (reterr error) {
|
||||||
|
|
||||||
exe, err := os.Executable()
|
exe, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
switch runtime.GOOS {
|
||||||
|
case "js", "wasip1":
|
||||||
|
// These platforms don't implement os.Executable (at least as of Go
|
||||||
|
// 1.21), but we don't really care much: it's only used as a default
|
||||||
|
// directory and hostname when they're not supplied. But we can fall
|
||||||
|
// back to "tsnet" as well.
|
||||||
|
exe = "tsnet"
|
||||||
|
default:
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prog := strings.TrimSuffix(strings.ToLower(filepath.Base(exe)), ".exe")
|
prog := strings.TrimSuffix(strings.ToLower(filepath.Base(exe)), ".exe")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue