From 1543e233e61374975dadb8a331f763cbda61e336 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 11 Jun 2023 17:36:26 -0700 Subject: [PATCH] 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 --- net/tstun/tun.go | 2 +- tsnet/tsnet.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/net/tstun/tun.go b/net/tstun/tun.go index 57912c79a..b31ffa7ca 100644 --- a/net/tstun/tun.go +++ b/net/tstun/tun.go @@ -1,7 +1,7 @@ // Copyright (c) Tailscale Inc & AUTHORS // SPDX-License-Identifier: BSD-3-Clause -//go:build !js +//go:build !wasm // Package tun creates a tuntap device, working around OS-specific // quirks if necessary. diff --git a/tsnet/tsnet.go b/tsnet/tsnet.go index eec421bfc..3c4860b44 100644 --- a/tsnet/tsnet.go +++ b/tsnet/tsnet.go @@ -22,6 +22,7 @@ import ( "net/netip" "os" "path/filepath" + "runtime" "strconv" "strings" "sync" @@ -441,7 +442,16 @@ func (s *Server) start() (reterr error) { exe, err := os.Executable() 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")