Exit main_loop cleanly on EOF