Implement ext:terminate-process

This commit is contained in:
Elias Pipping 2016-09-06 12:22:24 +00:00
parent 05ecb5dfd0
commit ee0152431c
6 changed files with 34 additions and 1 deletions

View file

@ -39,6 +39,9 @@ arity dependent on platform) is also possible.
- ext:random-state-array: new extension for random-states. Usage:
=(ext:random-state-array random-state)=.
- ext:terminate-process: new extension for external processes. Usage:
=(ext:terminate-process process)= with a second, optional argument.
** Enhancements
- Initial port for the Haiku platform
The port is done by Kacper Kasper's work, one of Haiku developers.

View file

@ -1225,6 +1225,7 @@ cl_symbols[] = {
{SYS_ "REPLACE-ARRAY", SI_ORDINARY, si_replace_array, 2, OBJNULL},
{SYS_ "ROW-MAJOR-ASET", SI_ORDINARY, si_row_major_aset, 3, OBJNULL},
{EXT_ "RUN-PROGRAM", EXT_ORDINARY, si_run_program, -1, OBJNULL},
{EXT_ "TERMINATE-PROCESS", EXT_ORDINARY, ext_terminate_process, -1, OBJNULL},
{SYS_ "WAIT-FOR-ALL-PROCESSES", SI_ORDINARY, si_wait_for_all_processes, -1, OBJNULL},
{EXT_ "SAFE-EVAL", EXT_ORDINARY, ECL_NAME(si_safe_eval), -1, OBJNULL},
{SYS_ "SCH-FRS-BASE", SI_ORDINARY, si_sch_frs_base, 2, OBJNULL},

View file

@ -1225,6 +1225,7 @@ cl_symbols[] = {
{SYS_ "REPLACE-ARRAY","si_replace_array"},
{SYS_ "ROW-MAJOR-ASET","si_row_major_aset"},
{EXT_ "RUN-PROGRAM","si_run_program"},
{EXT_ "TERMINATE-PROCESS","ext_terminate_process"},
{SYS_ "WAIT-FOR-ALL-PROCESSES","si_wait_for_all_processes"},
{EXT_ "SAFE-EVAL","ECL_NAME(si_safe_eval)"},
{SYS_ "SCH-FRS-BASE","si_sch_frs_base"},

View file

@ -301,6 +301,33 @@ ecl_waitpid(cl_object pid, cl_object wait)
@(return status code pid);
}
@(defun ext::terminate-process (process &optional (force ECL_NIL))
@
{
cl_env_ptr env = ecl_process_env();
bool error_encountered = FALSE;
ECL_WITH_SPINLOCK_BEGIN(env, &cl_core.external_processes_lock);
{
cl_object pid = external_process_pid(process);
if (!Null(pid)) {
int ret;
#if defined(ECL_MS_WINDOWS_HOST)
ret = TerminateProcess(ecl_fixnum(pid), -1);
error_encountered = (ret == 0);
#else
ret = kill(ecl_fixnum(pid), Null(force) ? SIGTERM : SIGKILL);
error_encountered = (ret != 0);
#endif
}
}
ECL_WITH_SPINLOCK_END;
if (error_encountered)
FEerror("Cannot terminate the process ~A", 1, process);
return ECL_NIL;
}
@)
@(defun si::wait-for-all-processes (&key (process ECL_NIL))
@
{

View file

@ -1329,6 +1329,7 @@
(values (or null two-way-stream)
(or null integer)
ext:external-process))
(proclamation ext:terminate-process (t &optional gen-bool) null)
(proclamation ext:make-weak-pointer (t) ext:weak-pointer :no-side-effects)
(proclamation ext:weak-pointer-value (ext:weak-pointer) t)

View file

@ -1891,7 +1891,7 @@ extern ECL_API cl_object si_make_pipe();
extern ECL_API cl_object si_run_program _ECL_ARGS((cl_narg narg, cl_object command, cl_object args, ...));
extern ECL_API cl_object si_external_process_wait _ECL_ARGS((cl_narg narg, cl_object h, ...));
extern ECL_API cl_object si_close_windows_handle(cl_object h);
extern ECL_API cl_object ext_terminate_process _ECL_ARGS((cl_narg narg, cl_object process, ...));
/* unicode -- no particular file, but we group these changes here */