Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Why's ttyname() called twice on start-up?

Being bored the other day, I played a little with strace(1).
Even if zsh runs non-interactively, invoked for example by

  % strace -f zsh -fc exit

I discovered to my astonishment a plethora of readdir() calls, all
skimming through the /dev directory, not only once, but three times!

Turns out that with my old Linux kernel 1.2.13 and libc 5.0.9, the
ttyname() function seems to be costly implemented.  Things improved
since then, under, say, 2.0/5.2.18 only a few getdents() system calls
are needed instead of several hundred readdir()s.  Ignoring the fact
that the implementation of ttyname() is highly system-specific, and
its efficiency may vary - can't the second call to it be avoided?
[With Linux, it's called a third time anyway, internally by getlogin()]

init_io () at init.c:318  (this is 3.0.0)
318             SHTTY = movefd(open(ttyname(0), O_RDWR));
setupvals () at init.c:520
520         if (!(ttystrname = ztrdup(ttyname(SHTTY))))


Messages sorted by: Reverse Date, Date, Thread, Author