Fix compiler warnings

Do error checking against getcwd() call in main().
Fix compiler warnings

Added error checking to open(), write() and fchown() calls in
write_pid_file().

Also made some adjustments to style and error log messages in a few
other places.
Style fixes