Added exit handler for logout commands (ctrl+d, 2xctl+c)

Fixes #594