multierror

This commit is contained in:
Mantas Vidutis 2019-04-24 09:27:56 -07:00
parent 37b665fa03
commit 0baf79e48f
3 changed files with 11 additions and 8 deletions

View File

@ -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
View File

@ -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

View File

@ -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)
}