MCPcopy Create free account
hub / github.com/DataDog/datadog-agent / isJavaProcess

Method isJavaProcess

pkg/network/usm/ebpf_javatls.go:186–206  ·  view source on GitHub ↗

isJavaProcess checks if the given PID comm's name is java. The method is much faster and efficient that using process.NewProcess(pid).Name().

(pid uint32)

Source from the content-addressed store, hash-verified

184// isJavaProcess checks if the given PID comm's name is java.
185// The method is much faster and efficient that using process.NewProcess(pid).Name().
186func (p *javaTLSProgram) isJavaProcess(pid uint32) bool {
187 filePath := filepath.Join(p.procRoot, strconv.Itoa(int(pid)), "comm")
188 content, err := os.ReadFile(filePath)
189 if err != nil {
190 // Waiting a bit, as we might get the event of process creation before the directory was created.
191 for i := 0; i < 3; i++ {
192 time.Sleep(10 * time.Millisecond)
193 // reading again.
194 content, err = os.ReadFile(filePath)
195 if err == nil {
196 break
197 }
198 }
199 }
200
201 if err != nil {
202 // short living process can hit here, or slow start of another process.
203 return false
204 }
205 return bytes.Equal(bytes.TrimSpace(content), javaProcessName)
206}
207
208// isAttachmentAllowed will return true if the pid can be attached
209// The filter is based on the process command line matching injectionAllowRegex and injectionBlockRegex regex

Callers 1

newJavaProcessMethod · 0.95

Calls 3

JoinMethod · 0.80
ReadFileMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected