Skip to content

Unify ps-based BSD OSProcess parsing onto a shared BsdOSProcess base - #3372

Merged
dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:bsd-osprocess-common-base
Jun 11, 2026
Merged

dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:bsd-osprocess-common-base

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Builds on #3370 (which extracted the shared BsdOSProcess base holding the BSD-family field storage and accessors). This PR unifies the remaining duplication: the ps-output parsing.

Before this change, each platform's updateAttributes(psMap) was byte-identical between the JNA and FFM backends and ~85% similar across FreeBSD/OpenBSD/DragonFly/NetBSD, while each OperatingSystem class carried its own copy of the PsKeywords enum + PS_COMMAND_ARGS.

  • A single BsdPsKeyword master enum (union of all BSD ps columns). Each platform's OSProcess base declares its ordered PS_KEYWORDS subset and derives PS_COMMAND_ARGS from it; the OperatingSystem classes reference those instead of per-backend copies.
  • A new ParseUtil.stringToEnumMap(Class, List<K> keys, values, delim) overload that maps an explicit ordered subset (the last key slurps the line remainder). The existing all-values method delegates to it. This is needed because stringToEnumMap is positional by enum ordinal, so a single master enum can't be parsed with the all-values form — each platform requests a different column subset/order.
  • One shared updateAttributes(Map<BsdPsKeyword,String>) and no-arg updateAttributes() in BsdOSProcess, reading defensively by present key. Per-platform differences are handled by two protected hooks: queryStartTimeMillis() (DragonFly overrides to read /proc) and updateThreadCount() (OpenBSD/NetBSD override).
  • The identical-across-backends getThreadDetails() moves into each platform's OSProcess base.

The JNA/FFM OSProcess classes now hold only their native code (arguments, environment, bitness, rlimit, cwd, open files). Derived PS_COMMAND_ARGS strings are byte-identical to before, so the ps invocations are unchanged.

Solaris and AIX source process data from /proc psinfo structs and perfstat rather than ps, so they are out of scope.

Notes

  • Folds in one pre-existing JNA/FFM divergence: OpenBSD's FFM updateThreadCount clamped the count to at least 1 while JNA did not; the shared version keeps the clamp (a live process always has at least one thread), matching NetBSD.
  • OperatingSystemTest.testThreads was pre-existing flaky: it asserted a thread's user-time component was nondecreasing, but platforms that derive it as TIME - SYSTIME from coarse-resolution ps columns can see it dip between two back-to-back reads (the ps syscall bumps kernel time while the total rounds unchanged). It now asserts total CPU time (user + kernel, which maps to the monotonic ps TIME) is nondecreasing.

Testing

All five unix.yaml VM jobs pass, exercising the refactored code on real FreeBSD, OpenBSD, DragonFly, and NetBSD systems (plus OpenIndiana). Local spotless / checkstyle / forbidden-APIs / javadoc and a clean full-reactor build also pass.

Summary by CodeRabbit

  • Bug Fixes

    • Ensured process CPU time is measured as total CPU time (user + kernel) to remain monotonic across BSD platforms.
  • New Features

    • More reliable BSD process attribute refreshes (state, memory, start time, command/args, thread counts) for FreeBSD, OpenBSD, DragonFly, and NetBSD.
  • Refactor

    • Unified BSD ps column handling and shared parsing logic to reduce duplication.
  • Tests

    • Added test coverage for ordered enum-based parsing utility.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 211b04a9-4e94-446f-b28a-5bac93d2ad6d

📥 Commits

Reviewing files that changed from the base of the PR and between 2472109 and cbb3c9f.

📒 Files selected for processing (5)
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (5)

51-69: LGTM!


71-87: LGTM!


170-183: LGTM!


185-194: LGTM!


89-168: LGTM!


📝 Walkthrough

Walkthrough

This PR centralizes BSD ps-driven process attribute parsing in a shared BsdOSProcess base, adds a BsdPsKeyword enum and an ordered ParseUtil mapping overload, and refactors FreeBSD, OpenBSD, DragonFly, and NetBSD (FFM and JNA variants) to use platform PS_KEYWORDS/PS_COMMAND_ARGS and the shared attribute population hooks.

Changes

BSD Process Consolidation

