Ejemplo n.º 1
0
    def spawn(self, wait=False, silent=False):
        if not os.path.isfile(self._file):
            raise OverlordException("%s not found" % (self._file, ))

        """Fork and exec the target process."""
        pid = os.fork()

        if pid == 0:
            # child

            if silent:
                fd = os.open("/dev/null", os.O_APPEND)
                os.dup2(fd, sys.stdout.fileno())
            sys.stdout.flush()

            os.execvp(self._file, self._args)
            exit(1)

        elif pid > 0:
            # parent
            if wait:
                pid, status = os.wait()
        else:
            os.perror("fork failed")
            pid = -1

        self._pid = pid
Ejemplo n.º 2
0
    def spawn(self, wait=False, silent=False):
        if not os.path.isfile(self._file):
            raise OverlordException("%s not found" % (self._file, ))
        """Fork and exec the target process."""
        pid = os.fork()

        if pid == 0:
            # child

            if silent:
                fd = os.open("/dev/null", os.O_APPEND)
                os.dup2(fd, sys.stdout.fileno())
            sys.stdout.flush()

            os.execvp(self._file, self._args)
            exit(1)

        elif pid > 0:
            # parent
            if wait:
                pid, status = os.wait()
        else:
            os.perror("fork failed")
            pid = -1

        self._pid = pid
Ejemplo n.º 3
0
def reset_redirection(stdout_save, stdin_save):
    sys.stdout.flush()
    result = os.dup2(stdout_save, 1)
    if result == -1:
        os.perror("dup2")
        exit(2)

    sys.stdin.flush()
    result = os.dup2(stdin_save, 0)
    if result == -1:
        os.perror("dup2")
        exit(2)
Ejemplo n.º 4
0
    def run(self):
        bin = "../scripts/vf_server.py"

        pid = os.fork()
        if not pid:
            # fork twice to avoid zombies
            pid2 = os.fork()
            if not pid2:
                os.execv("/home/devel/alikins/hg/virt/service/scripts/vf_server.py", ["vf_server.py"])
                # exec -should- never return
                os.perror(_("execv didn't execv?"))
            else:
                # call _exit so we don't mess up filehandles, etc
                os._exit(-1)
Ejemplo n.º 5
0
def redirect(file_name, redirect_location):
    if redirect_location == 0:
        file = os.open(file_name, os.O_RDONLY)
    else:
        file = os.open(file_name, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)  #0644
    fcntl.fcntl(file, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
    if file == -1:
        os.perror("dup2")
        exit(1)

    sys.stdout.flush()
    sys.stdin.flush()

    result = os.dup2(file, redirect_location)
    if file == -1:
        os.perror("dup2")
        exit(2)
Ejemplo n.º 6
0
def command_other(exe_st):
    stdin_save = os.dup(0)
    stdout_save = os.dup(1)

    childExitStatus = -5

    spawnpid = os.fork()
    if spawnpid == -1:
        print("Error")
    elif spawnpid == 0:
        exe = is_redirected(exe_st)
        if exe[0][0] == '#':
            exe[0] = ""

        if exe[0] != "":
            sys.stdout.flush()
            os.execvp(exe[0], exe)
            os.perror(exe[0])

        exit()
    else:
        reset_redirection(stdout_save, stdin_save)
        os.waitpid(spawnpid, 0)