Logo Search packages:      
Sourcecode: condor version File versions  Download package

int DaemonCore::Shutdown_Fast ( pid_t  pid,
bool  want_core = false 
)

Not_Yet_Documented

Parameters:
pid Not_Yet_Documented
Returns:
Not_Yet_Documented

Definition at line 4941 of file daemon_core.cpp.

References clearSession(), and Shutdown_Graceful().

Referenced by Dag::RemoveRunningScripts().

{
      (void) want_core;       // For windoze

      dprintf(D_PROCFAMILY,"called DaemonCore::Shutdown_Fast(%d)\n",
            pid);

      if ( pid == ppid )
            return FALSE;           // cannot shut down our parent

    // Clear sessions associated with the child
    clearSession(pid);

#if defined(WIN32)
      // even on a shutdown_fast, first try to send a WM_CLOSE because
      // when we call TerminateProcess, any DLL's do not get a chance to
      // free allocated memory.
      if ( Shutdown_Graceful(pid) == TRUE ) {
            // we successfully sent a WM_CLOSE.
            // sleep a quarter of a second for the process to consume the WM_CLOSE
            // before we call TerminateProcess below.
            Sleep(250);
      }
      // now call TerminateProcess as a last resort
      PidEntry *pidinfo;
      HANDLE pidHandle;
      bool must_free_handle = false;
      int ret_value;
      if (pidTable->lookup(pid, pidinfo) < 0) {
            // could not find a handle to this pid in our table.
            // try to get a handle from the NT kernel
            pidHandle = ::OpenProcess(PROCESS_TERMINATE,FALSE,pid);
            if ( pidHandle == NULL ) {
                  // process must have gone away.... we hope!!!!
                  return FALSE;
            }
            must_free_handle = true;
      } else {
            // found this pid on our table
            pidHandle = pidinfo->hProcess;
      }

      if( (DebugFlags & D_PROCFAMILY) && (DebugFlags & D_FULLDEBUG) ) {
                  char check_name[MAX_PATH];
                  CSysinfo sysinfo;
                  sysinfo.GetProcessName(pid,check_name, sizeof(check_name));
                  dprintf(D_PROCFAMILY,
                        "Shutdown_Fast(%d):calling TerminateProcess handle=%x check_name='%s'\n",
                        pid,pidHandle,check_name);
      }

      if (TerminateProcess(pidHandle,0)) {
            dprintf(D_PROCFAMILY,
                  "Shutdown_Fast:Successfully terminated pid %d\n", pid);
            ret_value = TRUE;
      } else {
            // TerminateProcess failed!!!??!
            // should we try anything else here?
            dprintf(D_PROCFAMILY,
                  "Shutdown_Fast: Failed to TerminateProcess on pid %d\n",pid);
            ret_value = FALSE;
      }
      if ( must_free_handle ) {
            ::CloseHandle( pidHandle );
      }
      return ret_value;
#else
      priv_state priv = set_root_priv();
      int status = kill(pid, want_core ? SIGABRT : SIGKILL );
      set_priv(priv);
      return (status >= 0);         // return 1 if kill succeeds, 0 otherwise
#endif
}


Generated by  Doxygen 1.6.0   Back to index