shell-pool / shell-pool/shpool

BUG: shpool attach fails to close file descriptors

Open
#369 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2k
Forks
67
Avg merge
3d 1h
Merged PRs (30d)
15

Description

AI Policy Ack
Ack

What happened
Run this command: shpool attach fd-test --cmd='ls -l /proc/self/fd'

Get output like this:

total 0
lrwx------. 1 codespace codespace 64 May  9 05:26 0 -> /dev/pts/12
lrwx------. 1 codespace codespace 64 May  9 05:26 1 -> /dev/pts/12
lrwx------. 1 codespace codespace 64 May  9 05:26 11 -> /dev/pts/12
lrwx------. 1 codespace codespace 64 May  9 05:26 13 -> /dev/pts/ptmx
lrwx------. 1 codespace codespace 64 May  9 05:26 18 -> /dev/pts/ptmx
lrwx------. 1 codespace codespace 64 May  9 05:26 2 -> /dev/pts/12
lrwx------. 1 codespace codespace 64 May  9 05:26 23 -> /dev/pts/ptmx
lr-x------. 1 codespace codespace 64 May  9 05:26 3 -> /proc/4171019/fd

When we spawn a subprocess, it should only inherit fds 0-2. ls -l will open a third fd to read the target directory. But we shouldn't be inheriting fds like 11,13,18,23.

I guess the issue is the fd is not being opened with O_CLOEXEC? The problem is likely shpool_pty not using that in open call. But then you want to turn it off with FD_SETFD on FD_CLOXEC on fds 0, 1, and 2 just before the exec, so the exec doesn't close them, I guess.

What I expected to happen
Get output like this:

$ ls -l /proc/self/fd
total 0
lrwx------. 1 codespace codespace 64 May  9 05:30 0 -> /dev/pts/15
lrwx------. 1 codespace codespace 64 May  9 05:30 1 -> /dev/pts/15
lrwx------. 1 codespace codespace 64 May  9 05:30 2 -> /dev/pts/15
lr-x------. 1 codespace codespace 64 May  9 05:30 3 -> /proc/292647/fd

To Reproduce
Steps to reproduce the behavior:
shpool attach fd-test --cmd='ls -l /proc/self/fd'

Version info
shpool 0.10.0

Logs
Probably not necessary

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with shpool attach fd-test --cmd='ls -l /proc/self/fd', then inspect the shpool_pty file-descriptor opening and exec path mentioned in the issue. Done means the spawned command inherits only descriptors 0–2, plus the descriptor that ls opens for /proc/self/fd; verify this with the reproduction command.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.