resolver un-conditionally restarts interrupted kevent

Christian S.J. Peron csjp at
Wed Jan 26 17:24:01 PST 2005


I've noticed kind of an anoying feature with our resolver. It
seems that if a process recieves a signal while waiting for a
DNS response, kevent(2) will fail returning EINTR which sounds
right. However I also noticed this:

                        n = _kevent(kq, &kv, 1, &kv, 1, &ts);
                        if (n < 0) {
                                if (errno == EINTR) {
                                        (void) gettimeofday(&ctv, NULL);
                                        if (timercmp(&ctv, &timeout, <)) {
                                                timersub(&timeout, &ctv, &ctv);
                                                TIMEVAL_TO_TIMESPEC(&ctv, &ts);
                                                goto wait;

Which un-conditionally restarts kevent(2) in the event of a signal.
Logic tells me that the right way to do this would be to have the
process set SA_RESTART when it registers a signal handler, and have
kevent return ERESTART and IF kevent returns ERESTART, restart the

After further investigation into our multiplexing mechanisms like
poll, select and kevent explicitly change ERESTART to EINTR.

                /* don't restart after signals... */
                if (error == ERESTART)
                        error = EINTR;
                else if (error == EWOULDBLOCK)
                        error = 0;
                goto done;

So I guess I have two questions

	1) why do we explicitly change ERESTART to EINTR?
	2) why do we unconditionally restart kevent in our
	   resolver code?

Any insight would be great, thanks!

Christian S.J. Peron
csjp at FreeBSD.ORG
FreeBSD Committer

More information about the freebsd-arch mailing list