Re-order code to have functions before the "main" part.

Plus, rename the daemon-loop from "start" to "run_qm_daemon".

refs #209
Stop QM if pidfile writing fails.

refs #209
Add functions for sanity checks.

refs #209
Add sanity checks for HRM logfiles.

refs #209