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
[x] Error handling
[x] Report to the user when waiting to acquire the lock
[x] Consider whether locking is required for save/restore
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