github.com/demonoid81/containerd@v1.3.4/cmd/containerd-shim/shim_linux.go (about)

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"os"
    21  	"os/signal"
    22  
    23  	"github.com/containerd/containerd/sys/reaper"
    24  	runc "github.com/containerd/go-runc"
    25  	"github.com/containerd/ttrpc"
    26  	"github.com/opencontainers/runc/libcontainer/system"
    27  	"golang.org/x/sys/unix"
    28  )
    29  
    30  // setupSignals creates a new signal handler for all signals and sets the shim as a
    31  // sub-reaper so that the container processes are reparented
    32  func setupSignals() (chan os.Signal, error) {
    33  	signals := make(chan os.Signal, 32)
    34  	signal.Notify(signals, unix.SIGTERM, unix.SIGINT, unix.SIGCHLD, unix.SIGPIPE)
    35  	// make sure runc is setup to use the monitor
    36  	// for waiting on processes
    37  	runc.Monitor = reaper.Default
    38  	// set the shim as the subreaper for all orphaned processes created by the container
    39  	if err := system.SetSubreaper(1); err != nil {
    40  		return nil, err
    41  	}
    42  	return signals, nil
    43  }
    44  
    45  func newServer() (*ttrpc.Server, error) {
    46  	return ttrpc.NewServer(ttrpc.WithServerHandshaker(ttrpc.UnixSocketRequireSameUser()))
    47  }