Layer / File(s) Summary
Shared BSD base class and keyword enum
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
Adds BsdPsKeyword enum, public boolean updateAttributes() that runs platform ps, shared protected boolean updateAttributes(Map<BsdPsKeyword,String>) population logic (state, IDs, user/group, priority, memory, thread count, times, start/up time, name/path, faults/context-switches, command fallback), and abstract/override hooks psKeywords(), psCommandArgs(), queryStartTimeMillis(), updateThreadCount().
ParseUtil enum-key ordering support
oshi-common/src/main/java/oshi/util/ParseUtil.java, oshi-common/src/test/java/oshi/util/ParseUtilTest.java
Adds stringToEnumMap(Class, List, String, char) to map delimited ps output to an explicit ordered key list (final key consumes remainder); original overload delegates to preserve compatibility; unit test verifies behavior.
oshi-common DragonFly implementation
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
Public PS_KEYWORDS and PS_COMMAND_ARGS; overrides hooks; implements queryStartTimeMillis() via /proc/<pid>/status parsing; updates getThreadDetails() to parse ps thread output.
oshi-common FreeBSD implementation
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java
Public PS_KEYWORDS and PS_COMMAND_ARGS; overrides hooks; updates getThreadDetails() to parse ps thread output into FreeBsdOSThread objects.
oshi-common NetBSD implementation
oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
Adds PS_KEYWORDS/PS_COMMAND_ARGS, changes constructor to accept Map<BsdPsKeyword,String>, delegates to superclass updateAttributes(psMap), and updates OS-level process-list parsing to use shared keywords and ARGS presence check.
oshi-common OpenBSD implementation
oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
Adds PS_KEYWORDS/PS_COMMAND_ARGS, overrides hooks, implements updateThreadCount() via native ps tid counting, and updates getThreadDetails() to parse and filter ps thread rows.
oshi-core-ffm platform implementations
oshi-core-ffm/src/main/java/oshi/software/os/unix/*
FFM variants refactored to accept Map<BsdPsKeyword,String>, remove local PsKeywords enums and per-class ps parsing/update overrides, and use shared PS_COMMAND_ARGS/PS_KEYWORDS; OpenBSD FFM adds sysctl-backed queryBitness/queryArguments/queryEnvironmentVariables.
oshi-core JNA platform implementations
oshi-core/src/main/java/oshi/software/os/unix/*
JNA variants refactored to accept Map<BsdPsKeyword,String>, convert public getters to protected query hooks, remove per-class attribute/thread overrides, and rely on superclass attribute population; FreeBSD/OpenBSD include platform-specific queryBitness/env/argument logic.
Test: CPU time monotonicity
oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
Change asserts to verify total CPU time (user + kernel) is nondecreasing after updateAttributes().

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related issues

Possibly related PRs

  • oshi/oshi#3288: tests comparing JNA vs FFM updateAttributes flow that exercise the new BSD updateAttributes path.
  • oshi/oshi#3370: closely related changes to introduce BsdOSProcess base used here.
  • oshi/oshi#3316: overlaps on FreeBSD thread/ps column constants and thread enumeration changes.

"🐰 I hopped through ps output, parsed each line with care,
Shared keywords now unite BSDs everywhere.
One base to rule the columns, one map to bind the rest,
I nibbled redundant code — now the system's at its best. 🥕"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.12% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main objective: unifying BSD process parsing across multiple platforms onto a shared base class using ps command standardization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (1)

81-92: 💤 Low value

Inconsistent parallel stream usage across BSD platforms.

FreeBSD uses .parallel() for thread detail parsing (line 88), while NetBSD and OpenBSD do not use parallel streams in their equivalent getThreadDetails() methods. While this is functionally correct, consider aligning the implementations for consistency—either all platforms use parallel or none do.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java`
around lines 81 - 92, FreeBsdOSProcess.getThreadDetails currently calls
.parallel() on the stream which is inconsistent with NetBSD/OpenBSD
implementations; to align behavior remove the .parallel() call so the stream
processing is sequential (locate the getThreadDetails method in FreeBsdOSProcess
and delete the .parallel() between .skip(1) and .map), ensuring semantics and
thread parsing remain the same across BSD platforms.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java`:
- Around line 84-98: The method queryStartTimeFromProc currently returns
System.currentTimeMillis() on parse failures which makes
BsdOSProcess.updateAttributes treat the process as started now; change the
failure return value to -1L so the base-class fallback path (ETIME/ETIMES) is
used; locate queryStartTimeFromProc in DragonFlyBsdOSProcess and replace the
final return with -1L (ensuring callers like BsdOSProcess.updateAttributes will
detect the sentinel and use the elapsed-time fallback).

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java`:
- Around line 81-92: FreeBsdOSProcess.getThreadDetails currently calls
.parallel() on the stream which is inconsistent with NetBSD/OpenBSD
implementations; to align behavior remove the .parallel() call so the stream
processing is sequential (locate the getThreadDetails method in FreeBsdOSProcess
and delete the .parallel() between .skip(1) and .map), ensuring semantics and
thread parsing remain the same across BSD platforms.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 05e4b70c-bdbe-4092-8118-483cbb911740

📥 Commits

Reviewing files that changed from the base of the PR and between bddf85f and 4f4b514.

📒 Files selected for processing (25)
  • config/checkstyle-suppressions.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java
🔇 Additional comments (41)
oshi-common/src/main/java/oshi/util/ParseUtil.java (1)

1395-1436: LGTM!

oshi-common/src/test/java/oshi/util/ParseUtilTest.java (1)

926-946: LGTM!

config/checkstyle-suppressions.xml (1)

65-68: LGTM!

oshi-common/src/main/java/module-info.java (1)

50-50: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java (1)

13-16: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/bsd/package-info.java (1)

5-8: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (1)

7-82: LGTM!

Also applies to: 100-111

oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java (5)

1-70: LGTM!


207-245: LGTM!


254-315: LGTM!


323-367: LGTM!


375-424: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (1)

49-54: LGTM!

Also applies to: 71-79

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (4)

49-77: LGTM!


79-107: LGTM!


109-145: LGTM!


147-195: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java (1)

107-133: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java (2)

41-76: LGTM!


78-101: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (3)

26-46: LGTM!


48-68: LGTM!


106-128: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java (1)

34-36: LGTM!

Also applies to: 127-142

oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (3)

28-56: LGTM!


58-102: LGTM!


143-161: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java (1)

33-35: LGTM!

Also applies to: 124-138

oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java (3)

34-55: LGTM!


57-94: LGTM!


96-132: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java (1)

31-34: LGTM!

Also applies to: 119-140

oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java (3)

25-61: LGTM!


63-103: LGTM!


105-139: LGTM!

oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java (1)

1-118: LGTM!

oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java (1)

28-29: LGTM!

Also applies to: 125-139

oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java (1)

1-152: LGTM!

oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java (1)

30-31: LGTM!

Also applies to: 125-139

oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java (1)

28-31: LGTM!

Also applies to: 121-147

oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java (1)

212-217: LGTM!

dbwiddis added 3 commits June 11, 2026 16:14
Adds stringToEnumMap(Class, List<K> keys, values, delim), which maps an
explicit ordered subset of enum keys rather than every constant in ordinal
order. The existing all-values method now delegates to it. This lets a single
enum back per-platform column subsets that vary in which columns are present
and their order, with the final key still slurping the line remainder.
The FreeBSD, OpenBSD, DragonFly, and NetBSD OSProcess implementations each
duplicated their ps-output parsing: updateAttributes(psMap) was byte-identical
between the JNA and FFM backends, and ~85% similar across the four platforms,
while each OperatingSystem class carried its own copy of the PsKeywords enum
and PS_COMMAND_ARGS constant.

Collapse this onto BsdOSProcess:

- Add a single BsdPsKeyword master enum (union of all BSD ps columns). Each
  platform's OSProcess base declares its ordered PS_KEYWORDS subset and derives
  PS_COMMAND_ARGS from it; the OperatingSystem classes reference those instead
  of their own copies.
- Move the no-arg updateAttributes() and a single shared
  updateAttributes(Map<BsdPsKeyword,String>) into BsdOSProcess. Per-platform
  differences (group vs user+rgid, nlwp vs separate thread count, systime/
  cputime/time, elapsed-vs-/proc start time, comm/ucomm, args/command) are
  handled by checking which keys are present, with two protected hooks:
  queryStartTimeMillis() (DragonFly overrides to read /proc) and
  updateThreadCount() (OpenBSD/NetBSD override).
- Move the (identical JNA/FFM) getThreadDetails() down into each platform's
  OSProcess base.

The JNA/FFM OSProcess classes now hold only their native code (arguments,
environment, bitness, rlimit, cwd, open files). Derived PS_COMMAND_ARGS strings
are unchanged, so the ps invocations are identical.

Also unifies a pre-existing JNA/FFM divergence: OpenBSD's FFM updateThreadCount
clamped the count to at least 1 while JNA did not; the shared version keeps the
clamp (a live process always has at least one thread), matching NetBSD.
testThreads read a thread's user time, called updateAttributes(), and asserted
the user time alone was nondecreasing. On platforms that derive thread user time
as (total - kernel) from coarse-resolution ps columns (e.g. FreeBSD: TIME minus
SYSTIME), the user component can dip between two back-to-back reads: the ps
syscall used to take the second reading bumps the thread's kernel time while the
total rounds unchanged. The sibling testProcess avoids this by sleeping 500ms
between reads; testThreads reads immediately, so it flaked.

Assert the total CPU time (user + kernel, which maps to the monotonic ps TIME)
is nondecreasing instead, keeping the kernel-time-nondecreasing check. Pre-
existing flakiness, independent of the OSProcess parsing dedup.
@dbwiddis
dbwiddis force-pushed the bsd-osprocess-common-base branch from 4f4b514 to 2472109 Compare June 11, 2026 23:14
@codecov

codecov Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.07018% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.80%. Comparing base (bddf85f) to head (cbb3c9f).

Files with missing lines Patch % Lines
...oshi/software/common/os/unix/bsd/BsdOSProcess.java 64.15% 9 Missing and 10 partials ⚠️
...tware/common/os/unix/openbsd/OpenBsdOSProcess.java 89.47% 0 Missing and 2 partials ⚠️
.../software/os/unix/openbsd/OpenBsdOSProcessJNA.java 0.00% 1 Missing and 1 partial ⚠️
...tware/common/os/unix/freebsd/FreeBsdOSProcess.java 92.85% 0 Missing and 1 partial ⚠️
...are/os/unix/openbsd/OpenBsdOperatingSystemJNA.java 80.00% 0 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (bddf85f) and HEAD (cbb3c9f). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (bddf85f) HEAD (cbb3c9f)
solaris 1 0
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3372      +/-   ##
============================================
- Coverage     75.18%   68.80%   -6.39%     
  Complexity       76       76              
============================================
  Files           565      566       +1     
  Lines         22192    22094      -98     
  Branches       3662     3658       -4     
============================================
- Hits          16686    15202    -1484     
- Misses         3450     5026    +1576     
+ Partials       2056     1866     -190     
Flag Coverage Δ
freebsd 26.20% <52.63%> (-0.02%) ⬇️
linux 29.99% <0.87%> (+0.13%) ⬆️
macos 30.67% <0.87%> (+0.13%) ⬆️
openbsd 25.62% <53.50%> (-0.07%) ⬇️
solaris ?
windows 38.51% <0.87%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java (1)

106-138: ⚠️ Potential issue | 🟠 Major

Guard ARGMAX before allocating JNA Memory in queryEnvironmentVariables()

If the kern.argmax sysctl fails, ARGMAX is set to 0, but queryEnvironmentVariables() still does new Memory(ARGMAX). com.sun.jna.Memory(long) requires a strictly positive size and throws IllegalArgumentException for 0/negative values, so the fallback path can crash the first env-var query. Add the same ARGMAX > 0 guard used by queryArguments().

Suggested fix
     `@Override`
     protected Map<String, String> queryEnvironmentVariables() {
+        if (ARGMAX <= 0) {
+            return Collections.emptyMap();
+        }
         // Get environment variables via sysctl(3)
         int[] mib = new int[4];
         mib[0] = 1; // CTL_KERN
         mib[1] = 55; // KERN_PROC_ARGS
         mib[2] = getProcessID();
         mib[3] = 3; // KERN_PROC_ENV
         // Allocate memory for environment variables
         try (Memory m = new Memory(ARGMAX); CloseableSizeTByReference size = new CloseableSizeTByReference(ARGMAX)) {
             // Fetch environment variables
             if (OpenBsdLibc.INSTANCE.sysctl(mib, mib.length, m, size, null, size_t.ZERO) == 0) {
                 // Returns a null-terminated list of pointers to the actual data
                 Map<String, String> env = new LinkedHashMap<>();
                 // To iterate the pointer-list
                 long offset = 0;
                 // Get the data base address to calculate offsets
                 long baseAddr = Pointer.nativeValue(m);
                 long maxAddr = baseAddr + size.longValue();
                 // Get the address of the data. If null (0) we're done iterating
                 long argAddr = Pointer.nativeValue(m.getPointer(offset));
                 while (argAddr > baseAddr && argAddr < maxAddr) {
                     String envStr = m.getString(argAddr - baseAddr);
                     int idx = envStr.indexOf('=');
                     if (idx > 0) {
                         env.put(envStr.substring(0, idx), envStr.substring(idx + 1));
                     }
                     offset += Native.POINTER_SIZE;
                     argAddr = Pointer.nativeValue(m.getPointer(offset));
                 }
                 return Collections.unmodifiableMap(env);
             }
         }
         return Collections.emptyMap();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java`
around lines 106 - 138, The method queryEnvironmentVariables() allocates new
Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard
used in queryArguments() so we bail out early (return Collections.emptyMap())
when ARGMAX is non-positive, preventing IllegalArgumentException from
com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check
immediately before the Memory allocation/try-with-resources block.
oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)

114-115: ⚠️ Potential issue | 🔴 Critical

Fix sysctl call-state allocation in DragonFly (queryBitness)
DragonFlyBsdOSProcessFFM.queryBitness() allocates callState with arena.allocate(ADDRESS) and passes it to FreeBsdLibcFunctions.sysctl(...). But FreeBsdLibcFunctions.sysctl uses CAPTURE_CALL_STATE and its javadoc requires callState to be allocated with ForeignFunctions.CAPTURED_STATE_LAYOUT for errno capture; the other FreeBsdLibcFunctions.sysctl call sites in this cohort allocate CAPTURED_STATE_LAYOUT (e.g., FreeBsdOSProcessFFM). This ADDRESS-vs-layout mismatch can break captured errno handling and make the downcall unsafe.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java`
around lines 114 - 115, In DragonFlyBsdOSProcessFFM.queryBitness(), the
callState is incorrectly allocated with arena.allocate(ADDRESS) before calling
FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the
allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e.,
arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe
and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of
the sysctl invocation the same and ensure the arena lifecycle remains correct.
♻️ Duplicate comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (1)

84-98: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Return the hook sentinel on parse failure to preserve elapsed-time fallback.

On Line 97, returning System.currentTimeMillis() causes BsdOSProcess.updateAttributes() to treat failures as "started now," which collapses uptime to ~1 ms instead of using ps elapsed time. This hook should return -1L when /proc parsing fails so the base-class fallback path (ETIME/ETIMES) is used.

Suggested fix
-        return System.currentTimeMillis();
+        return -1L;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java`
around lines 84 - 98, In DragonFlyBsdOSProcess.queryStartTimeFromProc change the
failure return value to -1L instead of System.currentTimeMillis() so parse or
missing /proc data signals a sentinel; ensure any branches where parsing fails
or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its
ETIME/ETIMES elapsed-time fallback rather than treating the process as "started
now."
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java`:
- Around line 39-42: The memoized identity fields (bitness, commandLine,
arguments, environmentVariables) are cached for the instance lifetime and can
become stale after PID reuse; update the class so these identity values are not
permanently memoized — either remove memoize() for those Suppliers and call
queryBitness/queryCommandLine/queryArguments/queryEnvironmentVariables directly,
or clear/reset their caches inside updateAttributes() whenever the process
identity changes (compare startTime or another identity field) so the Suppliers
(or backing fields) are refreshed; refer to the fields bitness, commandLine,
arguments, environmentVariables, the memoize helper, and the updateAttributes
method/OSProcess identity checks when making the change.
- Around line 260-268: The code in BsdOSProcess currently sets group = user when
BsdPsKeyword.GROUP is missing, which can produce inconsistent metadata; change
the branch handling psMap missing GROUP to not substitute the user name —
instead set group to an empty/unknown value (e.g., empty string or null) and
still set groupID = psMap.get(BsdPsKeyword.RGID); optionally attempt to resolve
the group name from the RGID (via existing group lookup utilities) and assign
that to group if resolution succeeds. Ensure you only modify the else branch
referencing psMap, BsdPsKeyword.GROUP, GID, RGID, group, groupID, and user.

---

Outside diff comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java`:
- Around line 114-115: In DragonFlyBsdOSProcessFFM.queryBitness(), the callState
is incorrectly allocated with arena.allocate(ADDRESS) before calling
FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the
allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e.,
arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe
and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of
the sysctl invocation the same and ensure the arena lifecycle remains correct.

In
`@oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java`:
- Around line 106-138: The method queryEnvironmentVariables() allocates new
Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard
used in queryArguments() so we bail out early (return Collections.emptyMap())
when ARGMAX is non-positive, preventing IllegalArgumentException from
com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check
immediately before the Memory allocation/try-with-resources block.

---

Duplicate comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java`:
- Around line 84-98: In DragonFlyBsdOSProcess.queryStartTimeFromProc change the
failure return value to -1L instead of System.currentTimeMillis() so parse or
missing /proc data signals a sentinel; ensure any branches where parsing fails
or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its
ETIME/ETIMES elapsed-time fallback rather than treating the process as "started
now."
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 44f0698e-e7cf-42a1-b80c-c6d4768e4183

📥 Commits

Reviewing files that changed from the base of the PR and between 4f4b514 and 2472109.

📒 Files selected for processing (22)
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
🚧 Files skipped from review as they are similar to previous changes (13)
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
🔇 Additional comments (14)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (4)

7-52: LGTM!


58-67: LGTM!


69-77: LGTM!


100-111: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (4)

7-54: LGTM!


60-69: LGTM!


71-79: LGTM!


81-92: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (4)

7-69: LGTM!


73-87: LGTM!


90-145: LGTM!


148-194: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)

42-67: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (1)

52-55: LGTM!

Also applies to: 59-101, 144-160

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java (1)

106-138: ⚠️ Potential issue | 🟠 Major

Guard ARGMAX before allocating JNA Memory in queryEnvironmentVariables()

If the kern.argmax sysctl fails, ARGMAX is set to 0, but queryEnvironmentVariables() still does new Memory(ARGMAX). com.sun.jna.Memory(long) requires a strictly positive size and throws IllegalArgumentException for 0/negative values, so the fallback path can crash the first env-var query. Add the same ARGMAX > 0 guard used by queryArguments().

Suggested fix
     `@Override`
     protected Map<String, String> queryEnvironmentVariables() {
+        if (ARGMAX <= 0) {
+            return Collections.emptyMap();
+        }
         // Get environment variables via sysctl(3)
         int[] mib = new int[4];
         mib[0] = 1; // CTL_KERN
         mib[1] = 55; // KERN_PROC_ARGS
         mib[2] = getProcessID();
         mib[3] = 3; // KERN_PROC_ENV
         // Allocate memory for environment variables
         try (Memory m = new Memory(ARGMAX); CloseableSizeTByReference size = new CloseableSizeTByReference(ARGMAX)) {
             // Fetch environment variables
             if (OpenBsdLibc.INSTANCE.sysctl(mib, mib.length, m, size, null, size_t.ZERO) == 0) {
                 // Returns a null-terminated list of pointers to the actual data
                 Map<String, String> env = new LinkedHashMap<>();
                 // To iterate the pointer-list
                 long offset = 0;
                 // Get the data base address to calculate offsets
                 long baseAddr = Pointer.nativeValue(m);
                 long maxAddr = baseAddr + size.longValue();
                 // Get the address of the data. If null (0) we're done iterating
                 long argAddr = Pointer.nativeValue(m.getPointer(offset));
                 while (argAddr > baseAddr && argAddr < maxAddr) {
                     String envStr = m.getString(argAddr - baseAddr);
                     int idx = envStr.indexOf('=');
                     if (idx > 0) {
                         env.put(envStr.substring(0, idx), envStr.substring(idx + 1));
                     }
                     offset += Native.POINTER_SIZE;
                     argAddr = Pointer.nativeValue(m.getPointer(offset));
                 }
                 return Collections.unmodifiableMap(env);
             }
         }
         return Collections.emptyMap();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java`
around lines 106 - 138, The method queryEnvironmentVariables() allocates new
Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard
used in queryArguments() so we bail out early (return Collections.emptyMap())
when ARGMAX is non-positive, preventing IllegalArgumentException from
com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check
immediately before the Memory allocation/try-with-resources block.
oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)

114-115: ⚠️ Potential issue | 🔴 Critical

Fix sysctl call-state allocation in DragonFly (queryBitness)
DragonFlyBsdOSProcessFFM.queryBitness() allocates callState with arena.allocate(ADDRESS) and passes it to FreeBsdLibcFunctions.sysctl(...). But FreeBsdLibcFunctions.sysctl uses CAPTURE_CALL_STATE and its javadoc requires callState to be allocated with ForeignFunctions.CAPTURED_STATE_LAYOUT for errno capture; the other FreeBsdLibcFunctions.sysctl call sites in this cohort allocate CAPTURED_STATE_LAYOUT (e.g., FreeBsdOSProcessFFM). This ADDRESS-vs-layout mismatch can break captured errno handling and make the downcall unsafe.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java`
around lines 114 - 115, In DragonFlyBsdOSProcessFFM.queryBitness(), the
callState is incorrectly allocated with arena.allocate(ADDRESS) before calling
FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the
allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e.,
arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe
and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of
the sysctl invocation the same and ensure the arena lifecycle remains correct.
♻️ Duplicate comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (1)

84-98: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Return the hook sentinel on parse failure to preserve elapsed-time fallback.

On Line 97, returning System.currentTimeMillis() causes BsdOSProcess.updateAttributes() to treat failures as "started now," which collapses uptime to ~1 ms instead of using ps elapsed time. This hook should return -1L when /proc parsing fails so the base-class fallback path (ETIME/ETIMES) is used.

Suggested fix
-        return System.currentTimeMillis();
+        return -1L;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java`
around lines 84 - 98, In DragonFlyBsdOSProcess.queryStartTimeFromProc change the
failure return value to -1L instead of System.currentTimeMillis() so parse or
missing /proc data signals a sentinel; ensure any branches where parsing fails
or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its
ETIME/ETIMES elapsed-time fallback rather than treating the process as "started
now."
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java`:
- Around line 39-42: The memoized identity fields (bitness, commandLine,
arguments, environmentVariables) are cached for the instance lifetime and can
become stale after PID reuse; update the class so these identity values are not
permanently memoized — either remove memoize() for those Suppliers and call
queryBitness/queryCommandLine/queryArguments/queryEnvironmentVariables directly,
or clear/reset their caches inside updateAttributes() whenever the process
identity changes (compare startTime or another identity field) so the Suppliers
(or backing fields) are refreshed; refer to the fields bitness, commandLine,
arguments, environmentVariables, the memoize helper, and the updateAttributes
method/OSProcess identity checks when making the change.
- Around line 260-268: The code in BsdOSProcess currently sets group = user when
BsdPsKeyword.GROUP is missing, which can produce inconsistent metadata; change
the branch handling psMap missing GROUP to not substitute the user name —
instead set group to an empty/unknown value (e.g., empty string or null) and
still set groupID = psMap.get(BsdPsKeyword.RGID); optionally attempt to resolve
the group name from the RGID (via existing group lookup utilities) and assign
that to group if resolution succeeds. Ensure you only modify the else branch
referencing psMap, BsdPsKeyword.GROUP, GID, RGID, group, groupID, and user.

---

Outside diff comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java`:
- Around line 114-115: In DragonFlyBsdOSProcessFFM.queryBitness(), the callState
is incorrectly allocated with arena.allocate(ADDRESS) before calling
FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the
allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e.,
arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe
and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of
the sysctl invocation the same and ensure the arena lifecycle remains correct.

In
`@oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java`:
- Around line 106-138: The method queryEnvironmentVariables() allocates new
Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard
used in queryArguments() so we bail out early (return Collections.emptyMap())
when ARGMAX is non-positive, preventing IllegalArgumentException from
com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check
immediately before the Memory allocation/try-with-resources block.

---

Duplicate comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java`:
- Around line 84-98: In DragonFlyBsdOSProcess.queryStartTimeFromProc change the
failure return value to -1L instead of System.currentTimeMillis() so parse or
missing /proc data signals a sentinel; ensure any branches where parsing fails
or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its
ETIME/ETIMES elapsed-time fallback rather than treating the process as "started
now."
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 44f0698e-e7cf-42a1-b80c-c6d4768e4183

📥 Commits

Reviewing files that changed from the base of the PR and between 4f4b514 and 2472109.

📒 Files selected for processing (22)
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
🚧 Files skipped from review as they are similar to previous changes (13)
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
📜 Review details
🔇 Additional comments (14)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (4)

7-52: LGTM!


58-67: LGTM!


69-77: LGTM!


100-111: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (4)

7-54: LGTM!


60-69: LGTM!


71-79: LGTM!


81-92: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (4)

7-69: LGTM!


73-87: LGTM!


90-145: LGTM!


148-194: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)

42-67: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (1)

52-55: LGTM!

Also applies to: 59-101, 144-160

🛑 Comments failed to post (2)
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java (2)

39-42: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Memoized identity fields can go stale after PID reuse.

updateAttributes() repopulates the instance from whatever process currently owns this PID, but bitness, arguments, environmentVariables, and commandLine are cached for the lifetime of the object. If a caller reads any of those once and the PID is later recycled, the instance will mix old-process identity data with new-process counters/state. This shared base is now the single place to prevent that, either by rejecting refresh when process identity changes or by avoiding lifetime memoization on a mutable OSProcess.

Also applies to: 87-90, 229-245, 294-303

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java`
around lines 39 - 42, The memoized identity fields (bitness, commandLine,
arguments, environmentVariables) are cached for the instance lifetime and can
become stale after PID reuse; update the class so these identity values are not
permanently memoized — either remove memoize() for those Suppliers and call
queryBitness/queryCommandLine/queryArguments/queryEnvironmentVariables directly,
or clear/reset their caches inside updateAttributes() whenever the process
identity changes (compare startTime or another identity field) so the Suppliers
(or backing fields) are refreshed; refer to the fields bitness, commandLine,
arguments, environmentVariables, the memoize helper, and the updateAttributes
method/OSProcess identity checks when making the change.

260-268: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't substitute the user name for the group name.

When GROUP is missing, this stores groupID = RGID but group = user. Those fields can legitimately refer to different principals, so callers can get internally inconsistent process metadata on DragonFly and any other platform that takes this branch. A safer fallback is to leave group unknown/empty here, or resolve it from RGID.

💡 Minimal safe fallback
         } else {
-            this.group = this.user;
+            this.group = "";
             this.groupID = psMap.get(BsdPsKeyword.RGID);
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java`
around lines 260 - 268, The code in BsdOSProcess currently sets group = user
when BsdPsKeyword.GROUP is missing, which can produce inconsistent metadata;
change the branch handling psMap missing GROUP to not substitute the user name —
instead set group to an empty/unknown value (e.g., empty string or null) and
still set groupID = psMap.get(BsdPsKeyword.RGID); optionally attempt to resolve
the group name from the RGID (via existing group lookup utilities) and assign
that to group if resolution succeeds. Ensure you only modify the else branch
referencing psMap, BsdPsKeyword.GROUP, GID, RGID, group, groupID, and user.

- DragonFlyBsdOSProcess.queryStartTimeFromProc: return the -1 sentinel on /proc
  read/parse failure instead of System.currentTimeMillis(), so updateAttributes()
  falls back to elapsed time rather than treating the process as started now.
- OpenBsdOSProcess/NetBsdOSProcess.getThreadDetails: parallelize the thread-row
  stream to match FreeBSD/DragonFly. The pipeline is stateless and each OSThread
  is independent (Collectors.toList preserves encounter order), so results are
  unchanged.
- DragonFlyBsdOSProcessFFM.queryBitness: allocate the captured-call-state segment
  with CAPTURED_STATE_LAYOUT instead of ADDRESS, matching the other FFM sysctl
  callers, so errno capture is correctly sized.
- OpenBsdOSProcessJNA.queryEnvironmentVariables: guard on ARGMAX > 0 (as
  queryArguments already does) to avoid new Memory(0) throwing when the
  kern.argmax sysctl is unavailable.
@dbwiddis
dbwiddis merged commit 68bf11a into oshi:master Jun 11, 2026
21 of 22 checks passed
@dbwiddis
dbwiddis deleted the bsd-osprocess-common-base branch June 12, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant