* Question about login_tty source
@ 2020-08-19 3:01 Soumendra Ganguly
2020-09-02 18:35 ` Adhemerval Zanella
0 siblings, 1 reply; 3+ messages in thread
From: Soumendra Ganguly @ 2020-08-19 3:01 UTC (permalink / raw)
To: libc-help
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.
Thank you in advance.
Soumendra
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question about login_tty source
2020-08-19 3:01 Question about login_tty source Soumendra Ganguly
@ 2020-09-02 18:35 ` Adhemerval Zanella
2020-09-02 19:01 ` Soumendra Ganguly
0 siblings, 1 reply; 3+ messages in thread
From: Adhemerval Zanella @ 2020-09-02 18:35 UTC (permalink / raw)
To: Soumendra Ganguly, libc-help
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://stackoverflow.com/questions/51593530/code-explanation-for-glibc-login-tty-function-openttyname-immediately-f
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question about login_tty source
2020-09-02 18:35 ` Adhemerval Zanella
@ 2020-09-02 19:01 ` Soumendra Ganguly
0 siblings, 0 replies; 3+ messages in thread
From: Soumendra Ganguly @ 2020-09-02 19:01 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: libc-help
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$
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-02 19:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 3:01 Question about login_tty source Soumendra Ganguly
2020-09-02 18:35 ` Adhemerval Zanella
2020-09-02 19:01 ` Soumendra Ganguly
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).