commands following asynchronous list are executed twice

2020-04-02 Thread Oğuz
While reading commands from stdin, if job controls are enabled,
commands following an asynchronous list in `{ cmd; } &` fashion are
executed twice. See below extract:

$ bash -m <<\EOD
{ sleep 1; } &
wait
echo $BASHPID
EOD
10615
10615

When job controls are disabled, or an external utility is called in
the same line this behavior disappears. E.g.:

$ bash -m <<\EOD
{ sleep 1; } & x
wait
echo $BASHPID
EOD
./bash: line 1: x: command not found
10618

This is reproducible on 4.4.20(1)-release, 5.0.11(1)-release and 5.0.16(1)-maint

-- 
Oğuz



verbosity of DEBUG trap following edit-and-execute-command

2020-04-02 Thread Ami Fischman
After the editor invoked by edit-and-execute-command exits, the
about-to-be-executed command (as edited by the editor) is echoed, but seemingly
as if [set -v] was set, causing a command executed before the edited command as
the result of a trap DEBUG to be echoed, as well. This is annoying for example
when using the DEBUG trap as a way to change colors as demonstrated in
https://nigeltao.github.io/blog/2018/colorful-text.html#shell-prompts

It would be nicer if the set -v was undone before the trap's handler was
executed so that the printf wasn't shown to the user in the example below.

Repro recipe follows. The initial echo demonstrates that the trap is silent in
the absence of edit-and-execute-command. The second echo command has C-x C-e hit
after the "echo He" is typed, and the line containing printf (third from the
bottom) is what I'm hoping to avoid.

~ $ docker run -it bash:5.0.16
bash-5.0# EDITOR=ed
bash-5.0# trap 'printf "\e[0m"' DEBUG
bash-5.0# echo Hello
Hello
bash-5.0# echo He
"/tmp/bash-fc.INbEkF", 1 lines, 8 chars
: 1s/He/Hello/
: w
"/tmp/bash-fc.INbEkF", 1 lines, 11 chars
: q
echo Hello
printf "\e[0m"
Hello
bash-5.0#

Note this also repros in 5.0.11(1) as well as 3.2.57(1).

Cheers,
-a



Re: commands following asynchronous list are executed twice

2020-04-02 Thread Chet Ramey
On 4/2/20 8:09 AM, Oğuz wrote:
> While reading commands from stdin, if job controls are enabled,
> commands following an asynchronous list in `{ cmd; } &` fashion are
> executed twice. 

Thanks for the report. This will be fixed in the next devel branch push.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: Obscure issue with process substitution since bash-5.0.016 upgrade

2020-04-02 Thread Chet Ramey
On 4/1/20 10:15 PM, Joan Bruguera Micó wrote:
> I'm having a problem with a script that used to work, which I reduced
> to the following test case:
> 
> #!/bin/bash
> 
> function docat() {
> for x in 1 2 3 ; do true; done
> cat "$@"
> }
> 
> for x in $(seq 25); do
> docat <(echo a) <(echo a) <(echo a) <(echo a) <(echo a) <(echo a)
> done
> 
> Expected behaviour: A lot of lines with an "a" are printed

Thanks for the report.

Yes, this is a problem, as you discovered, with bash-5.0 patch 16. There is
a better way to solve the problem that patch attempts to solve, and the
enclosed patch to bash-5.0.16 does it.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
*** ../bash-5.0-patched/subst.c 2019-08-29 11:16:49.0 -0400
--- subst.c 2020-04-02 16:24:19.0 -0400
***
*** 5337,5341 
  }
  
! char *
  copy_fifo_list (sizep)
   int *sizep;
--- 5337,5341 
  }
  
! void *
  copy_fifo_list (sizep)
   int *sizep;
***
*** 5343,5347 
if (sizep)
  *sizep = 0;
!   return (char *)NULL;
  }
  
--- 5343,5347 
if (sizep)
  *sizep = 0;
!   return (void *)NULL;
  }
  
***
*** 5409,5414 
if (fifo_list[i].file)
  {
!   fifo_list[j].file = fifo_list[i].file;
!   fifo_list[j].proc = fifo_list[i].proc;
j++;
  }
--- 5409,5419 
if (fifo_list[i].file)
  {
!   if (i != j)
! {
!   fifo_list[j].file = fifo_list[i].file;
!   fifo_list[j].proc = fifo_list[i].proc;
!   fifo_list[i].file = (char *)NULL;
!   fifo_list[i].proc = 0;
! }
j++;
  }
***
*** 5426,5433 
  void
  close_new_fifos (list, lsize)
