-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from libp2p/feat/signal-dump
handle SIGUSR1 as a signal to dump state
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |