Skip to content
Snippets Groups Projects
Commit 069a4bcf authored by Guido Trotter's avatar Guido Trotter
Browse files

Workaround missing SO_PEERCRED


This bug happens in a few new distributions, so we workaround it by
defining the constant ourselves, if it's missing.

Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarThomas Thrainer <thomasth@google.com>
parent ae549364
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,12 @@ from ganeti import vcluster
_STRUCT_UCRED = "iII"
_STRUCT_UCRED_SIZE = struct.calcsize(_STRUCT_UCRED)
# Workaround a bug in some linux distributions that don't define SO_PEERCRED
try:
_SO_PEERCRED = IN.SO_PEERCRED
except AttributeError:
_SO_PEERCRED = 17
# Regexes used to find IP addresses in the output of ip.
_IP_RE_TEXT = r"[.:a-z0-9]+" # separate for testing purposes
_IP_FAMILY_RE = re.compile(r"(?P<family>inet6?)\s+(?P<ip>%s)/" % _IP_RE_TEXT,
......@@ -93,7 +99,7 @@ def GetSocketCredentials(sock):
@return: The PID, UID and GID of the connected foreign process.
"""
peercred = sock.getsockopt(socket.SOL_SOCKET, IN.SO_PEERCRED,
peercred = sock.getsockopt(socket.SOL_SOCKET, _SO_PEERCRED,
_STRUCT_UCRED_SIZE)
return struct.unpack(_STRUCT_UCRED, peercred)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment