Skip to content

Commit

Permalink
(GH-552) Fix home directory evaluation
Browse files Browse the repository at this point in the history
Prior to this commit the module would fail when executed under the
context of systemd.

This was because Dir.home tries to expand `~` when
no UID is passed.
However the HOME environment variable is not available
when the agent is executed by systemd resulting in the following error:

`Could not evaluate: couldn't find login name -- expanding ~`

This commit fixes this by reverting to using Etc.getpwuid so that we can
retrieve the home dir from the  uid of the current process.

For consistency, retrieval of home dirs for a given user has also been
changed to use Etc.getpwnam.
  • Loading branch information
chelnak committed Jun 29, 2022
1 parent c23a38e commit 28c8a65
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/puppet/provider/vcsrepo/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,11 @@ def exec_git(*args)
exec_args = {
failonfail: true,
combine: true,
custom_environment: { 'HOME' => Dir.home },
custom_environment: { 'HOME' => Etc.getpwuid(Process.uid).dir },
}

if @resource.value(:user) && @resource.value(:user) != Facter['id'].value
exec_args[:custom_environment] = { 'HOME' => Dir.home(@resource.value(:user)) }
exec_args[:custom_environment] = { 'HOME' => Etc.getpwnam(@resource.value(:user)).dir }
exec_args[:uid] = @resource.value(:user)
end
Puppet::Util::Execution.execute([:git, args], **exec_args)
Expand Down

0 comments on commit 28c8a65

Please sign in to comment.