Exemplo n.º 1
0
 def server_activate(self):
     HTTPServer.server_activate(self)
     drop_privileges(self.username)
Exemplo n.º 2
0
 def server_activate(self):
     HTTPServer.server_activate(self)
     drop_privileges(self.username)
Exemplo n.º 3
0
def do(par):

    # it's not like we really need the pidfile under the Systemd
    #pidfd = write_pidfile(par.pidfile)

    connections = {}
    poller = select.poll()

    #lsock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
    #lsock.bind(par.usock)
    #lsock.listen(5)
    #poller.register(lsock.fileno(), select.POLLIN|select.POLLERR)

    asock = open_gps_tty(par.gps_dev_path, par.gps_dev_speed)
    conn = NmeaConnection(asock)
    connections[asock.fileno()] = conn
    poller.register(asock.fileno(), select.POLLIN|select.POLLERR)

    asock = fork_rtl_adsb(par.rtl_adsb_path)
    if par.input_mode:
        conn = UatConnection(asock)
    else:
        conn = AdsbConnection(asock)
    connections[asock.fileno()] = conn
    poller.register(asock.fileno(), select.POLLIN|select.POLLERR)

    drop_privileges('glie')

    last = time.time()
    while 1:
        # XXX exit here if no more sockets or rtl_adsb pipe is down (EOF)

        # [(fd, ev)]
        events = poller.poll(FRAME*1000)
        for event in events:
            #if event[0] == lsock.fileno():
            #    (csock, caddr) = lsock.accept()
            #    conn = Connection(csock, tcp_client_event)
            #    connections[csock.fileno()] = conn
            #    poller.register(csock.fileno(), select.POLLIN|select.POLLERR)
            #    send_challenge(conn)
            #    continue

            fd = event[0]
            if fd in connections:
                conn = connections[fd]
                if event[1] & select.POLLNVAL:
                    poller.unregister(fd)
                    connections[fd] = None
                elif event[1] & select.POLLHUP:
                    poller.unregister(fd)
                    connections[fd] = None
                elif event[1] & select.POLLERR:
                    poller.unregister(fd)
                    connections[fd] = None
                elif event[1] & select.POLLIN:
                    conn.recv_event()
                    if conn.state == 2:
                        # XXX Call conn.hup_proc() here and everywhere
                        poller.unregister(fd)
                        connections[fd] = None
                else:
                    poller.unregister(fd)
                    connections[fd] = None
            else:
                print(TAG+": polled unknown fd", fd, file=sys.stderr)
                os.close(fd)
        now = time.time()
        if now >= last + FRAME:
            # 5 minutes to catch anything with our poor receiption
            craft.prune(5*60.0)
            write_out(par.output_path, now)
            last = now
Exemplo n.º 4
0
def do(par):

    # it's not like we really need the pidfile under the Systemd
    #pidfd = write_pidfile(par.pidfile)

    connections = {}
    poller = select.poll()

    #lsock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
    #lsock.bind(par.usock)
    #lsock.listen(5)
    #poller.register(lsock.fileno(), select.POLLIN|select.POLLERR)

    asock = open_gps_tty(par.gps_dev_path, par.gps_dev_speed)
    conn = NmeaConnection(asock)
    connections[asock.fileno()] = conn
    poller.register(asock.fileno(), select.POLLIN | select.POLLERR)

    asock = fork_rtl_adsb(par.rtl_adsb_path)
    if par.input_mode:
        conn = UatConnection(asock)
    else:
        conn = AdsbConnection(asock)
    connections[asock.fileno()] = conn
    poller.register(asock.fileno(), select.POLLIN | select.POLLERR)

    drop_privileges('glie')

    last = time.time()
    while 1:
        # XXX exit here if no more sockets or rtl_adsb pipe is down (EOF)

        # [(fd, ev)]
        events = poller.poll(FRAME * 1000)
        for event in events:
            #if event[0] == lsock.fileno():
            #    (csock, caddr) = lsock.accept()
            #    conn = Connection(csock, tcp_client_event)
            #    connections[csock.fileno()] = conn
            #    poller.register(csock.fileno(), select.POLLIN|select.POLLERR)
            #    send_challenge(conn)
            #    continue

            fd = event[0]
            if fd in connections:
                conn = connections[fd]
                if event[1] & select.POLLNVAL:
                    poller.unregister(fd)
                    connections[fd] = None
                elif event[1] & select.POLLHUP:
                    poller.unregister(fd)
                    connections[fd] = None
                elif event[1] & select.POLLERR:
                    poller.unregister(fd)
                    connections[fd] = None
                elif event[1] & select.POLLIN:
                    conn.recv_event()
                    if conn.state == 2:
                        # XXX Call conn.hup_proc() here and everywhere
                        poller.unregister(fd)
                        connections[fd] = None
                else:
                    poller.unregister(fd)
                    connections[fd] = None
            else:
                print(TAG + ": polled unknown fd", fd, file=sys.stderr)
                os.close(fd)
        now = time.time()
        if now >= last + FRAME:
            # 5 minutes to catch anything with our poor receiption
            craft.prune(5 * 60.0)
            write_out(par.output_path, now)
            last = now