BUG: shpool attach fails to close file descriptors

Offen
#369 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
rust

Rechercherichtung

Reproduziere den Bericht mit shpool attach fd-test --cmd='ls -l /proc/self/fd' und untersuche anschließend den im Issue erwähnten Pfad zum Öffnen von Dateideskriptoren und zum Ausführen von shpool_pty. Als erledigt gilt die Aufgabe, wenn der gestartete Befehl nur die Deskriptoren 0–2 sowie den Deskriptor erbt, den ls für /proc/self/fd öffnet; überprüfe dies mit dem Reproduktionsbefehl.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
Rust
Sterne
2k
Forks
70
Ø Merge
2 T. 3 Std.
Gemergte PRs (30 T.)
6

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus shell-pool/shpool

Alle Issues in shell-pool/shpool

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.