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)
| 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(). |
| 186 | func (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 |
no test coverage detected