On Wed, May 22, 2013 at 2:59 PM, Guido Trotter <[email protected]> wrote:
> This bug happens in a few new distributions, so we workaround it by > defining the constant ourselves, if it's missing. > > Signed-off-by: Guido Trotter <[email protected]> > --- > lib/netutils.py | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/lib/netutils.py b/lib/netutils.py > index 3b76588..08d6960 100644 > --- a/lib/netutils.py > +++ b/lib/netutils.py > @@ -52,6 +52,13 @@ 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 > + > + > Extra line? > # 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 +100,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) > > -- > 1.7.10.4 > > Rest LGTM, Thanks -- Thomas Thrainer | Software Engineer | [email protected] | Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Katherine Stephens
