nalika / rpms / bash

Forked from rpms/bash 2 years ago
Clone
462fb2
From 0eb5e47f531b49c8d048c9ae9657eeb63f49a9f3 Mon Sep 17 00:00:00 2001
462fb2
From: Siteshwar Vashisht <svashisht@redhat.com>
462fb2
Date: Fri, 13 May 2016 01:34:06 +0530
462fb2
Subject: [PATCH] Fix shopt lastpipe mode crash
462fb2
462fb2
---
462fb2
 execute_cmd.c | 23 ++++++++++++++++++++---
462fb2
 1 file changed, 20 insertions(+), 3 deletions(-)
462fb2
462fb2
diff --git a/execute_cmd.c b/execute_cmd.c
462fb2
index c5cf6d2..7b22460 100644
462fb2
--- a/execute_cmd.c
462fb2
+++ b/execute_cmd.c
462fb2
@@ -2254,11 +2254,28 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
462fb2
   if (lastpipe_flag)
462fb2
     {
462fb2
 #if defined (JOB_CONTROL)
462fb2
-      append_process (savestring (the_printed_command), dollar_dollar_pid, exec_result, lastpipe_jid);
462fb2
-#endif
462fb2
+      if (INVALID_JOB (lastpipe_jid) == 0)
462fb2
+        {
462fb2
+          append_process (savestring (the_printed_command_except_trap), dollar_dollar_pid, exec_result, lastpipe_jid);
462fb2
+          lstdin = wait_for (lastpid);
462fb2
+        }
462fb2
+      else
462fb2
+        lstdin = wait_for_single_pid (lastpid);		/* checks bgpids list */
462fb2
+#else
462fb2
       lstdin = wait_for (lastpid);
462fb2
+#endif
462fb2
+
462fb2
 #if defined (JOB_CONTROL)
462fb2
-      exec_result = job_exit_status (lastpipe_jid);
462fb2
+      /* If wait_for removes the job from the jobs table, use result of last
462fb2
+	 command as pipeline's exit status as usual.  The jobs list can get
462fb2
+	 frozen and unfrozen at inconvenient times if there are multiple pipelines
462fb2
+	 running simultaneously. */
462fb2
+      if (INVALID_JOB (lastpipe_jid) == 0)
462fb2
+	exec_result = job_exit_status (lastpipe_jid);
462fb2
+      else if (pipefail_opt)
462fb2
+	exec_result = exec_result | lstdin;	/* XXX */
462fb2
+      /* otherwise we use exec_result */
462fb2
+        
462fb2
 #endif
462fb2
       unfreeze_jobs_list ();
462fb2
     }
462fb2
-- 
462fb2
2.5.5
462fb2