Rework serc_safe to operate on file descriptors

Initial work by Matthias Kilian tweaks by me.