Fix problems with handling TERM signal.