fix: decode child exit status for LASTEXIT
This commit is contained in:
@@ -27,7 +27,7 @@ Verified in this checkout on 2026-09-22:
|
||||
- `./claro doctor`: all checks `OK`.
|
||||
- `./claro validate`: validation passed.
|
||||
|
||||
This slice does not yet fix memory cleanup, `LASTEXIT`, HTTP buffering/status handling, or other review findings. Claro remains a trusted-script interpreter, not a sandbox.
|
||||
The `RUN COMMAND` path now decodes POSIX `pclose()` wait status before storing `LASTEXIT`, so a child that exits with code 3 exposes `3` rather than the encoded status `768`. Focused coverage is `tests/42_last_exit_code.claro`. This slice does not yet fix memory cleanup, HTTP buffering/status handling, or other review findings. Claro remains a trusted-script interpreter, not a sandbox.
|
||||
|
||||
## Feature matrix
|
||||
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ int pclose(FILE *stream);
|
||||
#ifndef _WIN32
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#else
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
@@ -205,7 +206,7 @@ static char *capture_command_output(const char *cmd,int *exit_code){
|
||||
#ifdef _WIN32
|
||||
if(exit_code) *exit_code=_pclose(fp);
|
||||
#else
|
||||
if(exit_code) *exit_code=pclose(fp);
|
||||
if(exit_code){ int status=pclose(fp); if(WIFEXITED(status)) *exit_code=WEXITSTATUS(status); else if(WIFSIGNALED(status)) *exit_code=128+WTERMSIG(status); else *exit_code=-1; }
|
||||
#endif
|
||||
return str_take(&out);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
RUN COMMAND "exit 3" AS output
|
||||
SAY LASTEXIT
|
||||
@@ -0,0 +1 @@
|
||||
3
|
||||
Reference in New Issue
Block a user