Skip to content

Commit

Permalink
exit when failed to start probe (KindlingProject#315)
Browse files Browse the repository at this point in the history
* exit when failed to start probe

Signed-off-by: sangyangji <[email protected]>

* improve: move to go

Signed-off-by: sangyangji <[email protected]>

Signed-off-by: sangyangji <[email protected]>
  • Loading branch information
sanyangji authored Sep 19, 2022
1 parent ec2c168 commit bdc0ccc
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion collector/pkg/component/receiver/cgoreceiver/cgo_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifdef __cplusplus
extern "C" {
#endif
void runForGo();
int runForGo();
int getKindlingEvent(void **kindlingEvent);
int subEventForGo(char* eventName, char* category);
#ifdef __cplusplus
Expand Down
5 changes: 4 additions & 1 deletion collector/pkg/component/receiver/cgoreceiver/cgoreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func NewCgoReceiver(config interface{}, telemetry *component.TelemetryTools, ana

func (r *CgoReceiver) Start() error {
r.telemetry.Logger.Info("Start CgoReceiver")
C.runForGo()
res := int(C.runForGo())
if res == 1 {
return fmt.Errorf("fail to init probe")
}
time.Sleep(2 * time.Second)
r.subEvent()
// Wait for the C routine running
Expand Down
4 changes: 2 additions & 2 deletions probe/src/cgo/cgo_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "kindling.h"


void runForGo(){
init_probe();
int runForGo(){
return init_probe();
}

int getKindlingEvent(void **kindlingEvent){
Expand Down
2 changes: 1 addition & 1 deletion probe/src/cgo/cgo_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifdef __cplusplus
extern "C" {
#endif
void runForGo();
int runForGo();
int getKindlingEvent(void **kindlingEvent);
void subEventForGo(char* eventName, char* category);
#ifdef __cplusplus
Expand Down
4 changes: 3 additions & 1 deletion probe/src/cgo/kindling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void sub_event(char *eventName, char *category)
}
}

void init_probe()
int init_probe()
{
bool bpf = false;
char* isPrintEvent = getenv("IS_PRINT_EVENT");
Expand Down Expand Up @@ -131,7 +131,9 @@ void init_probe()
catch(const exception &e)
{
fprintf(stderr, "kindling probe init err: %s", e.what());
return 1;
}
return 0;
}

int getEvent(void **pp_kindling_event)
Expand Down
2 changes: 1 addition & 1 deletion probe/src/cgo/kindling.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define SYSDIG_KINDLING_H
#include "sinsp.h"

void init_probe();
int init_probe();
int getEvent(void **kindlingEvent);
uint16_t get_kindling_category(sinsp_evt *sEvt);
void init_sub_label();
Expand Down

0 comments on commit bdc0ccc

Please sign in to comment.