Skip to content

Conversation

naoNao89
Copy link

@naoNao89 naoNao89 commented Oct 6, 2025

  • Read tty_nr from /proc/PID/stat (field 7) which is world-readable
  • Add TryFrom implementation to decode tty_nr device numbers
  • Fix Display impl bug that had wrong device name mappings
  • Update tty() method to use stat file first, fall back to fd scanning
  • Update all callers to use mutable borrow for tty() method

This fixes issue #179 where pgrep -t would fail when run as a normal user because /proc/PID/fd is only readable by the process owner.

- Read tty_nr from /proc/PID/stat (field 7) which is world-readable
- Add TryFrom<u64> implementation to decode tty_nr device numbers
- Fix Display impl bug that had wrong device name mappings
- Update tty() method to use stat file first, fall back to fd scanning
- Update all callers to use mutable borrow for tty() method

This fixes issue uutils#179 where pgrep -t would fail when run as a normal
user because /proc/PID/fd is only readable by the process owner.
@sylvestre
Copy link
Contributor

again, please stop with the AI generated comment 0
please take the time to write something for human

@cakebaker
Copy link
Contributor

I don't know if you have seen it: test_pgrep::test_terminal fails in the CI.

The previous test relied on tty1 existing in the CI environment and used
--inverse as a workaround. With the new terminal detection implementation
that reads from /proc/<PID>/stat, the test behavior changed.

This commit updates the test to:
- Test with '?' (unknown terminal) which matches processes without terminals
- Use kthreadd as a reliable test case (always has no terminal)
- Test --inverse functionality more robustly

This addresses the CI failure where test_terminal was panicking.
Comment on lines +119 to +126
4 => {
if minor == 0 {
// /dev/tty0 is the current virtual console
Ok(Self::Tty(0))
} else {
Ok(Self::Tty(minor))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The condition is not really necessary:

Suggested change
4 => {
if minor == 0 {
// /dev/tty0 is the current virtual console
Ok(Self::Tty(0))
} else {
Ok(Self::Tty(minor))
}
}
4 => Ok(Self::Tty(minor)),

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.

3 participants