| 81 | } |
| 82 | |
| 83 | func (h *Hooks) Load(ctx context.Context, opts agent.HookCfg, setupOpts config.Agent) error { |
| 84 | |
| 85 | h.sess.Set(uint64(0), &agent.Session{ |
| 86 | ID: uint64(0), // need to check this one |
| 87 | }) |
| 88 | err := h.load(ctx, opts, setupOpts) |
| 89 | if err != nil { |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | g, ok := ctx.Value(models.ErrGroupKey).(*errgroup.Group) |
| 94 | if !ok { |
| 95 | return errors.New("failed to get the error group from the context") |
| 96 | } |
| 97 | |
| 98 | g.Go(func() error { |
| 99 | defer utils.Recover(h.logger) |
| 100 | <-ctx.Done() |
| 101 | h.unLoad(ctx, opts) |
| 102 | |
| 103 | // deleting in order to free the memory on shutdown. |
| 104 | h.sess.Delete(uint64(0)) |
| 105 | return nil |
| 106 | }) |
| 107 | |
| 108 | return nil |
| 109 | } |
| 110 | |
| 111 | func (h *Hooks) load(ctx context.Context, opts agent.HookCfg, setupOpts config.Agent) error { |
| 112 | // Allow the current process to lock memory for eBPF resources. |