Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reuse of pty slave devices #2449

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

cgull
Copy link
Contributor

@cgull cgull commented Aug 31, 2024

This should fix the problem brought up by @francoisvignon in my original work on #2387. At the time I wrote that I hadn't even thought about pty masters allowing serial reuse of the pty slave, and so it worked more like physical serial devices, where you don't want them to work after the modem hangs up.

This is definitely one of those less well documented and supported bits of functionality in ptys (there are many). But it seems like a good idea to support this because Linux does.

@@ -446,6 +446,7 @@ static ssize_t tty_read(struct fd *fd, void *buf, size_t bufsize) {
lock(&tty->lock);
if (tty->hung_up || pty_is_half_closed_master(tty)) {
unlock(&pids_lock);
err = -1;
Copy link
Member

Choose a reason for hiding this comment

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

This should be an errno constant

// hang_up on the pty master. But the session leader may have a
// reference, and the pty master always has a reference.
if (tty->refcount - 1 == (tty->session ? 2 : 1)) {
tty->pty.other->hung_up = false;
Copy link
Member

Choose a reason for hiding this comment

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

This needs locking, right?

// If userland's reference count on the pty slave is now 1, clear
// hang_up on the pty master. But the session leader may have a
// reference, and the pty master always has a reference.
if (tty->refcount - 1 == (tty->session ? 2 : 1)) {
Copy link
Member

Choose a reason for hiding this comment

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

I found this check a bit unsettling in the last PR but figured it could be fixed later. Seeing it again, I'm thinking much the same thing... Ideally we would define explicitly which references count for this and which ones don't, and with that knowledge the likely solution is to create a second refcount field for tracking just those.

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.

4 participants