Question about login_tty source
Adhemerval Zanella
adhemerval.zanella@linaro.org
Wed Sep 2 18:35:50 GMT 2020
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
More information about the Libc-help
mailing list