Skip to content

Commit

Permalink
shim: fix debug flag not working
Browse files Browse the repository at this point in the history
As we know, shim starts twice. The first time we execute the shim with the
`start` arguments, the `-debug` argument is passed to the shim
process correctly. But the second time we execute shim, the debug flag
is ignored.

Signed-off-by: wllenyj <wllenyj@linux.alibaba.com>
(cherry picked from commit f710505)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
wllenyj authored and cpuguy83 committed Mar 19, 2023
1 parent 2ccfcff commit 28f1e32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions runtime/v2/runc/manager/manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type manager struct {
name string
}

func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (*exec.Cmd, error) {
func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string, debug bool) (*exec.Cmd, error) {
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return nil, err
Expand All @@ -87,6 +87,9 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co
"-id", id,
"-address", containerdAddress,
}
if debug {
args = append(args, "-debug")
}
cmd := exec.Command(self, args...)
cmd.Dir = cwd
cmd.Env = append(os.Environ(), "GOMAXPROCS=4")
Expand Down Expand Up @@ -114,7 +117,7 @@ func (m manager) Name() string {
}

func (manager) Start(ctx context.Context, id string, opts shim.StartOpts) (_ string, retErr error) {
cmd, err := newCommand(ctx, id, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress)
cmd, err := newCommand(ctx, id, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress, opts.Debug)
if err != nil {
return "", err
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/v2/shim/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type StartOpts struct {
ContainerdBinary string
Address string
TTRPCAddress string
Debug bool
}

type StopStatus struct {
Expand Down Expand Up @@ -333,6 +334,7 @@ func run(ctx context.Context, manager Manager, initFunc Init, name string, confi
ContainerdBinary: containerdBinaryFlag,
Address: addressFlag,
TTRPCAddress: ttrpcAddress,
Debug: debugFlag,
}

address, err := manager.Start(ctx, id, opts)
Expand Down

0 comments on commit 28f1e32

Please sign in to comment.