emacs: fix #952 by wrapping dup2 internally (#956)