Esempio n. 1
0
File: daemon.py Progetto: nla/jvmctl
    def handle_read(self):
        """Called when data is available for reading."""
        data, ancdata, _, _ = recvmsg(self.socket, 65536, 4096)

        if not data:
            return self.handle_close()

        fds, cred = parse_ancdata(ancdata)

        if self.header_buffer is not None:
            self.header_buffer += data.decode()

            linefeed = self.header_buffer.find('\n')
            if linefeed == -1:
                return

            header = json.loads(self.header_buffer[:linefeed])
            data = self.header_buffer[linefeed + 1:]
            self.header_buffer = None

            self.handle_header(fds, header)

            if not data:
                return

        meta = Metadata(time=datetime.now(),
                        pid=cred.pid,
                        comm=(comm_for_pid(cred.pid) or "unknown"),
                        unit=(unit_for_pid(cred.pid) or self.unit))

        if meta.unit is not None:
            log = self.log_manager.get(meta.unit, "stdio")
            log.write(data, meta)
Esempio n. 2
0
def recvsocket(control):
    control.wait_for_read()
    result = sendmsg.recvmsg(control.fileno())

    identifier, flags, [(level, type, data)] = result

    fd = struct.unpack('i', data)[0]
    try:
        sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
        sock = coro.coroutine_socket(sock)
    finally:
        os.close(fd)

    return sock
Esempio n. 3
0
def mount_fuse(mount_point):
    rfd, sfd = socketpair(AF_UNIX, SOCK_STREAM)
    newenv = os.environ.copy()

    if not os.fork():
        os.environ['_FUSE_COMMFD'] = str(sfd)
        for i in xrange(3, 1024):
            if i != sfd:
                try:
                    os.close(i)
                except OSError:
                    pass
                os.execl('/usr/bin/fusermount', 'fusermount', mount_point)
    else:
        #s = socket.fromfd(rfd, AF_UNIX, SOCK_STREAM)
        message, flags, ancillary = recvmsg(rfd)
        level, type, fd = ancillary[0]
        return unpack('=i', fd)[0]