mirror of
https://github.com/zoriya/ash.git
synced 2026-06-02 10:45:07 +00:00
Fixing redirection closure bug with builtins by handling stderr redirections
This commit is contained in:
@@ -17,10 +17,11 @@
|
||||
int run_builtin(const builtin *cmd, char **a, redirection *inout[2], env_t *env)
|
||||
{
|
||||
int ret = 0;
|
||||
int saved_fd[2];
|
||||
int saved_fd[3];
|
||||
|
||||
saved_fd[0] = dup(0);
|
||||
saved_fd[1] = dup(1);
|
||||
saved_fd[2] = dup(2);
|
||||
if (saved_fd[0] < 0 || saved_fd[1] < 0) {
|
||||
perror("mysh");
|
||||
return (-1);
|
||||
@@ -29,8 +30,10 @@ int run_builtin(const builtin *cmd, char **a, redirection *inout[2], env_t *env)
|
||||
ret = cmd->run(a, env);
|
||||
dup2(saved_fd[0], 0);
|
||||
dup2(saved_fd[1], 1);
|
||||
dup2(saved_fd[2], 2);
|
||||
close(saved_fd[0]);
|
||||
close(saved_fd[1]);
|
||||
close(saved_fd[2]);
|
||||
if (handle_parent_inout(inout, env, true))
|
||||
ret = 0;
|
||||
return (ret);
|
||||
|
||||
@@ -68,7 +68,7 @@ int newline_command(int key, buffer_t *buffer, env_t *env)
|
||||
ret = eval_raw_cmd(buffer->buffer, env);
|
||||
buffer->buffer[0] = '\0';
|
||||
buffer->pos = 0;
|
||||
if (env->window)
|
||||
if (env->window && ret >= 0)
|
||||
prompt_prepare(buffer, env);
|
||||
return (ret);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ void pty_get_output(redirection *pty, env_t *env)
|
||||
while (getline(&line, &size, file) > 0)
|
||||
my_addstr(env->window, line);
|
||||
if (line) {
|
||||
if (!strchr(line, '\n')) {
|
||||
if (line[0] && !strchr(line, '\n')) {
|
||||
my_attron(BACKGROUND_COLOR, WHITE);
|
||||
my_attron(COLOR, BLACK);
|
||||
my_addstr(env->window, "%\n");
|
||||
|
||||
Reference in New Issue
Block a user