--- portage_exec.py.orig 2005-10-29 18:54:02.000000000 +0900 +++ portage_exec.py 2005-10-29 19:07:21.000000000 +0900 @@ -66,7 +66,7 @@ return spawn(args,uid=uid,opt_name=opt_name,**keywords) # base spawn function -def spawn(mycommand,env={},opt_name=None,fd_pipes=None,returnpid=False,uid=None,gid=None,groups=None,umask=None,logfile=None,path_lookup=True): +def spawn(mycommand,env={},opt_name=None,fd_pipes=None,fd_unused=None,returnpid=False,uid=None,gid=None,groups=None,umask=None,logfile=None,path_lookup=True): if type(mycommand)==types.StringType: mycommand=mycommand.split() myc = mycommand[0] @@ -76,7 +76,12 @@ myc = find_binary(myc) if myc == None: return None - + + if not fd_pipes: + fd_pipes = {0:0, 1:1, 2:2} + if not fd_unused: + fd_unused = [] + mypid=[] if logfile: pr,pw=os.pipe() @@ -88,46 +93,22 @@ return (retval >> 8) # exit code else: return ((retval & 0xff) << 8) # signal - if not fd_pipes: - fd_pipes={} - fd_pipes[0] = 0 fd_pipes[1]=pw fd_pipes[2]=pw - + if not opt_name: opt_name = mycommand[0] myargs=[opt_name] myargs.extend(mycommand[1:]) mypid.append(os.fork()) if mypid[-1] == 0: - # this may look ugly, but basically it moves file descriptors around to ensure no - # handles that are needed are accidentally closed during the final dup2 calls. - trg_fd=[] - if type(fd_pipes)==types.DictType: - src_fd=[] - k=fd_pipes.keys() - k.sort() - for x in k: - trg_fd.append(x) - src_fd.append(fd_pipes[x]) - for x in range(0,len(trg_fd)): - if trg_fd[x] == src_fd[x]: - continue - if trg_fd[x] in src_fd[x+1:]: - new=os.dup2(trg_fd[x],max(src_fd) + 1) - os.close(trg_fd[x]) - try: - while True: - src_fd[s.index(trg_fd[x])]=new - except SystemExit, e: - raise - except: - pass - for x in range(0,len(trg_fd)): - if trg_fd[x] != src_fd[x]: - os.dup2(src_fd[x], trg_fd[x]) - else: - trg_fd=[0,1,2] + for x in fd_pipes: + if x != fd_pipes[x]: + os.dup2(fd_pipes[x], x) + if fd_pipes[x] not in fd_pipes and fd_pipes[x] not in fd_unused: + fd_unused.append(fd_pipes[x]) + for x in fd_unused: + os.close(x) for x in range(0,max_fd_limit): if x not in trg_fd: try: