Skip to content

Commit

Permalink
core: Allow restart on panel crash, unless restarting too quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
pdf committed Mar 16, 2024
1 parent 62f69be commit 8305a3d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cmd/hyprpanel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"runtime/debug"
"syscall"
"time"

"github.com/fsnotify/fsnotify"
"github.com/hashicorp/go-hclog"
Expand All @@ -21,7 +22,9 @@ import (
)

const (
name = `hyprpanel`
name = `hyprpanel`
crashTimeout = 2 * time.Second
crashCount = 3
)

func sigHandler(log hclog.Logger, h *host) {
Expand Down Expand Up @@ -138,7 +141,6 @@ func main() {

go func() {
for {

select {
case evt := <-watcher.Events:
if !evt.Has(fsnotify.Write) && !evt.Has(fsnotify.Create) && !evt.Has(fsnotify.Remove) {
Expand Down Expand Up @@ -189,11 +191,25 @@ func main() {
}
defer plugin.CleanupClients()

count := 0
timer := time.NewTimer(crashTimeout)
for {
err := h.run()
if err != nil && err != errReload {
log.Error(`hyprpanel exiting`, `err`, err)
os.Exit(1)
count += 1
log.Error(`Clients failed`, `err`, err)
select {
case <-timer.C:
if count >= crashCount {
log.Error(`Restarting too quickly, terminating`)
os.Exit(1)
}
count = 0
timer.Reset(crashTimeout)
continue
default:
continue
}
} else if err != nil && err == errReload {
continue
}
Expand Down

0 comments on commit 8305a3d

Please sign in to comment.