ipn/ipnlocal: make peerapi work on iOS again

It didn't have a storage directory.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/1622/head
Brad Fitzpatrick 3 years ago
parent 31c7745631
commit c3bee0b722

@ -1510,6 +1510,20 @@ func (b *LocalBackend) authReconfig() {
b.initPeerAPIListener() b.initPeerAPIListener()
} }
// tailscaleVarRoot returns the root directory of Tailscale's writable
// storage area. (e.g. "/var/lib/tailscale")
func tailscaleVarRoot() string {
if runtime.GOOS == "ios" {
dir, _ := paths.IOSSharedDir.Load().(string)
return dir
}
stateFile := paths.DefaultTailscaledStateFile()
if stateFile == "" {
return ""
}
return filepath.Dir(stateFile)
}
func (b *LocalBackend) initPeerAPIListener() { func (b *LocalBackend) initPeerAPIListener() {
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
@ -1525,15 +1539,15 @@ func (b *LocalBackend) initPeerAPIListener() {
return return
} }
stateFile := paths.DefaultTailscaledStateFile() varRoot := tailscaleVarRoot()
if stateFile == "" { if varRoot == "" {
b.logf("peerapi disabled; no state directory") b.logf("peerapi disabled; no state directory")
return return
} }
baseDir := fmt.Sprintf("%s-uid-%d", baseDir := fmt.Sprintf("%s-uid-%d",
strings.ReplaceAll(b.activeLogin, "@", "-"), strings.ReplaceAll(b.activeLogin, "@", "-"),
selfNode.User) selfNode.User)
dir := filepath.Join(filepath.Dir(stateFile), "files", baseDir) dir := filepath.Join(varRoot, "files", baseDir)
if err := os.MkdirAll(dir, 0700); err != nil { if err := os.MkdirAll(dir, 0700); err != nil {
b.logf("peerapi disabled; error making directory: %v", err) b.logf("peerapi disabled; error making directory: %v", err)
return return

@ -10,8 +10,13 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sync/atomic"
) )
// IOSSharedDir is a string set by the iOS app on start
// containing a directory we can read/write in.
var IOSSharedDir atomic.Value
// LegacyConfigPath returns the path used by the pre-tailscaled // LegacyConfigPath returns the path used by the pre-tailscaled
// "relaynode" daemon's config file. It returns the empty string for // "relaynode" daemon's config file. It returns the empty string for
// platforms where relaynode never ran. // platforms where relaynode never ran.

Loading…
Cancel
Save