Handle cases where we fail to write out the buffer

If we didn't write out the entire buffer, some
data would get dropped on the floor. This caused
corruption in files over some connection.
Don't truncate config section names by one

Prevents almost identical names from being
overwritten by each other.
Add required signal header
Improve error diagnostics