sshd.c:server_accept_loop(): avoidable skip of valid socket on eintr

Steffen Nurpmeso steffen at sdaoden.eu
Sun Mar 6 05:31:26 AEDT 2022


Hello.

Just was rebasing my ssh-agent patch, looking at the overall
differences, had a look at sshd.c and stumbled over

                for (i = 0; i < num_listen_socks; i++) {
                        if (!(pfd[i].revents & POLLIN))
                                continue;
                        fromlen = sizeof(from);
                        *newsock = accept(listen_socks[i],
                            (struct sockaddr *)&from, &fromlen);
                        if (*newsock == -1) {
                                if (errno != EINTR && errno != EWOULDBLOCK &&
                                    errno != ECONNABORTED && errno != EAGAIN)
                                        error("accept: %.100s",
                                            strerror(errno));
                                if (errno == EMFILE || errno == ENFILE)
                                        usleep(100 * 1000);
                                continue;

where this continue skips over pfd[i] without actually working it,
even on EINTR .. which can happen because the SIG_BLOCK has been
undone after ppoll(2) returns.  I mean it will show up again when
the loop ticks next, but skipping over a valid socket that
triggered seems so .. wasteful?  Is it really this "so what, then
next time"?

(I personally would BLOCK all the time and only use ppoll(2) for
the other mask, like this that EINTR case is even impossible, and
all the other code around would not need to watch out; most does
not anyway; and actual handling occurs once the loop ticks only.
Maybe i should even rewrite the ssh-agent patch like that?)

Ciao,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)


More information about the openssh-unix-dev mailing list