VoltaireNoir / blight

A hassle-free CLI utility/library to manage backlight on Linux; one that plays well with hybrid GPU configuration and proprietary drivers.
23 stars 1 forks source link

Use a lockfile to ensure single instance insetad of relying on pgrep #5

Closed VoltaireNoir closed 1 year ago

VoltaireNoir commented 1 year ago

This PR fixes #4 (WIP)

The older implementation relied on a hacky way of checking if another instance was running using pgrep, and even that was faulty or outright bad. It's an amateur mistake that regrettably made its way through multiple releases.

Summary

Instead of fixing the issue by using the -c flag/option to get the number of running instances using pgrep, it's better to use a lock file to allow write access to one instance at a time, to avoid conflicts and race conditions. Multiple instances are now allowed to run, however, only one instance will get to write to the brightness file at a time by acquiring an advisory lock to the lock file. This only affects commands involving write operations (except save and restore), the rest of the commands will not be affected.

The advisory lock is used on the lock file instead of the brightness file to completely avoid touching the library implementation. Therefore, this work will only affect the CLI side of things.

Todo