go-libp2p-daemon/trap_posix.go

35 lines
561 B
Go
Raw Normal View History

2019-02-14 16:26:05 +00:00
// +build !windows,!plan9,!nacl,!js
package p2pd
import (
"os"
"os/signal"
"syscall"
)
func (d *Daemon) trapSignals() {
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()
}
}