summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/msg_daemon.py
blob: 5ca5b09cfbc9ecb589dd7ab97de6288a0c888401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python2
#MythVantage osd message deamon.
#Use the client to send messages to localhost
import socket
import sys
import os
from subprocess import call

server_address = '/run/msg_socket'

# Make sure the socket does not already exist
try:
    os.unlink(server_address)
except OSError:
    if os.path.exists(server_address):
        raise
# Create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Bind the socket to the port
print >>sys.stderr, 'starting up on %s' % server_address
sock.bind(server_address)
#change permissions of socket
os.chmod(server_address,0777)

# Listen for incoming connections
sock.listen(1)

while True:
    # Wait for a connection
    connection, client_address = sock.accept()
    try:
        #print >>sys.stderr, 'connection from', client_address
        msg=""
        # Receive the data in small chunks and retransmit it
        while True:
            data = connection.recv(16)
            msg+=data
            if data:
                continue
            else:
                call(["/usr/LH/bin/lh_message.sh", msg])
                break

    finally:
        # Clean up the connection
        connection.close()