Handle errors better in functions suppress_error_output() and restore_error_output().

Plus split some code out into the common.h etc.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>