<i>Standard channels (stdin, stdout, stderr) on Windows may get broken by dup2()</i> status still Pending with 3 other changes
by
.
D 2018-11-12T19:45:37.962
J icomment @sebres,\sthanks\sfor\scommenting!\r\n\r\nI\sagree\sthe\ssituation\sis\srare\sbacause\s(a)\sit\sis\sWindows-specific,\s(b)\sredirection\sof\sstdin\sat\sruntime\sis\srarely\sused,\sand\s(c)\sthe\sproblem\smanifests\sonce\sper\sseveral\sthousand\scalls.\r\n\r\nIn\smy\sscenario,\sthe\scall\sto\sdup2()\soccurs\safter\sinitialization\sof\sthe\sTcl\schannels.\s\sNote\sthat\sthis\scan\shappen\sin\sthe\sC\scode\sthat\sdoes\snot\sknow\sanything\sabout\sTcl\sat\sall.\sIn\sthis\scase\sthe\shandle\sstored\sby\sTcl\schannel\smight\sbecome\sinvalid\s(and\sit\shappens\sin\smy\scase),\sand\sTcl\shas\sno\smeans\sto\sknow\sabout\sthat.\r\n\r\nIn\smy\scase\sthe\splace\swhere\sdup2()\sis\scalled\sis\saware\sof\sTcl.\sCalling\sTcl_SetStdChannel()\swas\sthe\sfirst\sthing\sI\sconsidered,\sbut\sthe\sproblem\sis\show\sto\srelease\sthe\sexisting\sTcl\schannel\sthat\suses\sinvalidated\shandle.\sThat\schannel\shas\sno\sany\sflag\sthat\swould\sindicate\sthat\sthis\shandle\swas\snot\sproperly\sallocated,\sand\sit\swill\stry\sdeleting\sthat\shandle\son\sdestruction.\sThis\sleads\sto\serror\sindeed.\r\n\r\nAnother\spoint\sis\sthat\scalling\sTcl_SetStdChannel()\swould\sbe\snot\ssufficient:\sby\sthat\stime,\sTcl\sintepretor\sis\salready\screated\sand\shas\sits\sown\scopy\sof\sthe\ssame\schannel,\sthus\sit\sshould\sbe\snecessary\sto\supdate\schannels\sstored\sin\sthe\sinterpretor\sas\swell\s(in\sgeneral\scase\s-\sall\sexisting\sinterpretors).\s\r\n\r\nThe\sproposed\ssolution\sdoes\ssolve\sthe\sproblem\ssince\sit\screates\sthe\sduplicate\sof\sthe\ssystem\shandle\swhich\sis\sthen\sowned\sby\sthe\schannel\sso\sit\scan\sbe\sreleased\ssafely,\sregardless\sof\swhether\sthe\sstandard\sstream\swas\sredefined\sor\snot.\s\r\n\r\nDuplication\sof\sthe\shandle\sdoes\snot\scause\sthe\serror\sbecause\sthe\sdevice\s(console\sin\smy\scase,\sbut\sit\scan\sbe\sdifferent)\sis\snot\sclosed,\sjust\sthe\shandle\sto\sthat\sdevice\sset\sas\s"standard\shandle"\sin\sthe\ssystem\sgets\sclosed\sand\sopened\sagain\s(sometimes\swith\sdifferent\svalue).\r\n\r\nBesides,\syou\scan\sgrep\sthe\scode\sfor\s'GetStdHandle'\sto\ssee\sseveral\sworkarounds\sagainst\sclosing\sof\sthe\sstandard\shandle\swhen\sTcl\schannel\sis\sclosed.\sThese\sworkarounds\scould\sperhaps\sbe\sremoved\safter\sthe\sfix.\sI\shave\snot\stouch\sthem\sthough\sbecause\sthey\smay\sstill\sbe\sneeded\sin\sother\sscenarios.
J login abv
J mimetype text/x-fossil-wiki
K 91c9bc1c457fda269ae18595944fc3c2b54d961d
U abv
Z dfdbca39b2976b2e2189132276914fff