<i>exec command fails with EINTR</i> status still Closed with 4 other changes
by
.
D 2001-04-05T22:51:23
J icomment Logged\sIn:\sNO\s\n\nReproducing\sthis\sis\sdifficult\sbecause\sit\sis\sdependent\son\nwhat\sthe\skernel\sis\sdoing\sand\swhat\sis\sspecifically\srunning\non\sa\sspecific\smachine\sat\sthe\stime.\sI've\snoticed\sa\smuch\nhigher\soccurrence\son\shpux\s10.20\smachines\sthan\sany\sothers.\n\nWith\sthat\ssaid,\sI\sdon't\sbelieve\sits\snecessary\sto\sreproduce\na\sproblem\sthat\sis\scaused\sby\sthe\simproper\scoding\sof\sunix\sio.\nThe\slow\slevel\sunix\sio\sfunctions\s(on\ssome\splatforms)\scan\sbe\ninterrupted\sat\sany\stime\sby\sthe\ssystem\sfor\sany\sreason.\sWhen\nthis\soccurs\sthe\sfunction\sreturns\san\s"error",\sbut\sthis\sneeds\nto\sbe\sinterpreted.\sThe\sinterpretation\sis\sto\scheck\serrno\sfor\nEINTR.\sEINTR\simplies\sthat\sthe\sio\swas\ssimply\sstopped\sto\sallow\ninterrupt\shandling\sto\soccur.\sHandling\sthe\sinterrupt\sis\nactually\sa\snon-issue.\sBut\sif\san\sinterrupt\shandler\sis\sin\splace,\nit\swill\soccur\sasynchronously\sto\sthe\sprocess\sand\scontrol\swill\nbe\sreturned\sto\swhere\sthe\sio\scall\sis.\sAt\sthis\spoint\sthe\sio\nshould\sbe\srestarted.\sNo\sdata\sis\sever\smoved\swhen\sit\sis\ninterrupted\sdue\sto\sEINTR,\sso\snothing\scan\sbe\slost.\sIf\sno\ninterrupt\shandler\sis\sin\splace,\sthe\sio\sis\sstill\shalted\sand\sstill\nneeds\sto\sbe\srestarted.\n\nSome\sof\sthe\sio\sfunctions\sthat\sdo\sthis\sare\sread(),\swrite(),\nfgetc(),\sand\sfputc().\sInterestingly,\swait's\salso\swork\sthis\nway.\sTake\sa\slook\sat\sthe\sTcl\s8.3,\scompat/waitpid.c,\sand\nsee\show\sthe\swaitpid()\sfunction\shandles\sreturn\scodes\nfrom\swait()\sor\swait3().\n\nThe\spatch\sgiven\sabove\smay\swork,\sbut\sisn't\sreally\sproper.\nThe\sreal\sfix\sshould\sbe\sto\sroot\sout\sall\sof\sthe\slow\slevel\sio\scalls\nand\sloop\sthem\swhen\sthe\scall\sfails\sdue\sto\sEINTR.\sread()\s(and\nprobably\swrite())\sseems\sto\sbe\sthe\smost\sused\soffender.\n\nread()\sis\ssimpler\sbut\shere's\san\sexample\sof\sfgetc()\swhich\nshows\sthe\s"quirkiness"\sof\sunix\sio.\n\n\s\s\s\s\s\scp\s=\sbuffer;\n\s\s\s\s\s\sfor(i\s=\s0;\si<(sizeof(buffer)-1);\si++)\s{\n\s\s\s\s\s\s\s\s\s/*\sRead\schars\suntil\sa\strue\sEOF/io\serror\sor\sa\sgood\schar\sis\sread\s*/\n\s\s\s\s\s\s\s\s\swhile\s((ch=fgetc(rfp))\s==\sEOF)\s{\n\s\s\s\s\s\s\s\s\s\s\s\sif\s(feof(rfp))\sgoto\seof;\n\s\s\s\s\s\s\s\s\s\s\s\sif\s(errno\s!=\sEAGAIN\s&&\serrno\s!=\sEINTR)\sgoto\sbadio;\n\s\s\s\s\s\s\s\s\s}\n\s\s\s\s\s\s\s\s\s*cp++\s=\sch;\n\s\s\s\s\s\s\s\s\sif(ch\s==\s'\\n')\sbreak;\n\s\s\s\s\s\s}\n\s\s\s\s\s\s*cp\s=\s0;\n\nNote\sthe\schecks\sfor\sfgetc().\sAn\sEOF\svalue\sis\sreturned\s"if\san\serror\noccurs",\sas\sdescribed\sin\sthe\sman\spage.\sThe\s"error"\snow\sneeds\nto\sbe\sinterpreted.\sA\scall\sto\sfeof()\sneeds\sto\sbe\smade\son\sthe\sstream\nto\sdetermine\sif\sthe\sEOF\sreturned\swas\sindeed\san\sactual\sEOF.\sIf\sso,\nits\snot\san\serror,\sjust\stime\sto\sprocess\sEOF.\sNow\slook\sat\sthe\snext\ntests\sfor\serrno\s=\sEAGAIN\sor\sEINTR.\sIf\sthe\serrno\sis\sset\sto\sthese,\nit\sstill\sis\snot\san\serror\sand\sthe\scode\ssimply\scontinues.\n\nThis\sis\sreally\show\sthe\sio\scode\sin\stcl\sshould\sbe\shandling\sthese\ninterrupts\srather\sthan\strying\sto\spropogate\sEINTR\sup\sto\sa\shigher\nlevel.\s(Note\salso\sthat\sEAGAIN\sis\sa\spossibility\sthat\sis\snot\shandled\nby\sthe\stcl\scode\sat\sall).\sHigher\slevel\scode\sshould\snever\shave\sto\nbe\sconcerned\swith\sthese\sinterrupts.\sThey\scan\sinstall\sinterrupt\nhandlers\sif\sthey\sneed\sto\ssee\sthem.\n\nFinally,\sI\syou\sdon't\swant\sto\stake\smy\sword\sfor\sit,\stake\sa\slook\nat\sa\sunix\sprogramming\sbook.\sSomething\slike\s"Advanced\nProgramming\sin\sthe\sUNIX\sEnvironment",\sby\sW.\sRichard\sStevens,\nAddison-Wesley\sPublishing\sCompany,\sCopyright\s1992,\ssection\n10.5,\spages\s275-277.\sPage\s276\shas\sthe\sfollowing\stext:\n\n"...The\stypical\scode\ssequence\s(assuming\sa\sread\soperation\sand\nassuming\swe\swant\sto\srestart\sthe\sread\seven\sif\sit's\sinterrupted)\nwould\sbe\n\nagain:\n\s\s\sif\s(\s(n\s=\sread(fd,\sbuff,\sBUFFSIZE)\s)\s<\s0)\s{\n\s\s\s\s\s\sif\s(errno\s==\sEINTR)\n\s\s\s\s\s\s\s\s\sgoto\sagain;\s\s\s\s\s\s\s\s\s/*\sjust\san\sinterrupted\ssystem\scall\s*/\n\s\s\s}\n\nTo\sprevent\sthe\sapplications\sfrom\shaving\sto\shandle\sinterrupted\ssystem\ncalls\s4.2BSD\sintroduced\sthe\sautomatic\srestarting\sof\scertain\sinterrupted\nsystem\scalls..."\n\n"...POSIX.1\sallows\san\simplementation\sto\srestart\ssystem\scalls,\sbut\sit\sis\nnot\srequired.\n\nSystem\sV\shas\snever\srestarted\ssystem\scalls\sby\sdefault...\n\n...\sWith\s4.3+BSD\sthe\sautomatic\srestarting\sof\ssystem\scalls\sdepends\son\nwhich\sfunction\sis\scalled\sto\sset\sthe\ssignal's\sdisposition..."\n\nIts\sa\slittle\sweak\sin\sthe\s"assuming\swe\swant\sto\srestart\sthe\sread"\sbit.\nThere\sreally\sis\sno\sreason\sto\snot\srestart\sthe\sread.\sEspecially\ssince\nsome\svendors\sdo\sand\ssome\sdon't.\sThe\sonly\sway\sto\sget\sconsistency\nacross\svendors\sis\sto\srestart\sthem.\n\n
J login nobody
J mimetype text/plain
J username nobody
K 218120ffffffffffffffffffffffffffffffffff
U nobody
Z bf46b0b009f28aa3b149c6c670fe9989