summaryrefslogtreecommitdiff
path: root/data/bash/bash40-019
blob: 30efd680607b67ce0dd612c6194cc859e6aa828a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
			     BASH PATCH REPORT
			     =================

Bash-Release: 4.0
Patch-ID: bash40-019

Bug-Reported-by: Oleksiy Melnyk <lex@upc.ua>
Bug-Reference-ID: <20090224142233.D2FEFC004@floyd.upc.ua>
Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2009-02/msg00200.html

Bug-Description:

Using an external command as part of the DEBUG trap when job control is
enabled causes pipelines to misbehave.  The problem has to do with process
groups assigned to the pipeline and terminal.

Patch:

*** ../bash-4.0-patched/jobs.c	2009-01-29 17:09:49.000000000 -0500
--- jobs.c	2009-04-17 21:08:20.000000000 -0400
***************
*** 443,447 ****
    the_pipeline = saved_pipeline;
    already_making_children = saved_already_making_children;
!   if (discard)
      discard_pipeline (old_pipeline);
  }
--- 443,447 ----
    the_pipeline = saved_pipeline;
    already_making_children = saved_already_making_children;
!   if (discard && old_pipeline)
      discard_pipeline (old_pipeline);
  }
***************
*** 4203,4205 ****
--- 4204,4225 ----
  }
  
+ void
+ save_pgrp_pipe (p, clear)
+      int *p;
+      int clear;
+ {
+   p[0] = pgrp_pipe[0];
+   p[1] = pgrp_pipe[1];
+   if (clear)
+     pgrp_pipe[0] = pgrp_pipe[1] = -1;
+ }
+ 
+ void
+ restore_pgrp_pipe (p)
+      int *p;
+ {
+   pgrp_pipe[0] = p[0];
+   pgrp_pipe[1] = p[1];
+ }
+ 
  #endif /* PGRP_PIPE */
*** ../bash-4.0-patched/jobs.h	2009-01-04 14:32:29.000000000 -0500
--- jobs.h	2009-04-17 15:07:51.000000000 -0400
***************
*** 236,239 ****
--- 236,241 ----
  
  extern void close_pgrp_pipe __P((void));
+ extern void save_pgrp_pipe __P((int *, int));
+ extern void restore_pgrp_pipe __P((int *));
  
  #if defined (JOB_CONTROL)
*** ../bash-4.0-patched/trap.c	2009-01-16 17:07:53.000000000 -0500
--- trap.c	2009-04-17 22:22:36.000000000 -0400
***************
*** 799,802 ****
--- 799,804 ----
  {
    int trap_exit_value;
+   pid_t save_pgrp;
+   int save_pipe[2];
  
    /* XXX - question:  should the DEBUG trap inherit the RETURN trap? */
***************
*** 804,808 ****
--- 806,832 ----
    if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && ((sigmodes[DEBUG_TRAP] & SIG_IGNORED) == 0) && ((sigmodes[DEBUG_TRAP] & SIG_INPROGRESS) == 0))
      {
+ #if defined (JOB_CONTROL)
+       save_pgrp = pipeline_pgrp;
+       pipeline_pgrp = 0;
+       save_pipeline (1);
+ #  if defined (PGRP_PIPE)
+       save_pgrp_pipe (save_pipe, 1);
+ #  endif
+       stop_making_children ();
+ #endif
+ 
        trap_exit_value = _run_trap_internal (DEBUG_TRAP, "debug trap");
+ 
+ #if defined (JOB_CONTROL)
+       pipeline_pgrp = save_pgrp;
+       restore_pipeline (1);
+ #  if defined (PGRP_PIPE)
+       close_pgrp_pipe ();
+       restore_pgrp_pipe (save_pipe);
+ #  endif
+       if (pipeline_pgrp > 0)
+ 	give_terminal_to (pipeline_pgrp, 1);
+       notify_and_cleanup ();
+ #endif
        
  #if defined (DEBUGGER)
*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 18
  
  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 19
  
  #endif /* _PATCHLEVEL_H_ */