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