multierror
This commit is contained in:
parent
37b665fa03
commit
0baf79e48f
12
daemon.go
12
daemon.go
|
@ -3,6 +3,7 @@ package p2pd
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/libp2p/go-libp2p-daemon/config"
|
||||
"os"
|
||||
"sync"
|
||||
|
@ -157,23 +158,24 @@ func clearUnixSockets(path ma.Multiaddr) error {
|
|||
if err := os.Remove(c.Value()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Daemon) Close() error {
|
||||
var merr multierror.Error
|
||||
if err := d.host.Close(); err != nil {
|
||||
return err
|
||||
merr = *multierror.Append(err)
|
||||
}
|
||||
|
||||
listenAddr := d.listener.Multiaddr()
|
||||
if err := d.listener.Close(); err != nil {
|
||||
return err
|
||||
merr = *multierror.Append(&merr, err)
|
||||
}
|
||||
|
||||
if err := clearUnixSockets(listenAddr); err != nil {
|
||||
return err
|
||||
merr = *multierror.Append(&merr, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return multierror.Flatten(&merr)
|
||||
}
|
||||
|
|
1
go.mod
1
go.mod
|
@ -2,6 +2,7 @@ module github.com/libp2p/go-libp2p-daemon
|
|||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.2.1
|
||||
github.com/hashicorp/go-multierror v1.0.0
|
||||
github.com/ipfs/go-cid v0.0.1
|
||||
github.com/ipfs/go-log v0.0.1
|
||||
github.com/libp2p/go-libp2p v0.0.16
|
||||
|
|
|
@ -11,16 +11,16 @@ import (
|
|||
|
||||
func (d *Daemon) trapSignals() {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGUSR1, syscall.SIGINT, syscall.SIGTERM, syscall.SIGABRT)
|
||||
signal.Notify(ch, syscall.SIGUSR1, syscall.SIGINT, syscall.SIGTERM)
|
||||
for {
|
||||
select {
|
||||
case s := <-ch:
|
||||
switch s {
|
||||
case syscall.SIGUSR1:
|
||||
d.handleSIGUSR1()
|
||||
case syscall.SIGINT, syscall.SIGTERM, syscall.SIGABRT:
|
||||
case syscall.SIGINT, syscall.SIGTERM:
|
||||
d.Close()
|
||||
os.Exit(int(s.(syscall.Signal)))
|
||||
os.Exit(0x80 + int(s.(syscall.Signal)))
|
||||
default:
|
||||
log.Warningf("uncaught signal %d", s)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue