HEX
Server: Apache
System: Linux sg241.singhost.net 2.6.32-896.16.1.lve1.4.51.el6.x86_64 #1 SMP Wed Jan 17 13:19:23 EST 2018 x86_64
User: honghock (909)
PHP: 8.0.30
Disabled: passthru,system,shell_exec,show_source,exec,popen,proc_open
Upload Files
File: //usr/lib/python2.7/site-packages/salt/grains/minion_process.py
# -*- coding: utf-8 -*-
'''
Set grains describing the minion process.
'''

# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import os

# Import salt libs
import salt.utils.user
import salt.utils.platform


def _uid():
    '''
    Grain for the minion User ID
    '''
    return salt.utils.user.get_uid()


def _username():
    '''
    Grain for the minion username
    '''
    return salt.utils.user.get_user()


def _gid():
    '''
    Grain for the minion Group ID
    '''
    return salt.utils.user.get_gid()


def _groupname():
    '''
    Grain for the minion groupname
    '''
    try:
        return salt.utils.user.get_default_group(_username()) or ''
    except KeyError:
        return ''


def _pid():
    '''
    Return the current process pid
    '''
    return os.getpid()


def grains():
    '''
    Return the grains dictionary
    '''
    ret = {
        'username': _username(),
        'groupname': _groupname(),
        'pid': _pid(),
    }

    if not salt.utils.platform.is_windows():
        ret['gid'] = _gid()
        ret['uid'] = _uid()

    return ret