def _call(self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0): self._expect_connected() fds = [] def mkfd(fp): if fp in (None, subprocess.STDOUT, subprocess.PIPE): return fp elif isinstance(fp, int): fds.append(fp) else: fds.append(fp.fileno()) return len(fds) - 1 stdin = mkfd(stdin) stdout = mkfd(stdout) stderr = mkfd(stderr) self._cnx.send(((args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags), len(fds))) for fd in fds: _multiprocessing.sendfd(self._cnx.fileno(), fd) return self._cnx.recv()
def handle_REQ_FD(self): bind_address = self.recv_str() logging.info('request fd: %s', bind_address) if bind_address in self.server.fd_map: bound_fd = self.server.fd_map[bind_address] logging.info('sending fd: %s %s', bind_address, bound_fd) self.send_str('OK') _multiprocessing.sendfd(self.request.fileno(), bound_fd) else: logging.info('no match for requested fd: %s %s', bind_address, self.server.fd_map.keys()) self.send_str('ERROR') self.send_str('No fd matching %r on %s %s' % (bind_address, os.getpid(), self.server.fd_map.keys()))
def _call(self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0): self._expect_connected() fds = [] def mkfd(fp): if fp in (None, subprocess.STDOUT, subprocess.PIPE): return fp elif isinstance(fp, int): fds.append(fp) else: fds.append(fp.fileno()) return len(fds) - 1 stdin = mkfd(stdin) stdout = mkfd(stdout) stderr = mkfd(stderr) self._cnx.send( ((args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags), len(fds))) for fd in fds: _multiprocessing.sendfd(self._cnx.fileno(), fd) return self._cnx.recv()
def send_handle(conn, handle, destination_pid): _multiprocessing.sendfd(conn.fileno(), handle)
env = '\n'.join(['PYZY_ENV=1', 'PWD=' + os.environ['PWD']]) def send_int(_int): sock.send(struct.pack('!I', _int)) def send_str(_str): send_int(len(_str)) sock.send(_str) print sys.argv send_str(env) send_int(len(sys.argv)) for arg in sys.argv: send_str(arg) fd = sock.fileno() _multiprocessing.sendfd(fd, sys.stdin.fileno()) _multiprocessing.sendfd(fd, sys.stdout.fileno()) _multiprocessing.sendfd(fd, sys.stderr.fileno()) return_msg_format = '!I' pid = struct.unpack( return_msg_format, sock.recv(struct.calcsize(return_msg_format))) return_msg_format = '!II' return_code, pid = struct.unpack( return_msg_format, sock.recv(struct.calcsize(return_msg_format))) print "return:", return_code, "pid:", pid sys.exit(return_code)
f = open(filename,mode) f_no = f.fileno() except: print >>sys.stderr, 'failed to open file ' + filename sys.exit(2) # Wait for a connection try: connection, client_address = sock.accept() except: print >>sys.stderr, 'failed to accept connection' sys.exit(2) print >>sys.stderr, 'sending file descriptor ' + str(f_no) try: sendfd(connection.fileno(), f_no) except: print >>sys.stderr, 'failed to send file descriptor' sys.exit(2) try: connection.close() except: pass else: try: print >>sys.stderr, 'connecting to ' + uds_name sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connection = sock.connect(uds_name) except: print >>sys.stderr, 'failed to connect'
def _send_fd_via_mp_sendfd(self, fd): """ internal use only """ return _multiprocessing.sendfd(self.clamd_socket.fileno(), fd)
f = open(filename, mode) f_no = f.fileno() except: print >> sys.stderr, 'failed to open file ' + filename sys.exit(2) # Wait for a connection try: connection, client_address = sock.accept() except: print >> sys.stderr, 'failed to accept connection' sys.exit(2) print >> sys.stderr, 'sending file descriptor ' + str(f_no) try: sendfd(connection.fileno(), f_no) except: print >> sys.stderr, 'failed to send file descriptor' sys.exit(2) try: connection.close() except: pass else: try: print >> sys.stderr, 'connecting to ' + uds_name sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connection = sock.connect(uds_name) except: print >> sys.stderr, 'failed to connect'
def sendfds(conn, fds): for fd in fds: _multiprocessing.sendfd(conn.fileno(), fd)