[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ghh5u4zi3w.fsf@gouders.net>
Date: Fri, 05 Dec 2025 23:20:03 +0100
From: Dirk Gouders <dirk@...ders.net>
To: Al Viro <viro@...iv.linux.org.uk>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby
<jslaby@...e.com>, linux-kernel@...r.kernel.org,
linux-newbie@...r.kernel.org
Subject: Re: pty: childs don't always react on close(2)
Al Viro <viro@...iv.linux.org.uk> writes:
> On Fri, Dec 05, 2025 at 10:37:44PM +0100, Dirk Gouders wrote:
>
>> child_pid1 = forkpty(&pty_fd1, NULL, NULL, NULL);
>
> You do realize that it will inherit all your opened descriptors,
> including pty_fd, right?
>
> ...
>> close(pty_fd);
>
> ... which doesn't do anything to the second child's descriptor
> table, including the descriptor that refers to the same opened file.
> IOW, the IO channel (== opened file) is very much opened after
> that close() - descriptors refering to it still exist.
Oh yes, thank you very much!
I use FD_CLOEXEC nearly everywhere in the mentioned program but exactly
not for the pty file descriptors. Oh well...
For completenes, I'll attach the modified test-case.
Would be interesting to hear if there are other possible fixes.
Thank you very much, again,
Dirk
View attachment "test-close-pty.c" of type "text/plain" (2139 bytes)
Powered by blists - more mailing lists