Review feedback.
1. Moves the log message for each socket to the appropriate _unix and _windows.go 2. Replaces all reference to Abstract Socket for Windows. 3. Adds support for ctrl+c on Windows to exit a shim. Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
parent
4b5403f9c9
commit
af1b6a026e
@ -202,11 +202,10 @@ func (s *Client) Serve() error {
|
|||||||
// serve serves the ttrpc API over a unix socket at the provided path
|
// serve serves the ttrpc API over a unix socket at the provided path
|
||||||
// this function does not block
|
// this function does not block
|
||||||
func serve(ctx context.Context, server *ttrpc.Server, path string) error {
|
func serve(ctx context.Context, server *ttrpc.Server, path string) error {
|
||||||
l, path, err := serveListener(path)
|
l, err := serveListener(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.WithField("socket", path).Debug("serving api on abstract socket")
|
|
||||||
go func() {
|
go func() {
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
if err := server.Serve(ctx, l); err != nil &&
|
if err := server.Serve(ctx, l); err != nil &&
|
||||||
|
@ -47,7 +47,7 @@ func setupDumpStacks(dump chan<- os.Signal) {
|
|||||||
signal.Notify(dump, syscall.SIGUSR1)
|
signal.Notify(dump, syscall.SIGUSR1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveListener(path string) (net.Listener, string, error) {
|
func serveListener(path string) (net.Listener, error) {
|
||||||
var (
|
var (
|
||||||
l net.Listener
|
l net.Listener
|
||||||
err error
|
err error
|
||||||
@ -57,14 +57,15 @@ func serveListener(path string) (net.Listener, string, error) {
|
|||||||
path = "[inherited from parent]"
|
path = "[inherited from parent]"
|
||||||
} else {
|
} else {
|
||||||
if len(path) > 106 {
|
if len(path) > 106 {
|
||||||
return nil, path, errors.Errorf("%q: unix socket path too long (> 106)", path)
|
return nil, errors.Errorf("%q: unix socket path too long (> 106)", path)
|
||||||
}
|
}
|
||||||
l, err = net.Listen("unix", "\x00"+path)
|
l, err = net.Listen("unix", "\x00"+path)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, path, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return l, path, nil
|
logrus.WithField("socket", path).Debug("serving api on abstract socket")
|
||||||
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSignals(logger *logrus.Entry, signals chan os.Signal) error {
|
func handleSignals(logger *logrus.Entry, signals chan os.Signal) error {
|
||||||
|
@ -54,20 +54,29 @@ func setupDumpStacks(dump chan<- os.Signal) {
|
|||||||
|
|
||||||
// serve serves the ttrpc API over a unix socket at the provided path
|
// serve serves the ttrpc API over a unix socket at the provided path
|
||||||
// this function does not block
|
// this function does not block
|
||||||
func serveListener(path string) (net.Listener, string, error) {
|
func serveListener(path string) (net.Listener, error) {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil, path, errors.New("'socket' must be npipe path")
|
return nil, errors.New("'socket' must be npipe path")
|
||||||
}
|
}
|
||||||
l, err := winio.ListenPipe(path, nil)
|
l, err := winio.ListenPipe(path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, path, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return l, path, nil
|
logrus.WithField("socket", path).Debug("serving api on npipe socket")
|
||||||
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSignals(logger *logrus.Entry, signals chan os.Signal) error {
|
func handleSignals(logger *logrus.Entry, signals chan os.Signal) error {
|
||||||
<-signals
|
logger.Info("starting signal loop")
|
||||||
return nil
|
for {
|
||||||
|
select {
|
||||||
|
case s := <-signals:
|
||||||
|
switch s {
|
||||||
|
case os.Interrupt:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *remoteEventsPublisher) Publish(ctx context.Context, topic string, event events.Event) error {
|
func (l *remoteEventsPublisher) Publish(ctx context.Context, topic string, event events.Event) error {
|
||||||
|
@ -37,7 +37,7 @@ func SetScore(pid int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SocketAddress returns an abstract npipe address
|
// SocketAddress returns a npipe address
|
||||||
func SocketAddress(ctx context.Context, id string) (string, error) {
|
func SocketAddress(ctx context.Context, id string) (string, error) {
|
||||||
ns, err := namespaces.NamespaceRequired(ctx)
|
ns, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -46,7 +46,7 @@ func SocketAddress(ctx context.Context, id string) (string, error) {
|
|||||||
return fmt.Sprintf("\\\\.\\pipe\\containerd-shim-%s-%s-pipe", ns, id), nil
|
return fmt.Sprintf("\\\\.\\pipe\\containerd-shim-%s-%s-pipe", ns, id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnonDialer returns a dialer for an abstract npipe
|
// AnonDialer returns a dialer for a npipe
|
||||||
func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
|
func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
|
||||||
return winio.DialPipe(address, &timeout)
|
return winio.DialPipe(address, &timeout)
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
|
|||||||
func NewSocket(address string) (net.Listener, error) {
|
func NewSocket(address string) (net.Listener, error) {
|
||||||
l, err := winio.ListenPipe(address, nil)
|
l, err := winio.ListenPipe(address, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to listen to abstract npipe %s", address)
|
return nil, errors.Wrapf(err, "failed to listen to npipe %s", address)
|
||||||
}
|
}
|
||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user