Skip to content

Conversation

mpb27
Copy link

@mpb27 mpb27 commented Aug 22, 2025

Using loginuid is only possible if the kernel is built with CONFIG_AUDIT enabled. The uid under which the process is running is available in status. This is different than the loginuid of the user that first logged in and somehow initiated the process.

At least this is my understanding of /proc//loginuid vs /proc//status.

I think it probably makes more sense to display the uid of the process and avoid the dependency on CONFIG_AUDIT.

Comments welcome.

Summary by Sourcery

Replace retrieval of process user ID via /proc//loginuid with parsing the Uid field from /proc//status to avoid CONFIG_AUDIT dependency and handle unknown UIDs.

Bug Fixes:

  • Get process UID from the status file instead of loginuid to support kernels without CONFIG_AUDIT.

Enhancements:

  • Add cat_multiline and regex-based parsing of the Uid field in /proc//status.
  • Introduce a fallback mapping for unknown UIDs in the usernames cache.

Using loginuid is only possible if the kernel is built with CONFIG_AUDIT enabled.
The Uid under which the process is running is available in status. This is different
than the uid of the user that initiated the process.

Upstream-Status: Inappropriate [OE-specific]

Signed-off-by: Mark Butowski <[email protected]>
Copy link
Contributor

sourcery-ai bot commented Aug 22, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces CONFIG_AUDIT-dependent loginuid lookup by parsing the Uid field in /proc//status (with fallback for missing matches) and introduces a multiline cat utility.

Class diagram for updated ProcessService and new cat_multiline utility

classDiagram
    class ProcessService {
        - usernames: dict
        - _root_path: str
        + __init__()
        + get_process_info(pid, gpu_mem_usage, process_name, uptime)
    }
    class cat {
        + cat(path)
    }
    class cat_multiline {
        + cat_multiline(path, max_length=16384)
    }
    ProcessService --> cat : uses
    ProcessService --> cat_multiline : uses
Loading

Flow diagram for process UID retrieval change

flowchart TD
    A[Start get_process_info] --> B[Read /proc/<pid>/status with cat_multiline]
    B --> C[Extract Uid field using regex]
    C --> D{Uid found?}
    D -- Yes --> E[Convert Uid to int]
    D -- No --> F[Set Uid to -1]
    E --> G[Lookup username]
    F --> G[Lookup username]
    G --> H[Continue process info gathering]
Loading

File-Level Changes

Change Details Files
Replace loginuid-based UID resolution with status-based parsing
  • Imported cat_multiline
  • Defined PROCESS_UID_REG for Uid extraction
  • Replaced cat(loginuid) with cat_multiline and regex match
  • Fallback to -1 when no UID matches
  • Expanded default usernames mapping to include -1
jtop/core/processes.py
Add multiline file read helper
  • Implemented cat_multiline to read up to a max length
jtop/core/common.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `jtop/core/common.py:119` </location>
<code_context>
         return f.readline().rstrip('\x00')


+def cat_multiline(path, max_length=16384):
+    with open(path, 'r') as f:
+        return f.read(max_length)
+
+
</code_context>

<issue_to_address>
Consider handling file read exceptions in cat_multiline.

Currently, if the file is missing or unreadable, an exception will be raised. Consider catching IOError/OSError and returning an empty string or a custom error, as done in 'cat'.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
def cat_multiline(path, max_length=16384):
    with open(path, 'r') as f:
        return f.read(max_length)
=======
def cat_multiline(path, max_length=16384):
    try:
        with open(path, 'r') as f:
            return f.read(max_length)
    except OSError:
        return ""
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `jtop/core/processes.py:98` </location>
<code_context>
-        uid = int(cat(os.path.join('/proc', pid, 'loginuid')))
+        proc_status = cat_multiline(os.path.join('/proc', pid, 'status'))
+        uid_matches = PROCESS_UID_REG.findall(proc_status)
+        uid = int(uid_matches[0]) if uid_matches else int(-1)
         if uid not in self.usernames:
             self.usernames[uid] = pwd.getpwuid(uid).pw_name
</code_context>

<issue_to_address>
Fallback to -1 for missing UID may mask parsing errors.

Consider adding a log message when no UID is found to make parsing issues more visible.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        proc_status = cat_multiline(os.path.join('/proc', pid, 'status'))
        uid_matches = PROCESS_UID_REG.findall(proc_status)
        uid = int(uid_matches[0]) if uid_matches else int(-1)
        if uid not in self.usernames:
            self.usernames[uid] = pwd.getpwuid(uid).pw_name
=======
        import logging
        proc_status = cat_multiline(os.path.join('/proc', pid, 'status'))
        uid_matches = PROCESS_UID_REG.findall(proc_status)
        if not uid_matches:
            logging.warning(f"No UID found in /proc/{pid}/status. Falling back to -1.")
        uid = int(uid_matches[0]) if uid_matches else int(-1)
        if uid not in self.usernames:
            self.usernames[uid] = pwd.getpwuid(uid).pw_name
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

uid = int(cat(os.path.join('/proc', pid, 'loginuid')))
proc_status = cat_multiline(os.path.join('/proc', pid, 'status'))
uid_matches = PROCESS_UID_REG.findall(proc_status)
uid = int(uid_matches[0]) if uid_matches else int(-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

mpb27 referenced this pull request in OE4T/meta-tegra Aug 23, 2025
* Enable I2C_CHARDEV for reading the CVM EEPROM
* Enable I2C_MUX_GPIO and I2C_MUX_PCA954x for camera support
* Enable AUDIT for jtop support

Signed-off-by: Matt Madison <[email protected]>
johnnynunez and others added 5 commits October 7, 2025 18:42
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.

2 participants