bit-team / backintime

Back In Time - An easy-to-use backup tool for GNU Linux using rsync in the back
https://backintime.readthedocs.io
GNU General Public License v2.0
1.9k stars 175 forks source link

fix: Global flock fallback to single-user mode if not enough permissions #1756

Open buhtz opened 3 weeks ago

buhtz commented 3 weeks ago

The global flock context manager (introduced in #1679) now fall back to single-user mode if not enough permissions available to create an flock file accessible by other users and root. The multi-user mode will be activate later until BIT is started as root for the first time. It will create an flock file accessible by all users. That behavior is relevant for Arch-based systems but not relevant on Debian-based systems because regular users have enough permissions to /run/lock. See the docstring for technical details.

It also fix a bug (introduced with #1679) ignoring the config value of global.use_flock.

Additionally I modified and fixed the Sphinx config to make all necessary information about this behavior available in the generated HTML documentation.

Fix #1743 Fix #1751

willemw12 commented 3 weeks ago

How to test this? Is see "INFO: Lock" and "INFO: Unlock". Is that it?

buhtz commented 3 weeks ago

Hello Willem, thanks for the reply and your efforts to test it. Not having an exception/crash is nice to hear. 😄

How to test this? Is see "INFO: Lock" and "INFO: Unlock". Is that it?

You should make sure to activate Run only one snapshot at a time in the Options tab of the Manage profiles (or Profile Settings) dialog? This need to be done for your users BIT profile and for your roots BIT profile.

Run BIT in terminal with --debug option. If BIT doesn't crash, great! 🤣 On Arch running as user, you should find a message like this in the terminal output.

DEBUG: [common/flock.py:67 GlobalFlock._log] Set flock /run/user/1000/backintime.flock by PID 1234.
...
DEBUG: [common/flock.py:67 GlobalFlock._log] Release flock /run/user/1000/backintime.flock by PID 1234.

If running as root the path is different.

DEBUG: [common/flock.py:67 GlobalFlock._log] Set flock /run/lock/backintime.flock by PID 1234.
...
DEBUG: [common/flock.py:67 GlobalFlock._log] Release flock /run/lock/backintime.flock by PID 1234.

When running again as user, after running it as root, the path should also be /run/lock.

willemw12 commented 2 weeks ago

Checked it on Arch in Distrobox, as a non-root user. Also does not crash. (Running as root would require more setup.)