From 7b1c764088673cfe17e2a8695170cdec8cfc47fd Mon Sep 17 00:00:00 2001 From: Andrew Lytvynov Date: Mon, 8 Jul 2024 16:40:06 -0700 Subject: [PATCH] ipn/ipnlocal: gate systemd-run flags on systemd version (#12747) We added a workaround for --wait, but didn't confirm the other flags, which were added in systemd 235 and 236. Check systemd version for deciding when to set all 3 flags. Fixes #12136 Signed-off-by: Andrew Lytvynov --- ipn/ipnlocal/c2n.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ipn/ipnlocal/c2n.go b/ipn/ipnlocal/c2n.go index 44dc4a6ba..ebe07d87b 100644 --- a/ipn/ipnlocal/c2n.go +++ b/ipn/ipnlocal/c2n.go @@ -441,9 +441,13 @@ func tailscaleUpdateCmd(cmdTS string) *exec.Cmd { // tailscaled is restarted during the update, systemd won't kill this // temporary update unit, which could cause unexpected breakage. // - // We want to use the --wait flag for systemd-run, to block the update - // command until completion and collect output. But this flag was added in - // systemd 232, so we need to check the version first. + // We want to use a few optional flags: + // * --wait, to block the update command until completion (added in systemd 232) + // * --pipe, to collect stdout/stderr (added in systemd 235) + // * --collect, to clean up failed runs from memory (added in systemd 236) + // + // We need to check the version of systemd to figure out if those flags are + // available. // // The output will look like: // @@ -461,10 +465,14 @@ func tailscaleUpdateCmd(cmdTS string) *exec.Cmd { if err != nil { return defaultCmd } - if systemdVer < 232 { - return exec.Command("systemd-run", "--pipe", "--collect", cmdTS, "update", "--yes") - } else { + if systemdVer >= 236 { return exec.Command("systemd-run", "--wait", "--pipe", "--collect", cmdTS, "update", "--yes") + } else if systemdVer >= 235 { + return exec.Command("systemd-run", "--wait", "--pipe", cmdTS, "update", "--yes") + } else if systemdVer >= 232 { + return exec.Command("systemd-run", "--wait", cmdTS, "update", "--yes") + } else { + return exec.Command("systemd-run", cmdTS, "update", "--yes") } }