1
- // +build !windows
2
-
3
1
/*
4
2
Copyright The containerd Authors.
5
3
19
17
package shim
20
18
21
19
import (
22
- "bytes"
23
20
"context"
24
21
"flag"
25
22
"fmt"
26
- "net"
27
23
"os"
28
- "os/exec"
29
- "os/signal"
30
24
"runtime"
31
25
"runtime/debug"
32
26
"strings"
33
- "syscall"
34
27
"time"
35
28
36
29
"github.com/containerd/containerd/events"
37
30
"github.com/containerd/containerd/namespaces"
38
31
shimapi "github.com/containerd/containerd/runtime/v2/task"
39
32
"github.com/containerd/ttrpc"
40
- "github.com/containerd/typeurl"
41
33
"github.com/gogo/protobuf/proto"
42
34
"github.com/pkg/errors"
43
35
"github.com/sirupsen/logrus"
44
- "golang.org/x/sys/unix"
45
36
)
46
37
47
38
// Client for a shim server
@@ -178,7 +169,7 @@ func NewShimClient(ctx context.Context, svc shimapi.TaskService, signals chan os
178
169
// Serve the shim server
179
170
func (s * Client ) Serve () error {
180
171
dump := make (chan os.Signal , 32 )
181
- signal . Notify (dump , syscall . SIGUSR1 )
172
+ setupDumpStacks (dump )
182
173
183
174
path , err := os .Getwd ()
184
175
if err != nil {
@@ -211,23 +202,10 @@ func (s *Client) Serve() error {
211
202
// serve serves the ttrpc API over a unix socket at the provided path
212
203
// this function does not block
213
204
func serve (ctx context.Context , server * ttrpc.Server , path string ) error {
214
- var (
215
- l net.Listener
216
- err error
217
- )
218
- if path == "" {
219
- l , err = net .FileListener (os .NewFile (3 , "socket" ))
220
- path = "[inherited from parent]"
221
- } else {
222
- if len (path ) > 106 {
223
- return errors .Errorf ("%q: unix socket path too long (> 106)" , path )
224
- }
225
- l , err = net .Listen ("unix" , "\x00 " + path )
226
- }
205
+ l , err := serveListener (path )
227
206
if err != nil {
228
207
return err
229
208
}
230
- logrus .WithField ("socket" , path ).Debug ("serving api on unix socket" )
231
209
go func () {
232
210
defer l .Close ()
233
211
if err := server .Serve (ctx , l ); err != nil &&
@@ -238,22 +216,6 @@ func serve(ctx context.Context, server *ttrpc.Server, path string) error {
238
216
return nil
239
217
}
240
218
241
- func handleSignals (logger * logrus.Entry , signals chan os.Signal ) error {
242
- logger .Info ("starting signal loop" )
243
- for {
244
- select {
245
- case s := <- signals :
246
- switch s {
247
- case unix .SIGCHLD :
248
- if err := Reap (); err != nil {
249
- logger .WithError (err ).Error ("reap exit status" )
250
- }
251
- case unix .SIGPIPE :
252
- }
253
- }
254
- }
255
- }
256
-
257
219
func dumpStacks (logger * logrus.Entry ) {
258
220
var (
259
221
buf []byte
@@ -273,29 +235,3 @@ type remoteEventsPublisher struct {
273
235
address string
274
236
containerdBinaryPath string
275
237
}
276
-
277
- func (l * remoteEventsPublisher ) Publish (ctx context.Context , topic string , event events.Event ) error {
278
- ns , _ := namespaces .Namespace (ctx )
279
- encoded , err := typeurl .MarshalAny (event )
280
- if err != nil {
281
- return err
282
- }
283
- data , err := encoded .Marshal ()
284
- if err != nil {
285
- return err
286
- }
287
- cmd := exec .CommandContext (ctx , l .containerdBinaryPath , "--address" , l .address , "publish" , "--topic" , topic , "--namespace" , ns )
288
- cmd .Stdin = bytes .NewReader (data )
289
- c , err := Default .Start (cmd )
290
- if err != nil {
291
- return err
292
- }
293
- status , err := Default .Wait (cmd , c )
294
- if err != nil {
295
- return err
296
- }
297
- if status != 0 {
298
- return errors .New ("failed to publish event" )
299
- }
300
- return nil
301
- }
0 commit comments