Fix stty parsing on HP/UX
Handle out-of-order restore() calls

This avoids an NPE in ShutdownHooks.remove
Merge branch 'pulls/147'