Exemplo n.º 1
0
 def read_child_output(self):
   """
   Reads up to conf.SHELL_OS_READ_AMOUNT bytes from the child subprocess's stdout.
   Returns a tuple of (output, more_available, new_offset).
   The second parameter indicates whether more output might be obtained by
   another call to read_child_output.
   """
   ofd = self._fd
   result = None
   try:
     next_output = os.read(ofd, shell.conf.SHELL_OS_READ_AMOUNT.get())
     self._read_buffer.seek(self._output_buffer_length)
     self._read_buffer.write(next_output)
     length = len(next_output)
     self._output_buffer_length += length
     num_excess_chars = self._output_buffer_length - shell.conf.SHELL_BUFFER_AMOUNT.get()
     if num_excess_chars > 0:
       self._read_buffer.seek(num_excess_chars)
       newval = self._read_buffer.read()
       self._read_buffer.truncate(0)
       self._read_buffer.write(newval)
       self._output_buffer_length = len(newval)
   except OSError, e: # No more output at all
     if e.errno == errno.EINTR:
       pass
     elif e.errno != errno.EAGAIN:
       format_str = "Encountered error while reading from process with PID %d : %s"
       LOG.error( format_str % (self.subprocess.pid, e))
       self.mark_for_cleanup()
Exemplo n.º 2
0
 def read_child_output(self):
   """
   Reads up to conf.SHELL_OS_READ_AMOUNT bytes from the child subprocess's stdout.
   Returns a tuple of (output, more_available, new_offset).
   The second parameter indicates whether more output might be obtained by
   another call to read_child_output.
   """
   ofd = self._fd
   result = None
   try:
     next_output = os.read(ofd, shell.conf.SHELL_OS_READ_AMOUNT.get())
     self._read_buffer.seek(self._output_buffer_length)
     self._read_buffer.write(next_output)
     length = len(next_output)
     self._output_buffer_length += length
     num_excess_chars = self._output_buffer_length - shell.conf.SHELL_BUFFER_AMOUNT.get()
     if num_excess_chars > 0:
       self._read_buffer.seek(num_excess_chars)
       newval = self._read_buffer.read()
       self._read_buffer.truncate(0)
       self._read_buffer.write(newval)
       self._output_buffer_length = len(newval)
   except OSError, e: # No more output at all
     if e.errno == errno.EINTR:
       pass
     elif e.errno != errno.EAGAIN:
       format_str = "Encountered error while reading from process with PID %d : %s"
       LOG.error(format_str % (self.pid, e))
       SHELL_OUTPUT_LOGGER.error(format_str % (self.pid, e))
       self.mark_for_cleanup()
Exemplo n.º 3
0
    def read_child_pipe(self, the_pipe, child):
        while True:
            eventlet.hubs.trampoline(the_pipe, read=True)
            c = os.read(the_pipe, 1)
            if c == 'd':
                self.handle_deadlychild()
                child.active = False

                return
Exemplo n.º 4
0
    def read_tail(self, tail):
        while True:
            buff = os.read(tail.file_descriptor, 1024)
            if not buff:
                return

            buff = buff.decode('utf8')

            # Append to last buffer
            if tail.buffer:
                buff = tail.buffer + buff
                tail.buffer = ""

            lines = buff.splitlines(True)
            if lines[-1][-1] != "\n":  # incomplete line in buffer
                tail.buffer = lines[-1][-1]
                lines = lines[:-1]

            for line in lines:
                self.handler({'message': line[:-1]})
Exemplo n.º 5
0
    def read_tail(self, tail):
        while True:
            buff = os.read(tail.file_descriptor, 1024)
            if not buff:
                return

            buff = buff.decode('utf8')

            # Append to last buffer
            if tail.buffer:
                buff = tail.buffer + buff
                tail.buffer = ""

            lines = buff.splitlines(True)
            if lines[-1][-1] != "\n":  # incomplete line in buffer
                tail.buffer = lines[-1][-1]
                lines = lines[:-1]

            for line in lines:
                self.handler({'message': line[:-1]})
Exemplo n.º 6
0
def get_buffer_output(nodename):
    out = _bufferdaemon.stdin
    instream = _bufferdaemon.stdout
    if not isinstance(nodename, bytes):
        nodename = nodename.encode('utf8')
    outdata = bytearray()
    with _bufferlock:
        out.write(struct.pack('I', len(nodename)))
        out.write(nodename)
        out.flush()
        select.select((instream, ), (), (), 30)
        while not outdata or outdata[-1]:
            try:
                chunk = os.read(instream.fileno(), 128)
            except IOError:
                chunk = None
            if chunk:
                outdata.extend(chunk)
            else:
                select.select((instream, ), (), (), 0)
        return bytes(outdata[:-1])