Skip to content

Commit

Permalink
[Dynamic Instrumentation] DI proctracker should not inspect itself (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tylfin authored Feb 26, 2025
1 parent bd44a13 commit da8f45d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/dynamicinstrumentation/proctracker/proctracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (pt *ProcessTracker) handleProcessStop(pid uint32) {
}

func (pt *ProcessTracker) inspectBinary(exePath string, pid uint32) {
// Avoid self-inspection.
if int(pid) == os.Getpid() {
return
}

serviceName := getServiceName(pid)
if serviceName == "" {
// if the expected env vars are not set we don't inspect the binary
Expand Down
33 changes: 33 additions & 0 deletions pkg/dynamicinstrumentation/proctracker/proctracker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build linux_bpf

package proctracker

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestProcessNotAdded(t *testing.T) {
pt := ProcessTracker{
processes: make(map[pid]binaryID),
}

// Use the current process ID for testing
pid := uint32(os.Getpid())

// Simulate process start
pt.inspectBinary("", pid)

// Ensure the process ID is not added to pt.processes
pt.lock.RLock()
defer pt.lock.RUnlock()
_, exists := pt.processes[pid]
assert.False(t, exists, "process ID should not be added to pt.processes")
}

0 comments on commit da8f45d

Please sign in to comment.