mirror of
https://github.com/tailscale/tailscale.git
synced 2026-02-08 09:12:00 +01:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
140 lines
3.6 KiB
Go
140 lines
3.6 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !ios
|
|
|
|
package version
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
"path"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// CmdName returns either the base name of the current binary
|
|
// using os.Executable. If os.Executable fails (it shouldn't), then
|
|
// "cmd" is returned.
|
|
func CmdName() string {
|
|
e, err := os.Executable()
|
|
if err != nil {
|
|
return "cmd"
|
|
}
|
|
return cmdName(e)
|
|
}
|
|
|
|
func cmdName(exe string) string {
|
|
// fallbackName, the lowercase basename of the executable, is what we return if
|
|
// we can't find the Go module metadata embedded in the file.
|
|
fallbackName := prepExeNameForCmp(exe, runtime.GOARCH)
|
|
|
|
var ret string
|
|
info, err := findModuleInfo(exe)
|
|
if err != nil {
|
|
return fallbackName
|
|
}
|
|
// v is like:
|
|
// "path\ttailscale.com/cmd/tailscale\nmod\ttailscale.com\t(devel)\t\ndep\tgithub.com/apenwarr/fixconsole\tv0.0.0-20191012055117-5a9f6489cc29\th1:muXWUcay7DDy1/hEQWrYlBy+g0EuwT70sBHg65SeUc4=\ndep\tgithub....
|
|
for _, line := range strings.Split(info, "\n") {
|
|
if goPkg, ok := strings.CutPrefix(line, "path\t"); ok { // like "tailscale.com/cmd/tailscale"
|
|
ret = path.Base(goPkg) // goPkg is always forward slashes; use path, not filepath
|
|
break
|
|
}
|
|
}
|
|
if runtime.GOOS == "windows" && strings.HasPrefix(ret, "gui") && checkPreppedExeNameForGUI(fallbackName) {
|
|
// The GUI binary for internal build system packaging reasons
|
|
// has a path of "tailscale.io/win/gui".
|
|
// Ignore that name and use fallbackName instead.
|
|
return fallbackName
|
|
}
|
|
if ret == "" {
|
|
return fallbackName
|
|
}
|
|
return ret
|
|
}
|
|
|
|
// findModuleInfo returns the Go module info from the executable file.
|
|
func findModuleInfo(file string) (s string, err error) {
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer f.Close()
|
|
// Scan through f until we find infoStart.
|
|
buf := make([]byte, 65536)
|
|
start, err := findOffset(f, buf, infoStart)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
start += int64(len(infoStart))
|
|
// Seek to the end of infoStart and scan for infoEnd.
|
|
_, err = f.Seek(start, io.SeekStart)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
end, err := findOffset(f, buf, infoEnd)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
length := end - start
|
|
// As of Aug 2021, tailscaled's mod info was about 2k.
|
|
if length > int64(len(buf)) {
|
|
return "", errors.New("mod info too large")
|
|
}
|
|
// We have located modinfo. Read it into buf.
|
|
buf = buf[:length]
|
|
_, err = f.Seek(start, io.SeekStart)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
_, err = io.ReadFull(f, buf)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(buf), nil
|
|
}
|
|
|
|
// findOffset finds the absolute offset of needle in f,
|
|
// starting at f's current read position,
|
|
// using temporary buffer buf.
|
|
func findOffset(f *os.File, buf, needle []byte) (int64, error) {
|
|
for {
|
|
// Fill buf and look within it.
|
|
n, err := f.Read(buf)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
i := bytes.Index(buf[:n], needle)
|
|
if i < 0 {
|
|
// Not found. Rewind a little bit in case we happened to end halfway through needle.
|
|
rewind, err := f.Seek(int64(-len(needle)), io.SeekCurrent)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
// If we're at EOF and rewound exactly len(needle) bytes, return io.EOF.
|
|
_, err = f.ReadAt(buf[:1], rewind+int64(len(needle)))
|
|
if err == io.EOF {
|
|
return -1, err
|
|
}
|
|
continue
|
|
}
|
|
// Found! Figure out exactly where.
|
|
cur, err := f.Seek(0, io.SeekCurrent)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
return cur - int64(n) + int64(i), nil
|
|
}
|
|
}
|
|
|
|
// These constants are taken from rsc.io/goversion.
|
|
|
|
var (
|
|
infoStart, _ = hex.DecodeString("3077af0c9274080241e1c107e6d618e6")
|
|
infoEnd, _ = hex.DecodeString("f932433186182072008242104116d8f2")
|
|
)
|