!  char *list;
   int lsize;
  {
int i;
  
if (list == 0)
--- 5431,5439 
  void
  close_new_fifos (list, lsize)
!  void *list;
   int lsize;
  {
int i;
+   char *plist;
  
if (list == 0)
***
*** 5437,5442 
  }
  
!   for (i = 0; i < lsize; i++)
! if (list[i] == 0 && i < fifo_list_size && fifo_list[i].proc != -1)
unlink_fifo (i);
  
--- 5443,5448 
  }
  
!   for (plist = (char *)list, i = 0; i < lsize; i++)
! if (plist[i] == 0 && i < fifo_list_size && fifo_list[i].proc != -1)
unlink_fifo (i);
  
***
*** 5560,5568 
  }
  
! char *
  copy_fifo_list (sizep)
   int *sizep;
  {
!   char *ret;
  
if (nfds == 0 || totfds == 0)
--- 5566,5574 
  }
  
! void *
  copy_fifo_list (sizep)
   int *sizep;
  {
!   void *ret;
  
if (nfds == 0 || totfds == 0)
***
*** 5570,5579 
if (sizep)
*sizep = 0;
!   return (char *)NULL;
  }
  
if (sizep)
  *sizep = totfds;
!   ret = (char *)xmalloc (totfds * sizeof (pid_t));
return (memcpy (ret, dev_fd_list, totfds * sizeof (pid_t)));
  }
--- 5576,5585 
if (sizep)
*sizep = 0;
!   return (void *)NULL;
  }
  
if (sizep)
  *sizep = totfds;
!   ret = xmalloc (totfds * sizeof (pid_t));
return (memcpy (ret, dev_fd_list, totfds * sizeof (pid_t)));
  }
***
*** 5648,5655 
  void
  close_new_fifos (list, lsize)
!  char *list;
   int lsize;
  {
int i;
  
if (list == 0)
--- 5654,5662 
  void
  close_new_fifos (list, lsize)
!  void *list;
   int lsize;
  {
int i;
+   pid_t *plist;
  
if (list == 0)
***
*** 5659,5664 
  }
  
!   for (i = 0; i < lsize; i++)
! if (list[i] == 0 && i < totfds && dev_fd_list[i])
unlink_fifo (i);
  
--- 5666,5671 
  }
  
!   for (plist = (pid_t *)list, i = 0; i < lsize; i++)
! if (plist[i] == 0 && i < totfds && dev_fd_list[i])
unlink_fifo (i);
  
*** ../bash-5.0-patched/subst.h 2018-10-21 18:46:09.0 -0400
--- subst.h 2020-04-02 16:29:28.0 -0400
***
*** 274,280 
  extern void unlink_fifo __P((int));
  
! extern char *copy_fifo_list __P((int *));
! extern void unlink_new_fifos __P((char *, int));
! extern void close_new_fifos __P((char *, int));
  
  extern void clear_fifo_list __P((void));
--- 274,279 
  extern void unlink_fifo __P((int));
  
! extern void *copy_fifo_list __P((int *));
! extern void close_new_fifos __P((void *, int));
  
  extern void clear_fifo_list __P((void));
*** ../bash-5.0-patched/execute_cmd.c   2020-02-06 20:16:48.0 -0500
--- execute_cmd.c   2020-04-02 17:00:10.0 -0400
***
*** 565,569 
  #if defined (PROCESS_SUBSTITUTION)
volatile int ofifo, nfifo, osize, saved_fifo;
!   volatile char *ofifo_list;
  #endif
  
--- 565,569 
  #if defined (PROCESS_SUBSTITUTION)
volatile int ofifo, nfifo, osize, saved_fifo;
!   volatile vo

Re: Obscure issue with process substitution since bash-5.0.016 upgrade

2020-04-02 Thread Joan Bruguera Micó
Thanks for your attention and the provided reduced patch. I can
confirm that, applied over bash-5.0.16, this solves my issue, both on
the test case as well as the bigger application from which it was
extracted.

Regards,
- Joan Bruguera

On Thu, 2 Apr 2020 at 23:20, Chet Ramey  wrote:
>
> On 4/1/20 10:15 PM, Joan Bruguera Micó wrote:
> > I'm having a problem with a script that used to work, which I reduced
> > to the following test case:
> >
> > #!/bin/bash
> >
> > function docat() {
> > for x in 1 2 3 ; do true; done
> > cat "$@"
> > }
> >
> > for x in $(seq 25); do
> > docat <(echo a) <(echo a) <(echo a) <(echo a) <(echo a) <(echo a)
> > done
> >
> > Expected behaviour: A lot of lines with an "a" are printed
>
> Thanks for the report.
>
> Yes, this is a problem, as you discovered, with bash-5.0 patch 16. There is
> a better way to solve the problem that patch attempts to solve, and the
> enclosed patch to bash-5.0.16 does it.
>
> Chet
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



-- 

Joan Bruguera Micó - PGP key id: 88A7 A061 6B47 0CE1 EB4E  D431 8744
44D1 21CE B72E