hectorm / hblock

Improve your security and privacy by blocking ads, tracking and malware domains.
https://hblock.molinero.dev
MIT License
1.58k stars 104 forks source link

Cannot add my custom lines to header when using systemd service #84

Closed seth100 closed 2 years ago

seth100 commented 2 years ago

Describe the bug: I added some custom lines in ~/.config/hblock/header and they are taken only when manually executing hblock. If it's executed via systemd service, that file is ignored and my custom lines not added to the final /etc/hosts file!

Steps to reproduce: Create ~/.config/hblock/header file and add your custom lines in it. Then run hblock and you'll see those lines in the /etc/hosts file. Then wait for systemd task to be executed or just restart the system, the final /etc/hosts file will not contain custom lines.

Expected behavior: I expect the final /etc/hosts file to have my custom lines (from ~/.config/hblock/header)

Environment:

Additional context: I tried to create /etc/systemd/system/hblock.service.d/override.conf and to add:

[Service]
Environment=HBLOCK_HEADER_FILE=/home/myhome/.config/hblock/header

and, after reloading deamon and restarting hblock.service I got an error:

oct 25 16:29:25 myhome systemd[1]: Starting hBlock...
oct 25 16:29:25 myhome env[35116]: [ERROR] No such file: /home/myhome/.config/hblock/header
oct 25 16:29:25 myhome systemd[1]: hblock.service: Main process exited, code=exited, status=1/FAILURE
oct 25 16:29:25 myhome systemd[1]: hblock.service: Failed with result 'exit-code'.
oct 25 16:29:25 myhome systemd[1]: Failed to start hBlock.

(I also tried to use the absolute path: Environment=HBLOCK_HEADER_FILE=${XDG_CONFIG_HOME}/hblock/header, but same result and similar error).

hectorm commented 2 years ago

If you are using the systemd service the recommended place to have your custom header is /etc/hblock/header.

The reason why even specifying the HBLOCK_HEADER_FILE variable produces an error is because for security reasons the service has ProtectHome=yes set.

seth100 commented 2 years ago

oh I see, got it! Thank you for confirming that and thanks for your work!