cmd/tailscaled/childproc: add be-child registration mechanism

For ssh and maybe windows service babysitter later.

Updates #3802

Change-Id: I7492b98df98971b3fb72d148ba92c2276cca491f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/4032/head
Brad Fitzpatrick 2 years ago committed by Brad Fitzpatrick
parent 6e4f3614cf
commit 4cbdc84d27

@ -0,0 +1,20 @@
// 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 childproc allows other packages to register "tailscaled be-child"
// child process hook code. This avoids duplicating build tags in the
// tailscaled package. Instead, the code that needs to fork/exec the self
// executable (when it's tailscaled) can instead register the code
// they want to run.
package childproc
var Code = map[string]func([]string) error{}
// Add registers code f to run as 'tailscaled be-child <typ> [args]'.
func Add(typ string, f func(args []string) error) {
if _, dup := Code[typ]; dup {
panic("dup hook " + typ)
}
Code[typ] = f
}

@ -168,6 +168,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
LD tailscale.com/chirp from tailscale.com/cmd/tailscaled
tailscale.com/client/tailscale from tailscale.com/derp
tailscale.com/client/tailscale/apitype from tailscale.com/client/tailscale+
tailscale.com/cmd/tailscaled/childproc from tailscale.com/cmd/tailscaled+
tailscale.com/control/controlclient from tailscale.com/ipn/ipnlocal+
tailscale.com/control/controlknobs from tailscale.com/control/controlclient+
tailscale.com/derp from tailscale.com/derp/derphttp+

@ -28,6 +28,7 @@ import (
"time"
"inet.af/netaddr"
"tailscale.com/cmd/tailscaled/childproc"
"tailscale.com/control/controlclient"
"tailscale.com/envknob"
"tailscale.com/ipn"
@ -105,6 +106,7 @@ var subCommands = map[string]*func([]string) error{
"install-system-daemon": &installSystemDaemon,
"uninstall-system-daemon": &uninstallSystemDaemon,
"debug": &debugModeFunc,
"be-child": &beChildFunc,
}
func main() {
@ -601,3 +603,17 @@ func mustStartProxyListeners(socksAddr, httpAddr string) (socksListener, httpLis
return socksListener, httpListener
}
var beChildFunc = beChild
func beChild(args []string) error {
if len(args) == 0 {
return errors.New("missing mode argument")
}
typ := args[0]
f, ok := childproc.Code[typ]
if !ok {
return fmt.Errorf("unknown be-child mode %q", typ)
}
return f(args[1:])
}

@ -27,6 +27,7 @@ import (
"github.com/creack/pty"
"github.com/gliderlabs/ssh"
"inet.af/netaddr"
"tailscale.com/cmd/tailscaled/childproc"
"tailscale.com/envknob"
"tailscale.com/ipn/ipnlocal"
"tailscale.com/net/tsaddr"
@ -34,6 +35,15 @@ import (
"tailscale.com/types/logger"
)
func init() {
childproc.Add("ssh", sshChild)
}
func sshChild([]string) error {
fmt.Println("TODO(maisem): ssh dbus stuff")
return nil
}
// TODO(bradfitz): this is all very temporary as code is temporarily
// being moved around; it will be restructured and documented in
// following commits.

@ -13,6 +13,7 @@ import (
// process and can cache a prior success when a dependency changes.
_ "inet.af/netaddr"
_ "tailscale.com/chirp"
_ "tailscale.com/cmd/tailscaled/childproc"
_ "tailscale.com/control/controlclient"
_ "tailscale.com/derp/derphttp"
_ "tailscale.com/envknob"

@ -13,6 +13,7 @@ import (
// process and can cache a prior success when a dependency changes.
_ "inet.af/netaddr"
_ "tailscale.com/chirp"
_ "tailscale.com/cmd/tailscaled/childproc"
_ "tailscale.com/control/controlclient"
_ "tailscale.com/derp/derphttp"
_ "tailscale.com/envknob"

@ -13,6 +13,7 @@ import (
// process and can cache a prior success when a dependency changes.
_ "inet.af/netaddr"
_ "tailscale.com/chirp"
_ "tailscale.com/cmd/tailscaled/childproc"
_ "tailscale.com/control/controlclient"
_ "tailscale.com/derp/derphttp"
_ "tailscale.com/envknob"

@ -13,6 +13,7 @@ import (
// process and can cache a prior success when a dependency changes.
_ "inet.af/netaddr"
_ "tailscale.com/chirp"
_ "tailscale.com/cmd/tailscaled/childproc"
_ "tailscale.com/control/controlclient"
_ "tailscale.com/derp/derphttp"
_ "tailscale.com/envknob"

@ -16,6 +16,7 @@ import (
_ "golang.org/x/sys/windows/svc/mgr"
_ "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
_ "inet.af/netaddr"
_ "tailscale.com/cmd/tailscaled/childproc"
_ "tailscale.com/control/controlclient"
_ "tailscale.com/derp/derphttp"
_ "tailscale.com/envknob"

Loading…
Cancel
Save