Skip to content

Fix LinuxHardwareI2C fd lifecycle#73

Open
l5yth wants to merge 1 commit into
meshtastic:masterfrom
l5yth:l5y-i2c-fd-lifecycle
Open

Fix LinuxHardwareI2C fd lifecycle#73
l5yth wants to merge 1 commit into
meshtastic:masterfrom
l5yth:l5y-i2c-fd-lifecycle

Conversation

@l5yth

@l5yth l5yth commented Jun 2, 2026

Copy link
Copy Markdown

@CLAassistant

CLAassistant commented Jun 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@thebentern
thebentern requested a review from Copilot July 16, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Fixes the Linux I2C file-descriptor lifecycle so pre-begin() operations don’t accidentally act on fd 0, and failed begin() calls can be retried safely.

Changes:

  • Initialize i2c_file to -1 (unopened) rather than 0.
  • Set hasBegun only when open() succeeds.
  • Reset i2c_file to -1 in end() after closing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cores/portduino/linux/LinuxHardwareI2C.h Default i2c_file to -1 to avoid accidental use of fd 0 prior to open().
cores/portduino/linux/LinuxHardwareI2C.cpp Guard hasBegun on successful open() and clear i2c_file on end().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


class LinuxHardwareI2C : public HardwareI2C {
int i2c_file = 0;
int i2c_file = -1; // unopened: fail fast instead of operating on stdin/stdout
Comment on lines +39 to +40
if (i2c_file >= 0)
hasBegun = true;
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.

Wire (LinuxHardwareI2C) defaults its fd to 0 (stdin), I2C ops before begin() block on stdin or run against the wrong fd

3 participants