def _setupSession():
    """
    Link the user keyring into the session keyring. pam_keyinit.so normally
    does this by default, but do it again in case someone made a new session or
    the session was revoked.

    We want to add keys to the user keyring so that they are reachable across
    sessions, and continue to work after the session is revoked due to e.g.
    detaching from screen and closing SSH. But keys are created with
    permissions that require "possession" to read them, where possession means
    the key is reachable via the session keyring. If the session keyring is
    empty, adding a key to any other keyring means that key is not under
    possession and thus not readable even though we own it.

    The fix is to ensure the user keyring is always linked under the session
    keyring so that keys in the user keyring are reachable via the session
    keyring.
    """
    global _keyring
    try:
        _keyutils.link(_keyutils.KEY_SPEC_USER_KEYRING,
                _keyutils.KEY_SPEC_SESSION_KEYRING)
    except __HOLE__:
        # Old keyutils. Downgrade to just using the session keyring directly,
        # because there's no way to look in the user keyring.
        _keyring = _keyutils.KEY_SPEC_SESSION_KEYRING
        return
    except _keyutils.Error as err:
        if err.args[0] != _keyutils.EKEYREVOKED:
            raise
        # Session key was revoked. Make a new session and try again.
        _keyutils.join_session_keyring()
        _keyutils.link(_keyutils.KEY_SPEC_USER_KEYRING,
                _keyutils.KEY_SPEC_SESSION_KEYRING)
dataset/ETHPy150Open sassoftware/conary/conary/lib/keystore.py/_setupSession