handle MacOS v6 quirk; more DBG
This commit is contained in:
@@ -27,7 +27,7 @@ import syslog
|
||||
PORT = 50003
|
||||
INTERVAL = 10
|
||||
PIDFILE = '/tmp/hbc.pid'
|
||||
DBG = True
|
||||
DBG = False
|
||||
|
||||
sock = None
|
||||
up = True
|
||||
@@ -48,13 +48,16 @@ def getsock(host):
|
||||
try:
|
||||
r=socket.getaddrinfo(host, 50001, 0, 0, socket.SOL_UDP)
|
||||
except socket.gaierror:
|
||||
logm = '%s hbc died: \n%s' % ('getsock', traceback.format_exc())
|
||||
if DBG: print logm
|
||||
return None
|
||||
if r[0][0] == 28:
|
||||
if r[0][0] in [28, 30]:
|
||||
af_type=socket.AF_INET6
|
||||
elif r[0][0] == 2:
|
||||
af_type=socket.AF_INET
|
||||
else:
|
||||
return None
|
||||
print "dont know this net type: %s" % r[0][0]
|
||||
sys.exit(1)
|
||||
if verbose:
|
||||
syslog.syslog("socktype: %s" % af_type)
|
||||
sock=socket.socket(af_type, socket.SOCK_DGRAM)
|
||||
@@ -70,6 +73,7 @@ def socksend(msg, tohost):
|
||||
|
||||
if sock == None:
|
||||
sock=getsock(tohost[0])
|
||||
if DBG: print "socksend: sending msg=%s on socket=%s" % (msg, sock)
|
||||
sock.sendto(msg, tohost)
|
||||
if verbose: syslog.syslog("msg %s sent" % msg)
|
||||
|
||||
@@ -111,6 +115,8 @@ def process():
|
||||
if verbose: syslog.syslog("sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port))
|
||||
socksend(msg, (hb_host, hb_port))
|
||||
except:
|
||||
logm = '%s hbc died: \n%s' % ('socksend', traceback.format_exc())
|
||||
if DBG: print logm
|
||||
pass
|
||||
|
||||
|
||||
@@ -235,6 +241,7 @@ if not msgonly:
|
||||
msgboot.append("interval=%s" % interval)
|
||||
|
||||
if len(msgboot) > 0:
|
||||
if DBG: print "on boot"
|
||||
msgboot.append("name=%s" % iam)
|
||||
msgboot.append("time=%s" % time.time())
|
||||
msgboot.append("acks=0")
|
||||
@@ -243,9 +250,11 @@ if len(msgboot) > 0:
|
||||
fail=0
|
||||
for hb_host in hb_hosts:
|
||||
try:
|
||||
if verbose: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port)
|
||||
if DBG: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port)
|
||||
socksend(msg, (hb_host, hb_port))
|
||||
except:
|
||||
logm = '%s hbc died: \n%s' % ('socksend2', traceback.format_exc())
|
||||
if DBG: print logm
|
||||
fail=1
|
||||
if fail:
|
||||
time.sleep(10)
|
||||
|
||||
Reference in New Issue
Block a user