Skip to content

fix(stdin-detect): walk full descendant tree, not just direct children (#86)#192

Open
quangdang46 wants to merge 1 commit into
masterfrom
fix/stdin-detect-nested-wrappers
Open

fix(stdin-detect): walk full descendant tree, not just direct children (#86)#192
quangdang46 wants to merge 1 commit into
masterfrom
fix/stdin-detect-nested-wrappers

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

What

check_process_tree previously scanned /proc once and stopped at direct children. Wrappers like bash -c "cat" worked, but nested chains (bash -> sh -> cat or any tool that re-execs through an extra shell layer) silently reported NotReading because the grandchild was never inspected.

This addresses issue #86: #86

Changes

  • crates/jcode-core/src/stdin_detect.rs:
    • Build a parent -> children graph from /proc up front.
    • DFS through all descendants (cycle-safe via a visited set).
    • Each child step still verifies the descendant shares the parent's stdin link before falling into strict check_inner — same correctness guard as the old direct-children path.
  • crates/jcode-core/src/stdin_detect_tests.rs: test_grandchild_process_tree_detection covering bash -> sh -> cat.

Tests

$ cargo test -p jcode-core stdin
test result: ok. 9 passed; 0 failed

Notes / scope deviation from upstream

Upstream PR 1jehuang#101 also bundles a JCODE_CHEAP_MODE config tweak (forces low-cost defaults). That is unrelated to stdin detection and is intentionally NOT applied here — port it separately if desired.

`check_process_tree` previously scanned /proc once and stopped at
direct children. Wrappers like bash -c "cat" worked, but nested
chains like bash -> sh -> cat (or any tool that re-execs through an
extra shell layer) silently reported NotReading because the
grandchild was never inspected.

Build a parent->children graph from /proc up front, then DFS through
all descendants (cycle-safe via a visited set). Each step still
verifies the descendant shares the parent's stdin link before falling
into strict check_inner, so we don't accidentally flag unrelated
descendants reading their own stdin.

Test `test_grandchild_process_tree_detection` covers the
bash -> sh -> cat case.

Ports upstream PR 1jehuang#101.
The JCODE_CHEAP_MODE config tweak the same upstream PR also bundles
is unrelated to stdin detection and is intentionally NOT applied here
— it can be ported separately if desired.
Closes #86
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