Logo Search packages:      
Sourcecode: nagios-plugins version File versions  Download package

def utils::Task::Run (   self,
  usesh = 0,
  detach = 0,
  stdout = None,
  stdin = None,
  stderr = None 
)
Actually run the process.
   This method should be called exactly once.
   optional arguments:
       usesh=0: if 1, run 'sh -c command', if 0, split the
        command into words, and run it by ourselves.
        If usesh=1, the 'Kill' method might not do what
        you want (it will kill the 'sh' process, not the
        command).
       detach=0: if 1, run 'sh -c 'command&' (regardless of
         'usesh'). Since the 'sh' process will immediately
         terminate, the task created will be inherited by
         'init', so you can safely forget it.  Remember that if
         detach=1, Kill(), Done() and Status() will manipulate
         the 'sh' process; there is no way to find out about the
         detached process.
       stdout=None: filename to use as stdout for the child process.
            If None, the stdout of the parent will be used.
       stdin= None: filename to use as stdin for the child process.
            If None, the stdin of the parent will be used.
       stderr=None: filename to use as stderr for the child process.
            If None, the stderr of the parent will be used.
   return value:                            
       None

Definition at line 89 of file utils.py.

                                                                     :
        """Actually run the process.
           This method should be called exactly once.
           optional arguments:
               usesh=0: if 1, run 'sh -c command', if 0, split the
                        command into words, and run it by ourselves.
                        If usesh=1, the 'Kill' method might not do what
                        you want (it will kill the 'sh' process, not the
                        command).
               detach=0: if 1, run 'sh -c 'command&' (regardless of
                         'usesh'). Since the 'sh' process will immediately
                         terminate, the task created will be inherited by
                         'init', so you can safely forget it.  Remember that if
                         detach=1, Kill(), Done() and Status() will manipulate
                         the 'sh' process; there is no way to find out about the
                         detached process.
               stdout=None: filename to use as stdout for the child process.
                            If None, the stdout of the parent will be used.
               stdin= None: filename to use as stdin for the child process.
                            If None, the stdin of the parent will be used.
               stderr=None: filename to use as stderr for the child process.
                            If None, the stderr of the parent will be used.
           return value:                            
               None
        """
        if self.pid!=None:
            raise error("Second run on task forbidden")
        self.pid=os.fork()
        if not self.pid:
            for fn in range(3,256): # Close all non-standard files in a safe way
                try:
                    os.close(fn)
                except os.error:
                    pass
          #
          # jaclu@galdrion.com 2000-07-14
          #
          # I changed this bit somewhat, since Nagios plugins
          # should send only limited errors to the caller
          # The original setup here corupted output when there was an error.
          # Instead the caller should check result of Wait() and anything
          # not zero should be reported as a failure.
          #
          try:
            if stdout: # Replace stdout by file
                os.close(1)
                i=os.open(stdout,os.O_CREAT|os.O_WRONLY|os.O_TRUNC,0666)
                if i!=1:
                  sys.stderr.write("stdout not opened on 1!\n")
            if stdin: # Replace stdin by file
                os.close(0)
                i=os.open(stdin,os.O_RDONLY)
                if i!=0:
                  sys.stderr.write("stdin not opened on 0!\n")
            if stderr: # Replace stderr by file
                os.close(2)
                i=os.open(stderr,os.O_CREAT|os.O_WRONLY|os.O_TRUNC,0666)
                if i!=2:
                  sys.stdout.write("stderr not opened on 2!\n")
            #try:
                if detach:
                    os.execv('/bin/sh',('sh','-c',self.cmd+'&'))
                elif usesh:
                    os.execv('/bin/sh',('sh','-c',self.cmd))
                else:
                    os.execvp(self.words[0],self.words)
            except:
                #print self.words
                #sys.stderr.write("Subprocess '%s' execution failed!\n"%self.cmd)
                sys.exit(1)
        else:
            # Mother process
            if detach:
                # Should complete "immediately"
                self.Wait()


Generated by  Doxygen 1.6.0   Back to index