From 9fe21bb382484df1c3b109e92d292eaa5144102d Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Thu, 4 Sep 2025 06:36:52 -0500 Subject: [PATCH] cmd/tailscaled: actually derive statedir from statepath The documentation for `--statedir` says that if unspecified, it will be derived from `--state` if possible. It was not. In addition, if `--state` was specified, `--statedir` was not even defaulted to its usual default, so remained empty. Now, if only `--state` is specified, `--statedir` is derived from it. Updates #14025 Signed-off-by: Percy Wegmann --- cmd/tailscaled/tailscaled.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index ddf6d9ef6..cb8c09bf5 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -255,9 +255,9 @@ func main() { log.Fatalf("--bird-socket is not supported on %s", runtime.GOOS) } - // Only apply a default statepath when neither have been provided, so that a - // user may specify only --statedir if they wish. if args.statepath == "" && args.statedir == "" { + // Only apply a default statepath when neither have been provided, so that a + // user may specify only --statedir if they wish. if paths.MakeAutomaticStateDir() { d := paths.DefaultTailscaledStateDir() if d != "" { @@ -269,6 +269,9 @@ func main() { } else { args.statepath = paths.DefaultTailscaledStateFile() } + } else if args.statedir == "" && args.statepath != "" { + // When only a statepath is specified, derive statedir from statepath. + args.statedir = filepath.Dir(args.statepath) } if args.encryptState {