mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-06 07:37:38 +00:00
tailscaled: revert to using pointers for subcommands
As part of #10631, we stopped using function pointers for subcommands, preventing us from registering platform-specific installSystemDaemon and uninstallSystemDaemon subcommands. Fixes #11099 Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:
parent
87154a2f88
commit
55b372a79f
@ -136,12 +136,16 @@ var (
|
|||||||
createBIRDClient func(string) (wgengine.BIRDClient, error) // non-nil on some platforms
|
createBIRDClient func(string) (wgengine.BIRDClient, error) // non-nil on some platforms
|
||||||
)
|
)
|
||||||
|
|
||||||
var subCommands = map[string]func([]string) error{
|
// Note - we use function pointers for subcommands so that subcommands like
|
||||||
"install-system-daemon": installSystemDaemon,
|
// installSystemDaemon and uninstallSystemDaemon can be assigned platform-
|
||||||
"uninstall-system-daemon": uninstallSystemDaemon,
|
// specific variants.
|
||||||
"debug": debugModeFunc,
|
|
||||||
"be-child": beChild,
|
var subCommands = map[string]*func([]string) error{
|
||||||
"serve-tailfs": serveTailFS,
|
"install-system-daemon": &installSystemDaemon,
|
||||||
|
"uninstall-system-daemon": &uninstallSystemDaemon,
|
||||||
|
"debug": &debugModeFunc,
|
||||||
|
"be-child": &beChildFunc,
|
||||||
|
"serve-tailfs": &serveTailFSFunc,
|
||||||
}
|
}
|
||||||
|
|
||||||
var beCLI func() // non-nil if CLI is linked in
|
var beCLI func() // non-nil if CLI is linked in
|
||||||
@ -173,12 +177,12 @@ func main() {
|
|||||||
|
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
sub := os.Args[1]
|
sub := os.Args[1]
|
||||||
if fn, ok := subCommands[sub]; ok {
|
if fp, ok := subCommands[sub]; ok {
|
||||||
if fn == nil {
|
if fp == nil {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
log.Fatalf("%s not available on %v", sub, runtime.GOOS)
|
log.Fatalf("%s not available on %v", sub, runtime.GOOS)
|
||||||
}
|
}
|
||||||
if err := fn(os.Args[2:]); err != nil {
|
if err := (*fp)(os.Args[2:]); err != nil {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -799,6 +803,8 @@ func mustStartProxyListeners(socksAddr, httpAddr string) (socksListener, httpLis
|
|||||||
return socksListener, httpListener
|
return socksListener, httpListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var beChildFunc = beChild
|
||||||
|
|
||||||
func beChild(args []string) error {
|
func beChild(args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return errors.New("missing mode argument")
|
return errors.New("missing mode argument")
|
||||||
@ -811,6 +817,8 @@ func beChild(args []string) error {
|
|||||||
return f(args[1:])
|
return f(args[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var serveTailFSFunc = serveTailFS
|
||||||
|
|
||||||
// serveTailFS serves one or more tailfs on localhost using the WebDAV
|
// serveTailFS serves one or more tailfs on localhost using the WebDAV
|
||||||
// protocol. On UNIX and MacOS tailscaled environment, tailfs spawns child
|
// protocol. On UNIX and MacOS tailscaled environment, tailfs spawns child
|
||||||
// tailscaled processes in serve-tailfs mode in order to access the fliesystem
|
// tailscaled processes in serve-tailfs mode in order to access the fliesystem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user