Skip to content

Commit

Permalink
Handle the case where we have a bracketed expression with redirection.
Browse files Browse the repository at this point in the history
In this case, make sure we fork and we do io processing.

if ( { ping -c 1 192.168.3.9 >& /dev/null } ) then
  echo "LAN is up"
endif
  • Loading branch information
zoulasc committed Nov 8, 2024
1 parent d9e82b8 commit 3c7a988
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Fixes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
39. Handle redirections in bracketed expressions if { foo > /dev/null }
(christos)
38. Recognize history searches in history expansion !?foo<tab> (christos)
37. V6.24.13 - 2024-06-12
36. Fix !^:h and !^:t failing when no / found (Kimmo Suominen)
Expand Down
2 changes: 2 additions & 0 deletions sh.exp.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,8 @@ evalav(Char **v)
cleanup_push(&paraml1, lex_cleanup);
alias(&paraml1);
t = syntax(paraml1.next, &paraml1, 0);
if (t->t_dflg & F_REDIR)
t->t_dflg |= F_FORK;
cleanup_push(t, syntax_cleanup);
if (seterr)
stderror(ERR_OLD);
Expand Down
2 changes: 2 additions & 0 deletions sh.h
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ struct command {
#ifdef apollo
#define F_VER (1<<16) /* execute command under SYSTYPE */
#endif
#define F_FORK (1<<17) /* force forking */
#define F_REDIR (1<<18) /* output redirected */
union {
Char *T_dlef; /* Input redirect word */
struct command *T_dcar; /* Left part of list/pipe */
Expand Down
1 change: 1 addition & 0 deletions sh.parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ syn3(const struct wordent *p1, const struct wordent *p2, int flags)
goto savep;

case '>':
t->t_dflg |= F_REDIR;
if (l != 0)
goto savep;
if (p->word[1] == '>')
Expand Down
5 changes: 2 additions & 3 deletions sh.sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ execute(struct command *t, volatile int wanttty, int *pipein, int *pipeout,
bifunc->bfunct == (bfunc_t)dopopd))
t->t_dflg &= ~(F_NICE);

if (((t->t_dflg & F_TIME) || ((t->t_dflg & F_NOFORK) == 0 &&
if (((t->t_dflg & F_TIME|F_FORK) || ((t->t_dflg & F_NOFORK) == 0 &&
(!bifunc || t->t_dflg &
(F_PIPEOUT | F_AMPERSAND | F_NICE | F_NOHUP | F_HUP)))) ||
/*
Expand Down Expand Up @@ -843,8 +843,7 @@ doio(struct command *t, int *pipein, int *pipeout)
int fd;
Char *cp;
unsigned long flags = t->t_dflg;

if (didfds || (flags & F_REPEAT))
if ((flags & F_FORK) == 0 && (didfds || (flags & F_REPEAT)))
return;
if ((flags & F_READ) == 0) {/* F_READ already done */
if (t->t_dlef) {
Expand Down

0 comments on commit 3c7a988

Please sign in to comment.