Commit Graph
26 Commits
Author SHA1 Message Date
Anton Novoselov 29d01fc8e5 fix: prevent stack overflow from process tree cycles in build_proc (#7706)
The `build_proc` function in procinfo recursively walks the process
tree to build child process information. If a cycle exists in the
parent PID chain (which can happen on Windows in particular due to PID
reuse or race conditions during process snapshot enumeration),
the recursion never terminates and overflows the stack.

Add a `visited` HashSet to track already-visited PIDs and skip them,
preventing infinite recursion. Applied to all three platforms (Windows,
Linux, macOS)

Fixes #7705
Related: #6671
2026-06-07 08:22:04 +01:00
crides 217dfb30f5 fix linux divine_process_list
Fixes #4993
2024-02-12 07:38:05 -07:00
Jalil David Salamé Messina d541e2e13d fix(clippy): Remove closures where possible
- Removes closures and function calls for types that implement default:

  ```rust
  // Change
  let _my_str = get_str().unwrap_or(String::new);
  // To
  let _my_str = get_str().unwrap_or_default();
  ```

- Uses the `.cloned()/.copied()` methods where possible
- Use function pointer instead of simple closure

May improve performace, as closures generate more code, and this might
unlock some inlining opportunities.
2023-03-19 08:41:38 -07:00
Jalil David Salamé Messina 191aacc7d7 fix(clippy): Use faster methods on Iterators
- Use `find` instead of `position(..).next()`
- Use `any` instead of `position(..).next().is_some()/.is_none()`
- Use `first/next` instead of `get(0)/nth(0)`
- Prefer `for` loops over `while let` loops on iterators

May improve performance.
2023-03-19 07:29:23 -07:00
Mikayla Maki 32771eecc6 Rearranged order of trimming and parsing 2022-09-06 20:14:27 -07:00
Mikayla Maki d74cb1b625 Added extra test 2022-09-06 20:14:27 -07:00
Mikayla Maki d7c4898f3d Add tests for sysctl parsing 2022-09-06 20:14:27 -07:00
Mikayla Maki 75a7c38800 Change wording 2022-09-06 20:14:27 -07:00
Mikayla Maki ffae6818ef Fixed small bug in how procinfo reads sysctl KERN_PROCARGS2 2022-09-06 20:14:27 -07:00
K Simmons 6166008b18 Make procinfo's lua dependency optional 2022-09-06 20:14:27 -07:00
Wez Furlong 862dbc604a cut more things over to dynamic 2022-05-18 07:47:39 -07:00
Wez Furlong f9c4855159 procinfo: windows: tweak and add more tracing
Use an alternative function to query the executable path for
a target process.

Add more tracing.

refs: #1896
2022-04-20 09:43:56 -07:00
Wez Furlong 92893f2a34 procinfo: defend against weird situations on Windows
I've had a couple of deadlock situations when invoking win32 apps
via wsl on my work machine.  In those situations, the process that
we show in the titlebar is a short lived process that has likely
recently terminated, so I suspect something weird about either
dangling references or, given the deadlock-y nature of things,
maybe trying to reference ourselves.

This commit tries to defend against these by:

* Avoiding creating a ProcHandle for our own pid
* Releasing the toolhelper snapshot as soon as we have copied
  out the list of pids that we need

Not sure that this will nail it, but it seems like it can't hurt.
2022-04-19 08:46:32 -07:00
Wez Furlong b2ba7383b0 windows: procinfo: extra defensive coding around reading proc info
Might possibly help with #1699
2022-04-05 08:54:05 -07:00
Wez Furlong e148cfe8e3 procinfo: tidy up windows impl a bit 2022-01-01 10:01:19 -07:00
Wez Furlong 6a7fd37d34 procinfo: add some comments 2022-01-01 09:53:56 -07:00
Wez Furlong 5660942055 procinfo: add windows console field. mux: ignore non-console procs
When considering the fg process, we don't want a newly spawned
notepad.exe to show as the fg process in a cmd/pwsh pane, as it
runs async from the console and isn't attached to it.

We can extract the console handle from the process information and
use a 0 value handle to indicate win32 apps that are not attached
to any console.

We cannot compare console handle values directly: without probing
deeper into the handle we don't know that two differently valued
handles refer to different consoles, because a handle can be
duplicated into another with a different numeric value.
2022-01-01 09:40:18 -07:00
Wez Furlong 8c66d02364 procinfo: fix build on freebsd 2021-12-31 22:50:53 -07:00
Wez Furlong 20d9ded070 procinfo: add some comments! 2021-12-31 22:49:08 -07:00
Wez Furlong ed958160f3 procinfo: fixup macos build 2021-12-31 21:46:36 -07:00
Wez Furlong 3e05ee667f procinfo: fix linux build 2021-12-31 21:31:28 -07:00
Wez Furlong 1ad4015f9c procinfo: reorg a bit; enable cwd probing on windows
Likely breaks the mac and windows builds
2021-12-31 21:28:03 -07:00
Wez Furlong e16a27dfb3 procinfo: fmt/refactor
Just moves some code around
2021-12-31 20:05:27 -07:00
Wez Furlong 6650879260 move platform logic about LocalProcessInfo into procinfo crate 2021-12-31 19:45:09 -07:00
Wez Furlong 416c700841 procinfo: start_time is now in unspecified units since boot 2021-12-31 19:39:37 -07:00
Wez Furlong 910b111efa move procinfo bits into own crate 2021-12-31 19:31:21 -07:00