bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The lastpipe shell option even with job control?


From: Dr. Werner Fink
Subject: The lastpipe shell option even with job control?
Date: Mon, 27 Mar 2017 15:44:22 +0200
User-agent: Mutt/1.6.2 (2016-07-01)

Hi,

I'd like to ask if there is crucial reason, beside the correct foreground
process group, not to allow the lastpipe shell option for an interactive
bash? Maybe something like in the attachment could be an option?

Werner

-- 
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr
diff --git execute_cmd.c execute_cmd.c
index 2a3df6d..9802303 100644
--- execute_cmd.c
+++ execute_cmd.c
@@ -2346,6 +2346,16 @@ lastpipe_cleanup (s)
   unfreeze_jobs_list ();
 }
 
+extern int shell_tty;
+
+static void
+restore_tty (s)
+     pid_t s;
+{
+  if (s > 0)
+    give_terminal_to (s, 0);
+}
+
 static int
 execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
      COMMAND *command;
@@ -2360,7 +2370,9 @@ execute_pipeline (command, asynchronous, pipe_in, 
pipe_out, fds_to_close)
 
 #if defined (JOB_CONTROL)
   sigset_t set, oset;
+  pid_t cpgrp;
   BLOCK_CHILD (set, oset);
+  cpgrp = shell_tty >= 0 ? tcgetpgrp (shell_tty) : -1;
 #endif /* JOB_CONTROL */
 
   ignore_return = (command->flags & CMD_IGNORE_RETURN) != 0;
@@ -2459,7 +2471,7 @@ execute_pipeline (command, asynchronous, pipe_in, 
pipe_out, fds_to_close)
   /* If the `lastpipe' option is set with shopt, and job control is not
      enabled, execute the last element of non-async pipelines in the
      current shell environment. */
-  if (lastpipe_opt && job_control == 0 && asynchronous == 0 && pipe_out == 
NO_PIPE && prev > 0)
+  if (lastpipe_opt && asynchronous == 0 && pipe_out == NO_PIPE && prev > 0)
     {
       lstdin = move_to_high_fd (0, 1, -1);
       if (lstdin > 0)
@@ -2467,6 +2479,7 @@ execute_pipeline (command, asynchronous, pipe_in, 
pipe_out, fds_to_close)
          do_piping (prev, pipe_out);
          prev = NO_PIPE;
          add_unwind_protect (restore_stdin, lstdin);
+         add_unwind_protect (restore_tty, cpgrp);
          lastpipe_flag = 1;
          freeze_jobs_list ();
          lastpipe_jid = stop_pipeline (0, (COMMAND *)NULL);    /* XXX */
@@ -2516,7 +2529,9 @@ execute_pipeline (command, asynchronous, pipe_in, 
pipe_out, fds_to_close)
       else if (pipefail_opt)
        exec_result = exec_result | lstdin;     /* XXX */
       /* otherwise we use exec_result */
-        
+
+      if (cpgrp > 0)
+       give_terminal_to (cpgrp, 0); 
 #endif
       unfreeze_jobs_list ();
     }
diff --git doc/bash.0 doc/bash.0
index 031be8a..6cfe061 100644
--- doc/bash.0
+++ doc/bash.0
@@ -5507,9 +5507,8 @@ SSHHEELLLL BBUUIILLTTIINN 
CCOOMMMMAANNDDSS
                       in  an  interactive  shell  (see  
CCOOMMMMEENNTTSS above).  This
                       option is enabled by default.
               llaassttppiippee
-                      If set, and job control is not active,  the  shell  runs
-                      the last command of a pipeline not executed in the back-
-                      ground in the current shell environment.
+                      If set the  shell  runs the last command of a pipeline 
not
+                      executed in the background in the current shell 
environment.
               lliitthhiisstt If set, and the ccmmddhhiisstt 
option  is  enabled,  multi-line
                       commands are saved to the history with embedded newlines
                       rather than using semicolon separators where possible.
