2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Fixed user detection.

The USER environment variable is not populated when the plugin is executed. Switched to checking the effective user.
This commit is contained in:
Neraud 2018-08-22 18:34:02 +02:00
parent d5caa85c06
commit 646a6c6985

View File

@ -114,6 +114,7 @@ GPLv2
import logging import logging
import os import os
from pathlib import Path from pathlib import Path
import pwd
from random import randint from random import randint
import re import re
from shlex import quote from shlex import quote
@ -128,6 +129,8 @@ if int(os.getenv('MUNIN_DEBUG', 0)) > 0:
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-7s %(message)s') format='%(asctime)s %(levelname)-7s %(message)s')
current_user = pwd.getpwuid(os.geteuid())[0]
conf = { conf = {
'git_path': os.getenv('git_path', '/usr/bin/git'), 'git_path': os.getenv('git_path', '/usr/bin/git'),
'state_file': os.getenv('MUNIN_STATEFILE'), 'state_file': os.getenv('MUNIN_STATEFILE'),
@ -170,7 +173,7 @@ def print_config():
def generate_git_command(repo_conf, git_command): 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 cmd = [quote(conf['git_path'])] + git_command
else: else:
shell_cmd = 'cd %s ; %s %s' % ( shell_cmd = 'cd %s ; %s %s' % (