From 646a6c698595658de41cc0684eabce06eeb43657 Mon Sep 17 00:00:00 2001 From: Neraud Date: Wed, 22 Aug 2018 18:34:02 +0200 Subject: [PATCH] Fixed user detection. The USER environment variable is not populated when the plugin is executed. Switched to checking the effective user. --- plugins/git/git_commit_behind | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/git/git_commit_behind b/plugins/git/git_commit_behind index e77d3ed3..bcd07319 100755 --- a/plugins/git/git_commit_behind +++ b/plugins/git/git_commit_behind @@ -114,6 +114,7 @@ GPLv2 import logging import os from pathlib import Path +import pwd from random import randint import re from shlex import quote @@ -128,6 +129,8 @@ if int(os.getenv('MUNIN_DEBUG', 0)) > 0: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-7s %(message)s') +current_user = pwd.getpwuid(os.geteuid())[0] + conf = { 'git_path': os.getenv('git_path', '/usr/bin/git'), 'state_file': os.getenv('MUNIN_STATEFILE'), @@ -170,7 +173,7 @@ def print_config(): def generate_git_command(repo_conf, git_command): - if not repo_conf['user'] or repo_conf['user'] == os.environ['USER']: + if not repo_conf['user'] or repo_conf['user'] == current_user: cmd = [quote(conf['git_path'])] + git_command else: shell_cmd = 'cd %s ; %s %s' % (