Skip to content

Commit

Permalink
fix: ppid search should use strict equal cond
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 26, 2024
1 parent f08f07c commit 3804857
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/ts/ps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ export const parseProcessList = (output: string, query: TPsLookupQuery = {}) =>

const processList = parseGrid(output.trim())
const pidList= (query.pid === undefined ? [] : [query.pid].flat(1)).map(v => v + '')
const filter = (['command', 'arguments', 'ppid'] as Array<TFilterKeys>)
.reduce((m, k) => {
const param = query[k]
if (param) m[k] = new RegExp(param + '', 'i')
return m
}, {} as Record<TFilterKeys, RegExp>)
const filters: Array<(p: TPsLookupEntry) => boolean> = [
p => query.command ? new RegExp(query.command, 'i').test(p.command) : true,
p => query.arguments ? new RegExp(query.arguments, 'i').test(p.arguments.join(' ')) : true,
p => query.ppid ? query.ppid + '' === p.ppid : true
]

return processList.filter(p =>
(pidList.length === 0 || pidList.includes(p.pid)) && Object.keys(filter).every((type) => filter[type as TFilterKeys].test(p[type as keyof TPsLookupEntry] + ''))
(pidList.length === 0 || pidList.includes(p.pid)) && filters.every(f => f(p))
)
}

Expand Down

0 comments on commit 3804857

Please sign in to comment.