/* This file is part of Lcrzo.
*/

int lcrzo_process_other_exit(lcrzo_process *pprocess)
#if defined LCRZODEF_SYSTEM_Unix
{ int ret;

  /* parameter verification */
  if (pprocess==NULL) return(LCRZO_ERR_PANULLPTR);

#if LCRZO_PRIV_DATA_ALLOC_DEBUG==2
  /* to be sure everything is displayed */
  lcrzo_time_sleep_msec(300);
#endif

  ret=kill(pprocess->processid, SIGINT);
  if (ret==-1)
  { /* under FreeBSD, killing a Zombie is an error. Moreover, with 
       some algorithms, there might be a time race : so if we try to kill
       al already dead process, we ignore the error. */
    if (errno!=ESRCH) return(LCRZO_ERR_FUKILL);
    /* ignore error */
    errno=0;
  }

  /* wait for it (otherwise, it will be a zombie) */
  lcrzo_er(lcrzo_process_other_wait_end(pprocess, LCRZO_WAIT_INFINITE, 
					NULL, NULL));
  return(LCRZO_ERR_OK);
}
#elif defined LCRZODEF_SYSTEM_Windows
{ 
  /* parameter verification */
  if (pprocess==NULL) return(LCRZO_ERR_PANULLPTR);

  /* get the thread return value */
  /* NOTE : call for TerminateThread is not nice. In future versions, I should
  implement an IPC between father and child to force clean termination */
  if ( ! TerminateThread(pprocess->threadhandle, LCRZO_ERR_OKPROCESSABRUPTTERM) )
  { /* ignore error when thread has already terminated */
    if ( GetLastError()!=ERROR_INVALID_PARAMETER )
    { return(LCRZO_ERR_FUTERMINATETHREAD);
    }
    lcrzo_er(lcrzo_err_purge());
  }

  return(LCRZO_ERR_OK);
}
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

