The following commit attempts to detect if you're executing with
sudo and to assign the lock file with the correct permissions, to
prevent cryptic error messages.
The code detects sudo using environment variables and correctly
parses the UID and GID from those values, before chown'ing the file.
If at any point there is an error whilst changing the owner, it
will continue as root and on the next run, it will give information
about the file in question. This should then aid diagnosing the
problem without changing the underlying existing flow.
The following commit attempts to detect if you're executing with sudo and to assign the lock file with the correct permissions, to prevent cryptic error messages.
The code detects sudo using environment variables and correctly parses the UID and GID from those values, before chown'ing the file.
If at any point there is an error whilst changing the owner, it will continue as root and on the next run, it will give information about the file in question. This should then aid diagnosing the problem without changing the underlying existing flow.
CC: @howbazaar Background information: https://bugs.launchpad.net/juju/+bug/1758369