Revision 1a8337f2 lib/daemon.py

b/lib/daemon.py
1 1
#
2 2
#
3 3

  
4
# Copyright (C) 2006, 2007, 2008 Google Inc.
4
# Copyright (C) 2006, 2007, 2008, 2010 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
100 100
    return False
101 101

  
102 102

  
103
def FormatAddress(family, address):
104
  """Format a client's address
105

  
106
  @type family: integer
107
  @param family: socket family (one of socket.AF_*)
108
  @type address: family specific (usually tuple)
109
  @param address: address, as reported by this class
110

  
111
  """
112
  if family == socket.AF_INET and len(address) == 2:
113
    return "%s:%d" % address
114
  elif family == socket.AF_UNIX and len(address) == 3:
115
    return "pid=%s, uid=%s, gid=%s" % address
116
  else:
117
    return str(address)
118

  
119

  
120 103
class AsyncStreamServer(GanetiBaseAsyncoreDispatcher):
121 104
  """A stream server to use with asyncore.
122 105

  
......
159 142
        # is passed in from accept anyway
160 143
        client_address = netutils.GetSocketCredentials(connected_socket)
161 144
      logging.info("Accepted connection from %s",
162
                   FormatAddress(self.family, client_address))
145
                   netutils.FormatAddress(self.family, client_address))
163 146
      self.handle_connection(connected_socket, client_address)
164 147

  
165 148
  def handle_connection(self, connected_socket, client_address):
......
290 273

  
291 274
  def close_log(self):
292 275
    logging.info("Closing connection from %s",
293
                 FormatAddress(self.family, self.peer_address))
276
                 netutils.FormatAddress(self.family, self.peer_address))
294 277
    self.close()
295 278

  
296 279
  # this method is overriding an asyncore.dispatcher method

Also available in: Unified diff