Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle SIGUSR1 as a signal to dump state #69

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewDaemon(ctx context.Context, maddr ma.Multiaddr, dhtEnabled bool, dhtClie
d.listener = l

go d.listen()
go d.trapSignals()

return d, nil
}
Expand Down
8 changes: 8 additions & 0 deletions trap_nonposix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build windows plan9 nacl js

package p2pd

func (d *Daemon) trapSignals() {
// TODO: define signals we want to trap on Windows, if any.
return
}
34 changes: 34 additions & 0 deletions trap_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +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()
}
}