Skip to content

Commit

Permalink
handle SIGUSR1 as a signal to dump state
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Feb 14, 2019
1 parent fa53c18 commit 9727bf7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package p2pd
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"

logging "github.com/ipfs/go-log"
libp2p "github.com/libp2p/go-libp2p"
Expand Down Expand Up @@ -64,6 +67,7 @@ func NewDaemon(ctx context.Context, maddr ma.Multiaddr, dhtEnabled bool, dhtClie
d.listener = l

go d.listen()
go d.handleSignals()

return d, nil
}
Expand Down Expand Up @@ -144,3 +148,28 @@ func (d *Daemon) listen() {
go d.handleConn(c)
}
}

func (d *Daemon) handleSignals() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGUSR1)
for {
select {
case s := <-ch:
switch s {
case syscall.SIGUSR1:
d.handleSIGUSR1()
default:
log.Warningf("unexpected signal %d", s)
}
case <-d.ctx.Done():
return
}
}
}

func (d *Daemon) handleSIGUSR1() {
// this is the state dump signal; for now just dht routing table if present
if d.dht != nil {
d.dht.RoutingTable().Print()
}
}

0 comments on commit 9727bf7

Please sign in to comment.