From 65ce358d918559662672cb1ae7f47cbe0d0eb9af Mon Sep 17 00:00:00 2001 From: Raymond Toy <toy.raymond@gmail.com> Date: Fri, 15 Sep 2017 22:50:47 -0700 Subject: [PATCH] Fix up minor issues in implementation - process-alive-p should return T for continued processes - Simplify prog-status slightly by making the status code array start :signaled instead of nil. - Update prog_status with enum to specify the codes to make it clearer what they mean and to make it clearer that it matches the expectations in prog-status. --- src/code/run-program.lisp | 5 +++-- src/lisp/runprog.c | 23 +++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/code/run-program.lisp b/src/code/run-program.lisp index f16dfb088..5a7f6e1e0 100644 --- a/src/code/run-program.lisp +++ b/src/code/run-program.lisp @@ -85,7 +85,7 @@ (declare (ignore ret)) (when (plusp pid) (values pid - (aref #(nil :signaled :stopped :continued :exited) what) + (aref #(:signaled :stopped :continued :exited) what) code (not (zerop corep)))))) @@ -217,7 +217,8 @@ (declare (type process proc)) (let ((status (process-status proc))) (if (or (eq status :running) - (eq status :stopped)) + (eq status :stopped) + (eq status :continued)) t nil))) diff --git a/src/lisp/runprog.c b/src/lisp/runprog.c index e6a5a0d77..852584a83 100644 --- a/src/lisp/runprog.c +++ b/src/lisp/runprog.c @@ -3,6 +3,8 @@ * */ +#include <stdio.h> + #include <sys/ioctl.h> #include <errno.h> #include <fcntl.h> @@ -85,6 +87,17 @@ spawn(char *program, char *argv[], char *envp[], char *pty_name, * core - true (non-zero) if a core was produced */ +/* + * Status codes. Must be in the same order as in ext::prog-status in + * run-program.lisp + */ +enum status_code { + SIGNALED, + STOPPED, + CONTINUED, + EXITED +}; + void prog_status(pid_t* pid, int* what, int* code, int* corep) { @@ -100,21 +113,23 @@ prog_status(pid_t* pid, int* what, int* code, int* corep) } if (WIFEXITED(status)) { - *what = 4; + *what = EXITED; *code = WEXITSTATUS(status); *corep = 0; } else if (WIFSIGNALED(status)) { - *what = 1; + *what = SIGNALED; *code = WTERMSIG(status); *corep = WCOREDUMP(status); } else if (WIFSTOPPED(status)) { - *what = 2; + *what = STOPPED; *code = WSTOPSIG(status); *corep = 0; } else if (WIFCONTINUED(status)) { - *what = 3; + *what = CONTINUED; *code = 0; *corep = 0; + } else { + fprintf(stderr, "pid = %d, status = 0x%x\n", *pid, status); } return; -- GitLab