pass all three std fds.
simplify attach/detach logic; get rid of goto; handle Detached condition.
log changes