Skip to content

Hoist BSD/Mac OperatingSystem version, session, and boot-time queries into bases - #3470

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:bsd-mac-os-dedup
Jul 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:bsd-mac-os-dedup

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Part of the cross-OS consistency/dedup audit (OperatingSystem subsystem, follow-on to the AIX base extraction #3469). The FreeBSD, DragonFly, OpenBSD, and Mac OperatingSystem JNA/FFM twins duplicated three methods whose logic is identical and differs only in the native backend.

What's hoisted

  • queryFamilyVersionInfo — the kern.ostype/kern.osrelease/kern.version (Mac: kern.osversion) sysctl reads plus the shared buildNumber parse.
  • getSessions — the USE_WHO_COMMAND ? super : who.getutxent() selection.
  • boot time — the kern.boottime sysctl read plus the sysctl -n kern.boottime command fallback (FreeBSD/DragonFly).

These move into the per-platform bases behind small native hooks — querySysctl, queryWhoSessions, queryKernBoottimeSeconds — and each twin now provides only those hook implementations plus the irreducible FileSystem/NetworkParams/InternetProtocolStats/OSProcess factories and getpid/getThreadId.

The shared version-info parse (buildFamilyVersionInfo) and boot-time command fallback (queryBootTimeFromCommand) live as static helpers on BsdOperatingSystem — no new abstract methods — so the command-line NetBSD implementation is untouched. OpenBSD's mib-based sysctl is handled by a querySysctl(int[], String) hook with the MIB identifiers defined on the OpenBSD base.

Left as-is (deliberate)

The Solaris (HAS_KSTAT2 kstat2 probing), Linux (HAS_UDEV/HAS_GETTID auxv/udev/gettid detection), and Windows (registry perf-counter suppliers) twins diverge in genuine native capability detection, not shareable logic — the same hard axis as the COM/PDH and Mac struct-reading cases.

No CHANGELOG entry: behavior is identical.

Local gate: spotless, checkstyle, forbiddenapis, javadoc, and a clean full-reactor build all pass; oshi-common and oshi-core tests pass. Mac runtime is validated locally — NativeComparisonTest.operatingSystemInfo() and sessions() (JNA==FFM) pass on Apple Silicon. FreeBSD and OpenBSD run on the pull-request CI; DragonFly is validated via a manual unix.yaml dispatch (it isn't part of the PR workflow).

Summary by CodeRabbit

  • New Features

    • Improved operating system version and build identification across macOS, FreeBSD, DragonFly BSD, and OpenBSD.
    • Added more reliable session discovery using native system data where available.
    • Improved boot-time detection with fallback handling when native values are unavailable.
  • Bug Fixes

    • Corrected static analysis suppression coverage for macOS operating-system code.

… into bases

The FreeBSD, DragonFly, OpenBSD, and Mac OperatingSystem twins duplicated
queryFamilyVersionInfo (sysctl kern.ostype/osrelease/version), getSessions
(who/getutxent), and boot-time logic between their JNA and FFM backends,
differing only in the native call.

Hoist those into the per-platform bases behind small native hooks
(querySysctl, queryWhoSessions, queryKernBoottimeSeconds), with the shared
version-info parse (buildFamilyVersionInfo) and boot-time command fallback
(queryBootTimeFromCommand) as static helpers on BsdOperatingSystem. The
helpers add no abstract methods, so the command-line NetBSD implementation is
untouched. Each twin now provides only its native hook implementations plus
the irreducible factories and getpid/getThreadId.

The genuinely-divergent native capability detection twins (Solaris kstat2,
Linux udev/gettid, Windows registry perf counters) are intentionally left as
is.

Behavior-preserving refactor; no CHANGELOG.
@coderabbitai

coderabbitai Bot commented Jul 17, 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: 52eb404a-7756-4edd-acb1-0be92ed192c1

📥 Commits

Reviewing files that changed from the base of the PR and between f879640 and c2214ae.

📒 Files selected for processing (14)
  • config/checkstyle-suppressions.xml
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.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/FreeBsdOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (3)
📚 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/BsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.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/freebsd/FreeBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
🔇 Additional comments (22)
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOperatingSystem.java (1)

28-28: LGTM!

Also applies to: 147-175

oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java (1)

31-38: LGTM!

Also applies to: 121-150

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

18-22: LGTM!

Also applies to: 61-77, 86-108

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

18-22: LGTM!

Also applies to: 59-75, 84-106

oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.java (1)

20-20: LGTM!

Also applies to: 32-53

config/checkstyle-suppressions.xml (1)

102-102: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java (1)

94-100: LGTM!

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

44-45: LGTM!


64-65: LGTM!


86-94: LGTM!

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

40-42: LGTM!


60-62: LGTM!


86-94: LGTM!

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

31-32: LGTM!

oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java (1)

78-84: LGTM!

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

33-34: LGTM!


53-54: LGTM!


74-77: LGTM!

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

32-34: LGTM!


52-54: LGTM!


76-80: LGTM!

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

24-26: LGTM!


📝 Walkthrough

Walkthrough

macOS and BSD common classes now centralize OS version, session, and boot-time orchestration. JNA and FFM implementations provide protected native-query hooks, while obsolete public overrides and command-parsing paths are removed. A Checkstyle suppression range is updated for the macOS additions.

Changes

OS query hook refactor

Layer / File(s) Summary
Shared BSD query helpers
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOperatingSystem.java
Adds shared family-version construction and command-based boot-time fallback helpers.
Common OS orchestration
oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java, oshi-common/src/main/java/oshi/software/common/os/unix/{dragonflybsd,freebsd,openbsd}/*
Adds common version, session, boot-time, and native-query hook implementations for macOS and BSD families.
JNA and FFM native backend hooks
oshi-core*/src/main/java/oshi/software/os/{mac,unix}/*
Moves sysctl, session, and boot-time access into protected JNA/FFM hooks and removes duplicated public implementations and text-parsing fallbacks.
macOS suppression alignment
config/checkstyle-suppressions.xml
Updates the suppressed MacOperatingSystem.java line range from 54-61 to 56-63.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CommonOperatingSystem
  participant NativeBackend
  participant NativeAPI
  CommonOperatingSystem->>NativeBackend: querySysctl or queryWhoSessions
  NativeBackend->>NativeAPI: invoke native sysctl or who access
  NativeAPI-->>NativeBackend: values or sessions
  NativeBackend-->>CommonOperatingSystem: return query result
Loading

Possibly related PRs

  • oshi/oshi#3104: Overlaps with the macOS FFM session-query hook refactor.
  • oshi/oshi#3303: Overlaps with DragonFlyBSD version, session, and boot-time query changes.
  • oshi/oshi#3375: Overlaps with shared BSD boot-time retrieval hooks.

Poem

A bunny hops through sysctl snow,
Finds version strings in rows,
JNA and FFM share the way,
Sessions spring to life today,
Boot time blooms where rabbits play.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.59% 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 accurately summarizes the main refactor: moving BSD/Mac version, session, and boot-time queries into shared base classes.
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.
✨ 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.

@codecov

codecov Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.96774% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.15%. Comparing base (f879640) to head (c2214ae).

Files with missing lines Patch % Lines
...oftware/common/os/unix/bsd/BsdOperatingSystem.java 40.00% 3 Missing ⚠️
...shi/software/common/os/mac/MacOperatingSystem.java 66.66% 0 Missing and 2 partials ⚠️
...common/os/unix/freebsd/FreeBsdOperatingSystem.java 60.00% 0 Missing and 2 partials ⚠️
...are/os/unix/freebsd/FreeBsdOperatingSystemFFM.java 66.66% 1 Missing ⚠️
...are/os/unix/freebsd/FreeBsdOperatingSystemJNA.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3470      +/-   ##
============================================
- Coverage     75.26%   75.15%   -0.11%     
  Complexity       76       76              
============================================
  Files           589      589              
  Lines         21528    21511      -17     
  Branches       3592     3593       +1     
============================================
- Hits          16202    16167      -35     
- Misses         3371     3391      +20     
+ Partials       1955     1953       -2     
Flag Coverage Δ
freebsd 27.71% <29.03%> (-0.01%) ⬇️
linux 32.28% <0.00%> (+0.03%) ⬆️
macos 32.80% <25.80%> (-0.03%) ⬇️
openbsd 27.01% <22.58%> (-0.04%) ⬇️
solaris 29.52% <0.00%> (-0.01%) ⬇️
windows 40.95% <0.00%> (-0.01%) ⬇️

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.

@dbwiddis
dbwiddis merged commit 1293a58 into oshi:master Jul 18, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the bsd-mac-os-dedup branch July 18, 2026 00:01
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