There's a race in ratrace. If started with a -c, the child must first set hang on itself. But wait! There's more! Before the parent restarts the child, it should set nohang on it -- nohang is inherited across exec and, since we're already tracing the child, nohang causes real trouble when the child forks. So, summary: child of -c command sets hang, and parent is careful to clear it. Sadly, however, this makes it hard for some reason for ratrace to trace ratrace :-( something more is still needed. This change is tested on x86 but not ARM yet. Notes: Mon Mar 7 13:53:48 EST 2011 geoff Ron realizes there is more to do. Reference: /n/sources/patch/sorry/ratrace-race Date: Fri Mar 4 07:54:34 CET 2011 Signed-off-by: rminnich@gmail.com Reviewed-by: geoff --- /sys/src/cmd/ratrace.c Fri Mar 4 07:54:16 2011 +++ /sys/src/cmd/ratrace.c Fri Mar 4 07:54:14 2011 @@ -52,6 +52,7 @@ die(smprint("%s: %r", truss)); cwrite(cfd, ctl, "stop", 4); + cwrite(cfd, ctl, "nohang", 6); cwrite(cfd, truss, "startsyscall", 12); s = mallocz(sizeof(Str) + Bufsize, 1); @@ -169,6 +170,15 @@ if (pid < 0) sysfatal("fork failed: %r"); if(pid == 0) { + char *ctl; + int cfd; + ctl = smprint("/proc/%d/ctl", getpid()); + if ((cfd = open(ctl, OWRITE)) < 0) + die(smprint("%s: %r", ctl)); + cwrite(cfd, ctl, "hang", 4); + /* make sure the cfd is closed! */ + close(cfd); + /* storage leak? we're doing an exec! */ exec(cmd, args); if(cmd[0] != '/') exec(smprint("/bin/%s", cmd), args);