hurd: Avoid extra ctty RPCs in init_dtable ()
authorSergey Bugaev <bugaevc@gmail.com>
Sat, 15 Apr 2023 16:17:18 +0000 (19:17 +0300)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 17 Apr 2023 12:08:12 +0000 (14:08 +0200)
commite55a55acb19400a26db4e7eec6d4649e364bc8d4
treefca631642e03fac830b83537e672dd732303e051
parent76d0f094dd177e303b36d7b77e21673f244a4b53
hurd: Avoid extra ctty RPCs in init_dtable ()

It is common to have (some of) stdin, stdout and stderr point to the
very same port. We were making the ctty RPCs that _hurd_port2fd () does
for each one of them separately:

1. term_getctty ()
2. mach_port_deallocate ()
3. term_open_ctty ()

Instead, let's detect this case and duplicate the ctty port we already
have. This means we do 1 RPC instead of 3 (and create a single protid
on the server side) if the file is our ctty, and no RPCs instead of 1
if it's not. A clear win!

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
hurd/dtable.c