Пример #1
0
    def tearDown(self):
        """
        Restore the original SIGCHLD handler and reap processes as long as
        there seem to be any remaining.
        """
        if self.originalHandler is not None:
            signal.signal(signal.SIGCHLD, self.originalHandler)
        if process is not None:
            begin = time.time()
            while process.reapProcessHandlers:
                log.msg(
                    "ReactorBuilder.tearDown reaping some processes %r" % (
                        process.reapProcessHandlers,))
                process.reapAllProcesses()

                # The process should exit on its own.  However, if it
                # doesn't, we're stuck in this loop forever.  To avoid
                # hanging the test suite, eventually give the process some
                # help exiting and move on.
                time.sleep(0.001)
                if time.time() - begin > 60:
                    for pid in process.reapProcessHandlers:
                        os.kill(pid, signal.SIGKILL)
                    raise Exception(
                        "Timeout waiting for child processes to exit: %r" % (
                            process.reapProcessHandlers,))
Пример #2
0
    def tearDown(self):
        """
        Restore the original SIGCHLD handler and reap processes as long as
        there seem to be any remaining.
        """
        if self.originalHandler is not None:
            signal.signal(signal.SIGCHLD, self.originalHandler)
        if process is not None:
            begin = time.time()
            while process.reapProcessHandlers:
                log.msg("ReactorBuilder.tearDown reaping some processes %r" %
                        (process.reapProcessHandlers, ))
                process.reapAllProcesses()

                # The process should exit on its own.  However, if it
                # doesn't, we're stuck in this loop forever.  To avoid
                # hanging the test suite, eventually give the process some
                # help exiting and move on.
                time.sleep(0.001)
                if time.time() - begin > 60:
                    for pid in process.reapProcessHandlers:
                        os.kill(pid, signal.SIGKILL)
                    raise Exception(
                        "Timeout waiting for child processes to exit: %r" %
                        (process.reapProcessHandlers, ))
Пример #3
0
 def check():
     # Handle the exact problem the warning we're testing for is about.
     # If the SIGCHLD arrives before we install our SIGCHLD handler,
     # we'll never see the process exit.  So after the SIGCHLD handler
     # is installed, try to reap children, just in case.
     from twisted.internet.process import reapAllProcesses
     reapAllProcesses()
Пример #4
0
 def check():
     # Handle the exact problem the warning we're testing for is about.
     # If the SIGCHLD arrives before we install our SIGCHLD handler,
     # we'll never see the process exit.  So after the SIGCHLD handler
     # is installed, try to reap children, just in case.
     from twisted.internet.process import reapAllProcesses
     reapAllProcesses()
Пример #5
0
 def mainbody(self):
     """main loop to run actions.
     """
     from twisted.internet.process import reapAllProcesses
     reapAllProcesses()
     zem = self.dmd.ZenEventManager
     self.loadActionRules()
     self.processRules(zem)
Пример #6
0
 def mainbody(self):
     """main loop to run actions.
     """
     from twisted.internet.process import reapAllProcesses
     reapAllProcesses()
     zem = self.dmd.ZenEventManager
     self.loadActionRules()
     self.processRules(zem)
Пример #7
0
    def doRead(self):
        """
        Having woken up the reactor in response to receipt of
        C{SIGCHLD}, reap the process which exited.

        This is called whenever the reactor notices the waker pipe is
        writeable, which happens soon after any call to the C{wakeUp}
        method.
        """
        _FDWaker.doRead(self)
        process.reapAllProcesses()
Пример #8
0
    def doRead(self):
        """
        Having woken up the reactor in response to receipt of
        C{SIGCHLD}, reap the process which exited.

        This is called whenever the reactor notices the waker pipe is
        writeable, which happens soon after any call to the C{wakeUp}
        method.
        """
        _FDWaker.doRead(self)
        process.reapAllProcesses()
Пример #9
0
 def tearDown(self):
     """
     Restore the original SIGCHLD handler and reap processes as long as
     there seem to be any remaining.
     """
     if self.originalHandler is not None:
         signal.signal(signal.SIGCHLD, self.originalHandler)
     if process is not None:
         while process.reapProcessHandlers:
             log.msg("ReactorBuilder.tearDown reaping some processes %r" % (process.reapProcessHandlers,))
             process.reapAllProcesses()
Пример #10
0
 def tearDown(self):
     """
     Restore the original SIGCHLD handler and reap processes as long as
     there seem to be any remaining.
     """
     if self.originalHandler is not None:
         signal.signal(signal.SIGCHLD, self.originalHandler)
     if process is not None:
         while process.reapProcessHandlers:
             log.msg("ReactorBuilder.tearDown reaping some processes %r" %
                     (process.reapProcessHandlers, ))
             process.reapAllProcesses()
Пример #11
0
    def do(self):
        # Run Cuckoo sandbox, parse log output, and report back of Peekaboo.
        srv = CuckooServer(self)
        reactor.spawnProcess(srv, self.interpreter, [self.interpreter, '-u',
                                                     self.cuckoo_exec])

        # do not install twisted's signal handlers because it will screw with
        # our logic (install a handler for SIGTERM and SIGCHLD but not for
        # SIGINT). Instead do what their SIGCHLD handler would do and call the
        # global process reaper.
        reactor.run(installSignalHandlers = False)
        process.reapAllProcesses()
        return self.exit_code
Пример #12
0
 def _handleSignals(self):
     """
     Extend the basic signal handling logic to also support
     handling SIGCHLD to know when to try to reap child processes.
     """
     _SignalReactorMixin._handleSignals(self)
     if platformType == 'posix':
         if not self._childWaker:
             self._childWaker = _SIGCHLDWaker(self)
             self._internalReaders.add(self._childWaker)
             self.addReader(self._childWaker)
         self._childWaker.install()
         # Also reap all processes right now, in case we missed any
         # signals before we installed the SIGCHLD waker/handler.
         # This should only happen if someone used spawnProcess
         # before calling reactor.run (and the process also exited
         # already).
         process.reapAllProcesses()
Пример #13
0
 def _handleSignals(self):
     """
     Extend the basic signal handling logic to also support
     handling SIGCHLD to know when to try to reap child processes.
     """
     _SignalReactorMixin._handleSignals(self)
     if platformType == 'posix' and processEnabled:
         if not self._childWaker:
             self._childWaker = _SIGCHLDWaker(self)
             self._internalReaders.add(self._childWaker)
             self.addReader(self._childWaker)
         self._childWaker.install()
         # Also reap all processes right now, in case we missed any
         # signals before we installed the SIGCHLD waker/handler.
         # This should only happen if someone used spawnProcess
         # before calling reactor.run (and the process also exited
         # already).
         process.reapAllProcesses()
Пример #14
0
    def do(self):
        """ Run Cuckoo sandbox, parse log output, and report back of Peekaboo. """
        command = self.cuckoo_exec.split(' ')

        # allow for injecting a custom interpreter which we use to run cuckoo
        # with python -u for unbuffered standard output
        if self.interpreter:
            command = self.interpreter.split(' ') + command

        reactor.spawnProcess(CuckooServer(self), command[0], command)

        # do not install twisted's signal handlers because it will screw with
        # our logic (install a handler for SIGTERM and SIGCHLD but not for
        # SIGINT). Instead do what their SIGCHLD handler would do and call the
        # global process reaper.
        reactor.run(installSignalHandlers=False)
        process.reapAllProcesses()
        return self.exit_code