fyne-io / systray

a cross platfrom Go library to place an icon and menu in the notification area
Apache License 2.0
245 stars 49 forks source link

Error connecting to DBUS when running as root #37

Closed Jacalz closed 1 year ago

Jacalz commented 1 year ago

Opening this here as part of issues raised over at fyne-io/fyne in https://github.com/fyne-io/fyne/issues/3120. It seems like we are getting a nil object because we can't connect to the DBUS interface and are thus crashing. We should add check and fail gracefully instead.

Stack trace from the issue above:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x8cfb76]

goroutine 1 [running, locked to thread]:
github.com/godbus/dbus/v5.(*Conn).export(0xc0005f3860?, 0xc0005f3830?, {0xa138af?, 0x6?}, {0xa1b4de?, 0x10?}, 0xb?)
        /home/fizlast/go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/export.go:383 +0x36
github.com/godbus/dbus/v5.(*Conn).exportMethodTable(0x984a80?, 0xc0005f3a88?, {0xa138af?, 0x13?}, {0xa1b4de?, 0x1a?}, 0x30?)
        /home/fizlast/go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/export.go:367 +0x11b
github.com/godbus/dbus/v5.(*Conn).ExportSubtreeMethodTable(...)
        /home/fizlast/go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/export.go:346
fyne.io/systray/internal/generated/notifier.ExportStatusNotifierItem(0x0?, {0xa138af, 0x13}, {0xb0bb20?, 0x117bcd0})
        /home/fizlast/go/pkg/mod/fyne.io/systray@v1.10.1-0.20220621085403-9a2652634e93/internal/generated/notifier/status_notifier_item.go:192 +0x338
fyne.io/systray.nativeStart()
        /home/fizlast/go/pkg/mod/fyne.io/systray@v1.10.1-0.20220621085403-9a2652634e93/systray_unix.go:168 +0x69
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).runGL(0xc0003e0620)
        /home/fizlast/go/pkg/mod/fyne.io/fyne/v2@v2.2.2/internal/driver/glfw/loop.go:117 +0xdb
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).Run(0xc0000003c0?)
        /home/fizlast/go/pkg/mod/fyne.io/fyne/v2@v2.2.2/internal/driver/glfw/driver.go:164 +0x33
fyne.io/fyne/v2/internal/driver/glfw.(*window).ShowAndRun(0xc0000003c0)
        /home/fizlast/go/pkg/mod/fyne.io/fyne/v2@v2.2.2/internal/driver/glfw/window.go:230 +0x2c
main.main()
        /home/fizlast/projects/temp/main.go:26 +0x236