Skip to content

Commit 2ec280d

Browse files
mortenljsechmannkimtore
committed
Make agent quit when systray quits if started by systray
Co-authored-by: Vegar Sechmann Molvig <[email protected]> Co-authored-by: Kim Tore Jensen <[email protected]>
1 parent fac9639 commit 2ec280d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/naisdevice-systray/main.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func main() {
5656
}
5757

5858
func run(ctx context.Context, notifier notify.Notifier) error {
59+
ctx, cancel := context.WithCancel(ctx)
60+
defer cancel()
61+
5962
otelCancel, err := otel.SetupOTelSDK(ctx, "naisdevice-systray", log)
6063
if err != nil {
6164
log.WithError(err).Warnf("setup OTel SDK")
@@ -104,7 +107,13 @@ func run(ctx context.Context, notifier notify.Notifier) error {
104107
span.RecordError(err)
105108
return fmt.Errorf("spawning naisdevice-agent: %w", err)
106109
}
107-
defer command.Wait()
110+
defer func() {
111+
cancel()
112+
err := command.Wait()
113+
if err != nil {
114+
log.Errorf("naisdevice-agent exited with error: %v", err)
115+
}
116+
}()
108117
} else {
109118
span.AddEvent("agent.reuse")
110119
err := conn.Close()

0 commit comments

Comments
 (0)