diff --git doc/bash.1 doc/bash.1
index 9a7a384..8327867 100644
--- doc/bash.1
+++ doc/bash.1
@@ -9788,8 +9788,8 @@ line to be ignored in an interactive shell (see
 above).  This option is enabled by default.
 .TP 8
 .B lastpipe
-If set, and job control is not active, the shell runs the last command of
-a pipeline not executed in the background in the current shell environment.
+If set the shell runs the last command of a pipeline not
+executed in the background in the current shell environment.
 .TP 8
 .B lithist
 If set, and the
diff --git doc/bash.html doc/bash.html
index 983284e..2a2b242 100644
--- doc/bash.html
+++ doc/bash.html
@@ -12431,8 +12431,8 @@ above).  This option is enabled by default.
 <DT><B>lastpipe</B>
 
 <DD>
-If set, and job control is not active, the shell runs the last command of
-a pipeline not executed in the background in the current shell environment.
+If set the shell runs the last command of a pipeline not
+executed in the background in the current shell environment.
 <DT><B>lithist</B>
 
 <DD>
diff --git doc/bash.info doc/bash.info
index fac6786..6dd1c77 100644
--- doc/bash.info
+++ doc/bash.info
@@ -4504,9 +4504,8 @@ This builtin allows you to change additional shell 
optional behavior.
           interactive shell.  This option is enabled by default.
 
      'lastpipe'
-          If set, and job control is not active, the shell runs the last
-          command of a pipeline not executed in the background in the
-          current shell environment.
+          If set the shell runs the last command of a pipeline not
+          executed in the background in the current shell environment.
 
      'lithist'
           If enabled, and the 'cmdhist' option is enabled, multi-line
diff --git doc/bashref.html doc/bashref.html
index 8c2eabf..9b8b505 100644
--- doc/bashref.html
+++ doc/bashref.html
@@ -6138,7 +6138,7 @@ This option is enabled by default.
 </p>
 </dd>
 <dt><code>lastpipe</code></dt>
-<dd><p>If set, and job control is not active, the shell runs the last command 
of
+<dd><p>If set the shell runs the last command of
 a pipeline not executed in the background in the current shell environment.
 </p>
 </dd>
diff --git doc/bashref.info doc/bashref.info
index 28b0610..f268f5e 100644
--- doc/bashref.info
+++ doc/bashref.info
@@ -4504,7 +4504,7 @@ This builtin allows you to change additional shell 
optional behavior.
           interactive shell.  This option is enabled by default.
 
      'lastpipe'
-          If set, and job control is not active, the shell runs the last
+          If set the shell runs the last
           command of a pipeline not executed in the background in the
           current shell environment.
 
diff --git doc/bashref.texi doc/bashref.texi
index c0f4a2f..8a3a3de 100644
--- doc/bashref.texi
+++ doc/bashref.texi
@@ -5263,8 +5263,8 @@ line to be ignored in an interactive shell.
 This option is enabled by default.
 
 @item lastpipe
-If set, and job control is not active, the shell runs the last command of
-a pipeline not executed in the background in the current shell environment.
+If set the shell runs the last command of a pipeline not
+executed in the background in the current shell environment.
 
 @item lithist
 If enabled, and the @code{cmdhist}
diff --git doc/builtins.0 doc/builtins.0
index 3706dad..f4755d7 100644
--- doc/builtins.0
+++ doc/builtins.0
@@ -1480,9 +1480,8 @@ BBAASSHH BBUUIILLTTIINN 
CCOOMMMMAANNDDSS
                       in  an  interactive  shell  (see  
CCOOMMMMEENNTTSS above).  This
                       option is enabled by default.
               llaassttppiippee
-                      If set, and job control is not active,  the  shell  runs
-                      the last command of a pipeline not executed in the back-
-                      ground in the current shell environment.
+                      If set the  shell  runs the last command of a pipeline 
not
+                      executed in the background in the current shell 
environment.
               lliitthhiisstt If set, and the ccmmddhhiisstt 
option  is  enabled,  multi-line
                       commands are saved to the history with embedded newlines
                       rather than using semicolon separators where possible.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]