juju / mutex

Provides a named machine level mutex shareable between processes.
Other
28 stars 11 forks source link

Re-write permissions if running as root #6

Closed SimonRichardson closed 6 years ago

SimonRichardson commented 6 years ago

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

SimonRichardson commented 6 years ago

$$merge$$