Fix checkresult filehandler permissions

Taken from Icinga. Credit to them and Kyle O'Donnell. Reference
Icinga issue #2264.
Fix race condition when opening command file

Taken from Icinga. Credit to them and Matej Vela. Reference
Icinga issue #2400.
Style fixes
Added temporary vim files to .gitignore