Cannot open or create lease file with custom dnsmasq config

System:
Raspberry Pi 5 8gb
Raspberry Pi OS on Bookworm and aarch64
Versions: core: ge682f69, web: 8e239ec4, FTL: a7e08286

Expected Behavior:
Loading custom configs via misc.etc_dnsmasq_d should either work or tell me my configuration is invalid.

Actual Behavior:
FTL exits.
error in FTL.log:
2025-01-31 14:53:05.333 CRIT Error in dnsmasq configuration: cannot open or create lease file /var/lib/misc/dnsmasq.leases: Permission denied
Full Log:

2025-01-31 14:53:05.328 CET [796M] INFO: ########## FTL started on blueberrypi! ##########
2025-01-31 14:53:05.328 CET [796M] INFO: FTL branch: development
2025-01-31 14:53:05.328 CET [796M] INFO: FTL version: vDev-a7e0828
2025-01-31 14:53:05.328 CET [796M] INFO: FTL commit: a7e08286
2025-01-31 14:53:05.328 CET [796M] INFO: FTL date: 2025-01-30 20:46:46 +0100
2025-01-31 14:53:05.328 CET [796M] INFO: FTL user: pihole
2025-01-31 14:53:05.328 CET [796M] INFO: Compiled for linux/arm64/v8 (compiled on CI) using cc (Alpine 14.2.0) 14.2.0
2025-01-31 14:53:05.330 CET [796M] INFO: Wrote config file:
2025-01-31 14:53:05.330 CET [796M] INFO:  - 152 total entries
2025-01-31 14:53:05.330 CET [796M] INFO:  - 136 entries are default
2025-01-31 14:53:05.330 CET [796M] INFO:  - 16 entries are modified
2025-01-31 14:53:05.330 CET [796M] INFO:  - 0 entries are forced through environment
2025-01-31 14:53:05.330 CET [796M] INFO: Parsed config file /etc/pihole/pihole.toml successfully
2025-01-31 14:53:05.333 CET [796M] INFO: PID of FTL process: 796
2025-01-31 14:53:05.333 CET [796M] CRIT: Error in dnsmasq configuration: cannot open or create lease file /var/lib/misc/dnsmasq.leases: Permission denied
2025-01-31 14:53:05.348 CET [796M] INFO: PID of FTL process: 796
2025-01-31 14:53:05.348 CET [796M] INFO: Database version is 21
2025-01-31 14:53:05.348 CET [796M] INFO: Database successfully initialized
2025-01-31 14:53:05.354 CET [796M] INFO: Imported 705 queries from the on-disk database (it has 705 rows)
2025-01-31 14:53:05.354 CET [796M] INFO: Parsing queries in database
2025-01-31 14:53:05.358 CET [796M] INFO: Imported 705 queries from the long-term database
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Total DNS queries: 705
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Cached DNS queries: 172
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Forwarded DNS queries: 527
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Blocked DNS queries: 6
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Unknown DNS queries: 0
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Unique domains: 57
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Unique clients: 9
2025-01-31 14:53:05.358 CET [796M] INFO:  -> DNS cache records: 6
2025-01-31 14:53:05.358 CET [796M] INFO:  -> Known forward destinations: 8
2025-01-31 14:53:05.467 CET [796M] INFO: FTL is running as user pihole (UID 999)
2025-01-31 14:53:05.467 CET [796M] INFO: Reading certificate from /etc/pihole/tls.pem ...
2025-01-31 14:53:05.468 CET [796M] INFO: Using SSL/TLS certificate file /etc/pihole/tls.pem
2025-01-31 14:53:05.468 CET [796M] INFO: Web server ports:
2025-01-31 14:53:05.468 CET [796M] INFO:   - 80 (HTTP, IPv4, optional)
2025-01-31 14:53:05.468 CET [796M] INFO:   - 443 (HTTPS, IPv4, optional)
2025-01-31 14:53:05.468 CET [796M] INFO:   - 80 (HTTP, IPv6, optional)
2025-01-31 14:53:05.468 CET [796M] INFO:   - 443 (HTTPS, IPv6, optional)
2025-01-31 14:53:05.468 CET [796M] INFO: Restored 2 API sessions from the database
2025-01-31 14:53:09.651 CET [796/T19568] INFO: Received 8/8 valid NTP replies from pool.ntp.org
2025-01-31 14:53:09.651 CET [796/T19568] INFO: Time offset: 1.077354e-01 ms (excluded 0 outliers)
2025-01-31 14:53:09.651 CET [796/T19568] INFO: Round-trip delay: 2.245575e+01 ms (excluded 0 outliers)
2025-01-31 14:53:09.651 CET [796/T19577] INFO: NTP server listening on 0.0.0.0:123 (IPv4)
2025-01-31 14:53:09.651 CET [796/T19578] INFO: NTP server listening on :::123 (IPv6)

My configuration in /etc/dnsmasq.d/hostapd.conf is:

interface=wlan0
dhcp-range=192.168.50.2,192.168.50.20,255.255.255.0,24h

Debug Log: https://tricorder.pi-hole.net/la7WtQY6/

Yes, this is a difficult situation.

When you enabled misc.etc_dnsmasq_d, FTL runs a syntax check on the config files therein and accepts the change only if it succeeds. What you are now reporting,

is not actually a configuration error (I know, the error message implies this) but a runtime issue. This is not really something the configuration checker can foresee as dnsmasq --test does not check for such runtime errors but really only parses the config files and checks for errors.

Quoting man dnsmasq:

       --test Read and syntax check configuration file(s). Exit with code 0 if
              all is OK, or a non-zero code otherwise. Do not  start  up  dns‐
              masq.

What you see now is that FTL acknowledges this issue and that it is impossible to start the DNS resolver. It still continues running as to provide the embedded webserver and the API so you can log in on http://pi.hole/admin and see the error message you quoted without having to ssh into the machine and check any logs. As Pi-hole is very often the first Linux project users are trying, this seems the best solution to offer them a way to easily check what is going on.

I really don't know how to improve on this and am open for a discussion. We could try restoring an older configuration (we have a few backups) but that may not be sufficient and actually cause additional pain. Assume you always had the DHCP configuration and something outside the influence of Pi-hole, e.g., a docker mount option change, etc., causes /var/lib/misc/dnsmasq.leases to become read-only. FTL will not be able to launch dnsmasq even when reverting several steps of configuration iterations.

I looked into the Issue again and found the directory /var/lib/misc/was empty.
After running sudo chmod -R a+w /var/lib/misc/ FTL starts up as expected and was able to create dnsmasq.leases. I am not really sure what could have changed permissions and excluded pihole from this folder.
Now i get a Warning 2025-02-01 12:20:06.722 WARNING WARNING in dnsmasq core: interface wlan0 does not currently exist although it exists and set UP by hostapd (it has no assigned ip tho, because dnsmasq should do that). when trying to connect to the hotspot i get
2025-02-01 12:21:54.446 WARNING WARNING in dnsmasq core: DHCP packet received on wlan0 which has no address

New Debug log: https://tricorder.pi-hole.net/L9wKCHUD/

No, there's some conflict here, the DHCP server never asigns an address to itself. The server's address always has to be configured manually.