Question about login_tty source

Soumendra Ganguly soumendra@tamu.edu
Wed Sep 2 19:01:55 GMT 2020


Sir,
    cpython's pty.fork() uses the old System V method as a fallback as
well. pty.fork()/os.forkpty() is like forkpty(), but they close the
slave end without letting one set slave winsize/termios. Thank you for
the explanation. I will now remove the dead code from my python
login_tty() implementation.

Soumendra

On 9/2/20, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
>
>
> On 19/08/2020 00:01, Soumendra Ganguly via Libc-help wrote:
>> Hello. In /login/login_tty.c, while setting fd to be our controlling
>> tty, we first check #ifdef TIOCSCTTY. This question is about the #else
>> part. In
>>
>> if (fdname)
>> {
>>     if (fd != 0)
>>        (void) close (0);
>>    if (fd != 1)
>>        (void) close (1);
>>    if (fd != 2)
>>        (void) close (2);
>>    newfd = open (fdname, O_RDWR);
>>    (void) close (newfd);
>> }
>>
>> can anyone please explain why we need the following block?
>>
>>    if (fd != 0)
>>        (void) close (0);
>>    if (fd != 1)
>>        (void) close (1);
>>    if (fd != 2)
>>        (void) close (2);
>>
>> If necessary, dup2 should close 0,1, and 2 later anyway.
>
> Since this was added by Roland almost 25 years ago, it seems to be trying
> to
> emulate the TIOCSCTTY for system derived from System V (as indicated by
> this
> stackflow thread [1]).
>
> Back in the day glibc tries to enclose fallbacks to be portable to the
> various
> Unix implementations.  Currently this is just a dead code with various
> shortcomings (as for a lot of the glibc fallback implementation where
> proper
> kernel support was the correct answer) since neither Linux nor Hurd uses
> it.
>
> And it seems that Unixes derived from System V also has moved on from this
> interface, neither Solaris nor Illumos seems to provide it.
>
> https://urldefense.com/v3/__https://stackoverflow.com/questions/51593530/code-explanation-for-glibc-login-tty-function-openttyname-immediately-f__;!!KwNVnqRv!Vtu1n8f09GnQ28wafOTRPvyTWxkgO0bd7c3sHMxR5GQqPjq4jJhaL_8J8kw-ZliJ$
>
>


More information about the Libc-help mailing list