added signal handling support to restore stdin state