Skip to content

Rexec rexecd dpopen#3558

Open
JianyuWang0623 wants to merge 2 commits into
apache:masterfrom
JianyuWang0623:rexec_rexecd_dpopen
Open

Rexec rexecd dpopen#3558
JianyuWang0623 wants to merge 2 commits into
apache:masterfrom
JianyuWang0623:rexec_rexecd_dpopen

Conversation

@JianyuWang0623

Copy link
Copy Markdown
Contributor

Summary

This PR contains two fixes for the rexecd/rexec utilities under netutils/.

  1. netutils/rexecd: use dpopen() instead of popen() to get raw fd
    popen() now returns a fopencookie()-backed FILE*. On such a stream
    fileno() returns the cookie pointer instead of a real file descriptor,
    which is typically negative. rexecd's relay loop feeds that value into
    poll(), where a negative fd is silently ignored, so the loop never sees
    the child's POLLIN/POLLHUP/EOF and blocks forever waiting for the command
    to finish. (Related upstream change: system/popen: Avoid copying FILE #3511.)
  2. netutils/rexec: initialize ret to avoid maybe-uninitialized

Impact

  • Users: rexecd no longer hangs after the remote command finishes; the
    command-completion (EOF/POLLHUP) path works again. No API or CLI change.
  • Build: removes a potential -Werror=maybe-uninitialized build break in
    rexec.c.
  • Dependencies: rexecd now depends on dpopen()/dpclose()
    (CONFIG_SYSTEM_POPEN), the descriptor-based counterparts of
    popen()/pclose().
  • Hardware / Security / Compatibility: no change. Documentation: none needed.

Testing

Built with the standard nuttx-apps toolchain; warning-as-error build of
netutils/rexec and netutils/rexecd passes after the ret initialization fix.

Runtime verified by running rexecd on the target and issuing a remote command
from rexec:

  • Before: rexec <host> <cmd> printed the command output but then hung; the
    session never returned to the prompt because poll() ignored the negative
    fileno() and the relay loop never observed command completion.
  • After: the same rexec <host> <cmd> prints the output, receives EOF/POLLHUP
    when the child exits, and the session terminates cleanly.

When the relay loop exits early without entering any branch, ret would be
returned uninitialized, tripping -Werror=maybe-uninitialized. Initialize
it to 0.

Assisted-by: GitHubCopilot:claude-4.8-opus
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
popen() now returns a fopencookie-backed FILE* whose fileno() yields the
cookie pointer rather than a real descriptor, so poll() silently ignores
the negative fd and the relay loop blocks forever waiting for command
completion. See apache#3511

Use dpopen()/dpclose() to obtain the raw bidirectional socket descriptor
directly, restoring the EOF/POLLHUP command-completion signal.

Assisted-by: GitHubCopilot:claude-4.8-opus
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants