From 07b7f94278848a2e01f396d68ee01a9ee22778ca Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Mon, 19 Aug 2024 11:41:23 -0400 Subject: [PATCH] Use actual systray error instead of const string --- ee/desktop/runner/runner.go | 2 +- ee/desktop/runner/runner_darwin.go | 5 +++++ ee/desktop/runner/runner_linux.go | 5 +++++ ee/desktop/runner/runner_windows.go | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ee/desktop/runner/runner.go b/ee/desktop/runner/runner.go index 94d2fc1a17..d794577527 100644 --- a/ee/desktop/runner/runner.go +++ b/ee/desktop/runner/runner.go @@ -950,7 +950,7 @@ func (r *DesktopUsersProcessesRunner) processLogs(uid string, stdErr io.ReadClos // Check to see if the log line contains systrayNeedsRestartErr. // systray is not able to self-recover from the systrayNeedsRestartErr, // so if we see it even once, we should take action. - if !strings.Contains(logLine, systrayNeedsRestartErr) { + if !logIndicatesSystrayNeedsRestart(logLine) { continue } diff --git a/ee/desktop/runner/runner_darwin.go b/ee/desktop/runner/runner_darwin.go index 1962f1c094..bc96ade249 100644 --- a/ee/desktop/runner/runner_darwin.go +++ b/ee/desktop/runner/runner_darwin.go @@ -60,3 +60,8 @@ func (r *DesktopUsersProcessesRunner) runAsUser(ctx context.Context, uid string, func osversion() (string, error) { return unix.Sysctl("kern.osrelease") } + +// logIndicatesSystrayNeedsRestart is Windows-only functionality +func logIndicatesSystrayNeedsRestart(_ string) bool { + return false +} diff --git a/ee/desktop/runner/runner_linux.go b/ee/desktop/runner/runner_linux.go index 89d80e67d7..dcf4aee650 100644 --- a/ee/desktop/runner/runner_linux.go +++ b/ee/desktop/runner/runner_linux.go @@ -387,3 +387,8 @@ func getXdgRuntimeDir(uid string) string { func osversion() (string, error) { return "", errors.New("not implemented") } + +// logIndicatesSystrayNeedsRestart is Windows-only functionality +func logIndicatesSystrayNeedsRestart(_ string) bool { + return false +} diff --git a/ee/desktop/runner/runner_windows.go b/ee/desktop/runner/runner_windows.go index 0dea21cf3d..804f4c4fc1 100644 --- a/ee/desktop/runner/runner_windows.go +++ b/ee/desktop/runner/runner_windows.go @@ -8,10 +8,12 @@ import ( "errors" "fmt" "os/exec" + "strings" "syscall" "github.com/kolide/launcher/ee/consoleuser" "github.com/kolide/launcher/pkg/traces" + "github.com/kolide/systray" ) func (r *DesktopUsersProcessesRunner) runAsUser(ctx context.Context, uid string, cmd *exec.Cmd) error { @@ -64,3 +66,10 @@ func processAccessToken(pid int32) (syscall.Token, error) { func osversion() (string, error) { return "", errors.New("not implemented") } + +// logIndicatesSystrayNeedsRestart checks to see if the log line contains +// "tray not ready yet", which indicates that the systray had an irrecoverable +// error during initialization and requires restart. +func logIndicatesSystrayNeedsRestart(logLine string) bool { + return strings.Contains(logLine, systray.ErrTrayNotReadyYet.Error()) +}