Skip to content

Commit

Permalink
perf: return clearer error messages for sys.exec
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Nov 27, 2024
1 parent d499f59 commit 058c18c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ static int eco_sys_exec(lua_State *L)
int epipe[2] = {};
pid_t pid;

if (pipe(opipe) < 0 || pipe(epipe) < 0)
if (pipe(opipe) < 0 || pipe(epipe) < 0) {
lua_pushnil(L);
lua_pushfstring(L, "pipe: %s", strerror(errno));
goto err;
}

pid = fork();
if (pid < 0) {
lua_pushnil(L);
lua_pushfstring(L, "fork: %s", strerror(errno));
goto err;
} else if (pid == 0) {
const char **args;
Expand Down Expand Up @@ -116,9 +121,6 @@ static int eco_sys_exec(lua_State *L)
}

err:
lua_pushnil(L);
lua_pushstring(L, strerror(errno));

if (opipe[0] > 0) {
close(opipe[0]);
close(opipe[1]);
Expand Down

0 comments on commit 058c18c

Please sign in to comment.