Skip to content

[codex] Hide sys log follower unit from argv#2

Open
jjangg96 wants to merge 1 commit into
mainfrom
codex/hide-log-unit-argv
Open

[codex] Hide sys log follower unit from argv#2
jjangg96 wants to merge 1 commit into
mainfrom
codex/hide-log-unit-argv

Conversation

@jjangg96
Copy link
Copy Markdown

Summary

  • Change default sys log follow mode so the long-lived journalctl process no longer receives -u <unit> in argv.
  • Use a short prelude plus cursor handoff into a JSON journal stream filtered in Python by unit fields.
  • Reject follow-mode options that would break the safe follower or reintroduce unit names into persistent argv.
  • Document the new follow-mode constraints and add an install-time python3 dependency warning.

Root Cause

sys log hl-visor kept a persistent process like journalctl --user -o cat -f -u hl-visor. hl-visor appears to scan process command lines broadly, so it interpreted the log follower as a second matching hl-visor process during restart and panicked.

Validation

  • bash -n sys install.sh uninstall.sh
  • git diff --check
  • Fake systemctl/journalctl harness confirming default sys log hl-visor output still follows matching records while persistent journalctl/filter process argv does not contain hl-visor.
  • Negative checks for unsupported -f, -o, --unit, and unit-name-containing passthrough args.

Closes #1

@jjangg96 jjangg96 marked this pull request as ready for review May 30, 2026 13:43
Copilot AI review requested due to automatic review settings May 30, 2026 13:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR changes sys log follow mode to avoid leaving the target unit name in long-lived process argv, addressing false process matches by services that inspect command lines.

Changes:

  • Adds a safe follow implementation using a short journalctl -u prelude and a long-lived JSON stream filtered by Python.
  • Rejects follow-mode options that would conflict with the internal JSON follower or expose unit names in argv.
  • Updates help/docs and adds an install-time python3 dependency warning.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
sys Adds the safe log follower and routes default sys log follow mode through it.
README.md Documents argv-hiding behavior, follow-mode restrictions, and python3 dependency.
install.sh Warns when required python3 is missing.

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

Comment thread sys
Comment on lines +407 to +413
-f|--follow)
echo "sys: log 명령은 기본적으로 follow 모드라서 $arg 옵션을 따로 받을 수 없어요." >&2
exit 1
;;
--follow=*)
echo "sys: log 명령은 기본적으로 follow 모드라서 $arg 옵션을 따로 받을 수 없어요." >&2
exit 1
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a82ea8df3b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sys
else
journal_cmd+=(-n 0)
fi
journal_cmd+=("$@")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle --no-tail before passing it to the follower

When a user runs sys log <unit> --no-tail, journalctl defines --no-tail as showing all lines even in follow mode. The prelude already receives that option and prints the unit's history, but passing the same option through here makes the unscoped follower replay the entire journal again before Python filters it, so the target unit's historical logs are emitted a second time and the command scans all journals unnecessarily. This regresses the documented journalctl passthrough behavior for --no-tail; either consume it in the prelude path or reject it like the other unsupported follow options.

Useful? React with 👍 / 👎.

Comment thread sys
arg="${filtered_args[$i]}"
case "$arg" in
-n|--lines)
if [[ $((i + 1)) -ge ${#filtered_args[@]} || ! "${filtered_args[$((i + 1))]}" =~ ^([0-9]+|all)$ ]]; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept journalctl's leading-plus line counts

This new validation rejects sys log <unit> -n +100 and the --lines=+100/-n+100 variants even though these were previously passed directly to journalctl and are valid; I checked journalctl --help, which advertises -n --lines[=[+]INTEGER]. In follow mode this now exits before journalctl runs, so users relying on journalctl's leading-plus line-count semantics lose a supported passthrough option.

Useful? React with 👍 / 👎.

Comment thread sys
if [[ -n "${SYS_LOG_AFTER_CURSOR:-}" ]]; then
journal_cmd+=(-n all --after-cursor "$SYS_LOG_AFTER_CURSOR")
else
journal_cmd+=(-n 0)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid dropping logs when there is no cursor

If the prelude finds no matching entry, SYS_LOG_AFTER_CURSOR is empty and the long-lived follower starts with -n 0; journalctl --help describes -n as the number of entries to show, so this only follows entries that arrive after that second journalctl process is attached. Because the new implementation splits the old single journalctl -f -u invocation into a prelude and a later unscoped follower, any first log line written by the unit in the gap between those two commands is silently missed.

Useful? React with 👍 / 👎.

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.

sys log can break service restart when unit name appears in journalctl argv

2 participants