Overview
| Artifact ID: | c5af7a98bb469c842ae3fa7943b005e2f01a75be |
|---|---|
| Ticket: | 218120ffffffffffffffffffffffffffffffffff
exec command fails with EINTR |
| User & Date: | nobody on 2001-04-05 22:51:23 |
Changes
- icomment:
Logged In: NO Reproducing this is difficult because it is dependent on what the kernel is doing and what is specifically running on a specific machine at the time. I've noticed a much higher occurrence on hpux 10.20 machines than any others. With that said, I don't believe its necessary to reproduce a problem that is caused by the improper coding of unix io. The low level unix io functions (on some platforms) can be interrupted at any time by the system for any reason. When this occurs the function returns an "error", but this needs to be interpreted. The interpretation is to check errno for EINTR. EINTR implies that the io was simply stopped to allow interrupt handling to occur. Handling the interrupt is actually a non-issue. But if an interrupt handler is in place, it will occur asynchronously to the process and control will be returned to where the io call is. At this point the io should be restarted. No data is ever moved when it is interrupted due to EINTR, so nothing can be lost. If no interrupt handler is in place, the io is still halted and still needs to be restarted. Some of the io functions that do this are read(), write(), fgetc(), and fputc(). Interestingly, wait's also work this way. Take a look at the Tcl 8.3, compat/waitpid.c, and see how the waitpid() function handles return codes from wait() or wait3(). The patch given above may work, but isn't really proper. The real fix should be to root out all of the low level io calls and loop them when the call fails due to EINTR. read() (and probably write()) seems to be the most used offender. read() is simpler but here's an example of fgetc() which shows the "quirkiness" of unix io. cp = buffer; for(i = 0; i<(sizeof(buffer)-1); i++) { /* Read chars until a true EOF/io error or a good char is read */ while ((ch=fgetc(rfp)) == EOF) { if (feof(rfp)) goto eof; if (errno != EAGAIN && errno != EINTR) goto badio; } *cp++ = ch; if(ch == '\n') break; } *cp = 0; Note the checks for fgetc(). An EOF value is returned "if an error occurs", as described in the man page. The "error" now needs to be interpreted. A call to feof() needs to be made on the stream to determine if the EOF returned was indeed an actual EOF. If so, its not an error, just time to process EOF. Now look at the next tests for errno = EAGAIN or EINTR. If the errno is set to these, it still is not an error and the code simply continues. This is really how the io code in tcl should be handling these interrupts rather than trying to propogate EINTR up to a higher level. (Note also that EAGAIN is a possibility that is not handled by the tcl code at all). Higher level code should never have to be concerned with these interrupts. They can install interrupt handlers if they need to see them. Finally, I you don't want to take my word for it, take a look at a unix programming book. Something like "Advanced Programming in the UNIX Environment", by W. Richard Stevens, Addison-Wesley Publishing Company, Copyright 1992, section 10.5, pages 275-277. Page 276 has the following text: "...The typical code sequence (assuming a read operation and assuming we want to restart the read even if it's interrupted) would be again: if ( (n = read(fd, buff, BUFFSIZE) ) < 0) { if (errno == EINTR) goto again; /* just an interrupted system call */ } To prevent the applications from having to handle interrupted system calls 4.2BSD introduced the automatic restarting of certain interrupted system calls..." "...POSIX.1 allows an implementation to restart system calls, but it is not required. System V has never restarted system calls by default... ... With 4.3+BSD the automatic restarting of system calls depends on which function is called to set the signal's disposition..." Its a little weak in the "assuming we want to restart the read" bit. There really is no reason to not restart the read. Especially since some vendors do and some don't. The only way to get consistency across vendors is to restart them. - login: "nobody"
- mimetype: "text/plain"
- username: "nobody"