Refactor inhibit_sleep handling on linux to catch errors earlier