github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/runsc/cmd/trace/trace.go (about) 1 // Copyright 2022 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package trace provides subcommands for the trace command. 16 package trace 17 18 import ( 19 "bytes" 20 "context" 21 22 "github.com/google/subcommands" 23 "github.com/ttpreport/gvisor-ligolo/pkg/sentry/seccheck" 24 "github.com/ttpreport/gvisor-ligolo/runsc/flag" 25 ) 26 27 // Trace implements subcommands.Command for the "trace" command. 28 type Trace struct{} 29 30 // Name implements subcommands.Command. 31 func (*Trace) Name() string { 32 return "trace" 33 } 34 35 // Synopsis implements subcommands.Command. 36 func (*Trace) Synopsis() string { 37 return "manages trace sessions for a given sandbox" 38 } 39 40 // Usage implements subcommands.Command. 41 func (*Trace) Usage() string { 42 buf := bytes.Buffer{} 43 buf.WriteString("Usage: trace <flags> <subcommand> <subcommand args>\n\n") 44 45 cdr := createCommander(&flag.FlagSet{}) 46 cdr.VisitGroups(func(grp *subcommands.CommandGroup) { 47 cdr.ExplainGroup(&buf, grp) 48 }) 49 50 return buf.String() 51 } 52 53 // SetFlags implements subcommands.Command. 54 func (*Trace) SetFlags(f *flag.FlagSet) {} 55 56 // Execute implements subcommands.Command. 57 func (*Trace) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { 58 seccheck.Initialize() 59 return createCommander(f).Execute(ctx, args...) 60 } 61 62 func createCommander(f *flag.FlagSet) *subcommands.Commander { 63 cdr := subcommands.NewCommander(f, "trace") 64 cdr.Register(cdr.HelpCommand(), "") 65 cdr.Register(cdr.FlagsCommand(), "") 66 cdr.Register(new(create), "") 67 cdr.Register(new(delete), "") 68 cdr.Register(new(list), "") 69 cdr.Register(new(metadata), "") 70 cdr.Register(new(procfs), "") 71 return cdr 72 }