예제 #1
0
    def add_close_childfds(self, start_fd, except_fd=-1):
        """Add to a SpawnFileAction a series of 'closes' that will close all of
        the fds >= startfd in the child process.  A single fd may be skipped,
        provided that it is given as the optional except argument."""

        if not isinstance(start_fd, int):
            raise TypeError("start_fd must be int type")
        if not isinstance(except_fd, int):
            raise TypeError("except_fd must be int type")

        # Set up walk_data for fdwalk.
        wd = ffi.new("walk_data *", [0])
        wd.skip_fd = ffi.cast("int", except_fd)
        wd.start_fd = ffi.cast("int", start_fd)
        wd.fap = self.fa

        # Perform the walk.
        lib.fdwalk(walk_func, wd)
예제 #2
0
def walk_func(data, fd):
    wd = ffi.cast("walk_data *", data)
    if fd >= wd.start_fd and fd != wd.skip_fd:
        rc = lib.posix_spawn_file_actions_addclose(wd.fap, fd)
        _check_error(rc)
    return 0