1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 18:38:30 +00:00

Merge pull request #938 from Neraud/git_commit_behind_fixed_shell

Git commit behind fixed shell
This commit is contained in:
Lars Kruse 2018-09-10 19:15:44 +02:00 committed by GitHub
commit 81833d05e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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,14 +173,14 @@ 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' % (
quote(repo_conf['path']), quote(repo_conf['path']),
quote(conf['git_path']), quote(conf['git_path']),
' '.join(git_command)) ' '.join(git_command))
cmd = ['su', '-', repo_conf['user'], '-c', shell_cmd] cmd = ['su', '-', repo_conf['user'], '-s', '/bin/sh', '-c', shell_cmd]
return cmd return cmd