diff --git a/cli/cmd/tls.go b/cli/cmd/tls.go index 297492abe..5918e8852 100644 --- a/cli/cmd/tls.go +++ b/cli/cmd/tls.go @@ -59,6 +59,7 @@ func openSSLCommandFunc(command *cobra.Command, args []string) { modNames := []string{user.MODULE_NAME_OPENSSL, user.MODULE_NAME_GNUTLS, user.MODULE_NAME_NSPR} + var runMods uint8 for _, modName := range modNames { mod := user.GetModuleByName(modName) if mod == nil { @@ -88,28 +89,32 @@ func openSSLCommandFunc(command *cobra.Command, args []string) { conf.SetHex(gConf.IsHex) if e := conf.Check(); e != nil { - logger.Fatal(e) - os.Exit(1) + logger.Printf("%v", e) + break } //初始化 err := mod.Init(ctx, logger, conf) if err != nil { - logger.Fatal(err) - os.Exit(1) + logger.Printf("%v", err) + break } // 加载ebpf,挂载到hook点上,开始监听 go func(module user.IModule) { err := module.Run() if err != nil { - logger.Fatalf("%v", err) + logger.Printf("%v", err) + return } }(mod) - + runMods++ } - <-stopper + // needs runmods > 0 + if runMods > 0 { + <-stopper + } cancelFun() os.Exit(0) } diff --git a/user/probe_nspr.go b/user/probe_nspr.go index da4aae046..dea0264b5 100644 --- a/user/probe_nspr.go +++ b/user/probe_nspr.go @@ -10,6 +10,7 @@ import ( "golang.org/x/sys/unix" "log" "math" + "os" ) type MNsprProbe struct { @@ -46,7 +47,10 @@ func (this *MNsprProbe) start() error { } // setup the managers - this.setupManagers() + err = this.setupManagers() + if err != nil { + return errors.Wrap(err, "tls module couldn't find binPath.") + } // initialize the bootstrap manager if err := this.bpfManager.InitWithOptions(bytes.NewReader(byteBuf), this.bpfManagerOptions); err != nil { @@ -93,7 +97,7 @@ func (e *MNsprProbe) constantEditor() []manager.ConstantEditor { return editor } -func (this *MNsprProbe) setupManagers() { +func (this *MNsprProbe) setupManagers() error { var binaryPath string switch this.conf.(*NsprConfig).elfType { case ELF_TYPE_BIN: @@ -105,6 +109,11 @@ func (this *MNsprProbe) setupManagers() { binaryPath = "/lib/x86_64-linux-gnu/libnspr4.so" } + _, err := os.Stat(binaryPath) + if err != nil { + return err + } + this.logger.Printf("HOOK type:%d, binrayPath:%s\n", this.conf.(*NsprConfig).elfType, binaryPath) this.bpfManager = &manager.Manager{ @@ -191,6 +200,7 @@ func (this *MNsprProbe) setupManagers() { // 填充 RewriteContants 对应map ConstantEditors: this.constantEditor(), } + return nil } func (this *MNsprProbe) DecodeFun(em *ebpf.Map) (IEventStruct, bool) {