stderr can differ from STDERR_FILENO
moved shared code into common directory.