MCPcopy Create free account
hub / github.com/SeeFlowerX/stackplz / runFunc

Function runFunc

cli/cmd/root.go:369–449  ·  view source on GitHub ↗
(command *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

367}
368
369func runFunc(command *cobra.Command, args []string) {
370 stopper := make(chan os.Signal, 1)
371 signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
372 ctx, cancelFun := context.WithCancel(context.TODO())
373 if gconfig.Rpc {
374 rpc.SetupRpc(ctx, Logger, gconfig)
375 rpc.StartRpcServer(stopper, gconfig.RpcPath)
376 os.Exit(0)
377 }
378 var runMods uint8
379 var runModules = make(map[string]module.IModule)
380 var wg sync.WaitGroup
381
382 var modNames []string
383 if mconfig.BrkAddr != 0 {
384 modNames = append(modNames, module.MODULE_NAME_BRK)
385 } else if mconfig.SysCallConf.Enable {
386 modNames = append(modNames, module.MODULE_NAME_PERF)
387 modNames = append(modNames, module.MODULE_NAME_SYSCALL)
388 } else if len(mconfig.StackUprobeConf.Points) > 0 {
389 modNames = append(modNames, module.MODULE_NAME_PERF)
390 modNames = append(modNames, module.MODULE_NAME_STACK)
391 } else {
392 Logger.Fatal("hook nothing, plz set -w/--point or -s/--syscall or --brk")
393 }
394 for _, modName := range modNames {
395 // 现在合并成只有一个模块了 所以直接通过名字获取
396 mod := module.GetModuleByName(modName)
397
398 mod.Init(ctx, Logger, mconfig)
399 err := mod.Run()
400 if err != nil {
401 Logger.Printf("%s\tmodule Run failed, [skip it]. error:%+v", mod.Name(), err)
402 os.Exit(1)
403 }
404 runModules[mod.Name()] = mod
405 if gconfig.Debug {
406 Logger.Printf("%s\tmodule started successfully", mod.Name())
407 }
408 wg.Add(1)
409 runMods++
410
411 }
412 if runMods > 0 {
413 Logger.Printf("start %d modules", runMods)
414 go func() {
415 scanner := bufio.NewScanner(os.Stdin)
416 for {
417 scanner.Scan()
418 err := scanner.Err()
419 if err != nil {
420 Logger.Printf("get input from console failed, err:%v", err)
421 syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
422 }
423 input_text := scanner.Text()
424 if input_text == "c" {
425 event.LetItRun()
426 }

Callers

nothing calls this directly

Calls 9

SetupRpcFunction · 0.92
StartRpcServerFunction · 0.92
GetModuleByNameFunction · 0.92
LetItRunFunction · 0.92
DumpCloseMethod · 0.80
InitMethod · 0.65
RunMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected