Skip to content

Commit a4adb2d

Browse files
committed
Fix waitpid
1 parent 66a84f6 commit a4adb2d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/exec.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ int launch_bin(char *full_bin_path, char **args, ef_t *ef)
129129
status = command_error(full_bin_path, args, errno);
130130
free_env(ef->env);
131131
free((void *)args);
132-
free(ef->buffer);
133-
exit(status);
132+
exit((free(ef->buffer), status));
134133
}
135134
}
136-
waitpid(pid, &status, 0);
135+
if (ef->out_fd == STDOUT_FILENO || ef->p_i == ef->p_sz - 1)
136+
waitpid(pid, &status, 0);
137+
else
138+
waitpid(pid, &status, WNOHANG);
137139
if (WIFEXITED(status))
138140
ef->history->last_exit_code =
139141
ef->history->last_exit_code ?: WEXITSTATUS(status);

src/exec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ typedef struct {
3333
size_t skip_i;
3434
size_t skip_sz;
3535
uint8_t flags;
36+
size_t p_i;
37+
size_t p_sz;
3638
int rin_fd;
3739
int rout_fd;
3840
int pipes[2];

src/visitor.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ int visit_pipes(ef_t *ef)
110110
ast_t *node = ef->act_node;
111111
int result = RETURN_FAILURE;
112112

113+
ef->p_i = 0;
114+
ef->p_sz = node->list.sz;
113115
ef->pin_fd = STDIN_FILENO;
114116
for (size_t i = 0; i < node->list.sz; i++) {
117+
ef->p_i = i;
115118
result = visit_pipe(ef, i, node);
116119
if (result == -1)
117120
break;

0 commit comments

Comments
 (0)