reassign 733722 xfce4-terminal 0.6.3-1
retitle 733722 xfce4-terminal: doesn't reset SIGPIPE before spawing a shell
tags 733722 + patch
forwarded 733722 https://bugzilla.xfce.org/show_bug.cgi?id=10602
thanks

(xfce4-terminal maintainer: please see the original report for a
slightly longer explanation of the bug)

On Fri, Jan 03, 2014 at 07:32:09PM -0700, Bob Proulx wrote:
> [...]
> Ignoring SIGPIPE is definitely the problem.  The 'head' process should
> exit.  The 'yes' process should get SIGPIPE which should cause it to
> terminate.  Instead yes is ignoring SIGPIPE and therefore continuing
> and trying to write to the pipe.  At that point the write to the pipe
> has an error and this is reported (as it should be) as a broken pipe.

Yes, I can see that.  What is interesting, though, is it appears to be
somewhat selective, or maybe it's connected to the amount of content
that's being sent, or something.  And there's something seemingly
random about it too: here's one series of shell commands and their
output:

erdos:~ $ ls /media/JG-BACKUP/mythtv/recordings/ | head
1001_20121224170300.mpg
1001_20121224170300.mpg.png
1001_20130611223300.mpg
1001_20130611223300.mpg.-1.100x75.png
1001_20130611223300.mpg.png
1001_20131008223200.mpg
1001_20131008223200.mpg.-1.100x75.png
1001_20131008223200.mpg.-1.160x90.png
1001_20131008223200.mpg.png
1001_20131227205700.mpg
erdos:~ $ ls -l /media/JG-BACKUP/mythtv/recordings/ | head
total 330796024
-rw-r--r-- 1 mythtv mythtv 2153487172 Dec 24  2012 1001_20121224170300.mpg
-rw-rw-rw- 1 mythtv mythtv      56772 Dec 26  2012 1001_20121224170300.mpg.png
-rw-r--r-- 1 mythtv mythtv 3727479948 Jun 12  2013 1001_20130611223300.mpg
-rw-rw-rw- 1 mythtv mythtv      14222 Oct 16 23:25 
1001_20130611223300.mpg.-1.100x75.png
-rw-rw-rw- 1 mythtv mythtv      88745 Jun 12  2013 1001_20130611223300.mpg.png
-rw-r--r-- 1 mythtv mythtv 2486190208 Oct  9 00:59 1001_20131008223200.mpg
-rw-rw-rw- 1 mythtv mythtv      14450 Oct 16 23:24 
1001_20131008223200.mpg.-1.100x75.png
-rw-rw-rw- 1 mythtv mythtv      26258 Dec 22 01:15 
1001_20131008223200.mpg.-1.160x90.png
-rw-rw-rw- 1 mythtv mythtv      90696 Oct 13 21:23 1001_20131008223200.mpg.png
ls: write error: Broken pipe
erdos:~ $ ls /media/JG-BACKUP/mythtv/recordings/ | head -n1
1001_20121224170300.mpg
ls: write error: Broken pipe
erdos:~ $ ls /media/JG-BACKUP/mythtv/recordings/ | head -n10
1001_20121224170300.mpg
1001_20121224170300.mpg.png
1001_20130611223300.mpg
1001_20130611223300.mpg.-1.100x75.png
1001_20130611223300.mpg.png
1001_20131008223200.mpg
1001_20131008223200.mpg.-1.100x75.png
1001_20131008223200.mpg.-1.160x90.png
1001_20131008223200.mpg.png
1001_20131227205700.mpg
ls: write error: Broken pipe
erdos:~ $ ls /media/JG-BACKUP/mythtv/recordings/ | head -n20
1001_20121224170300.mpg
1001_20121224170300.mpg.png
1001_20130611223300.mpg
1001_20130611223300.mpg.-1.100x75.png
1001_20130611223300.mpg.png
1001_20131008223200.mpg
1001_20131008223200.mpg.-1.100x75.png
1001_20131008223200.mpg.-1.160x90.png
1001_20131008223200.mpg.png
1001_20131227205700.mpg
1001_20131227205700.mpg.png
1001_20131228205700.mpg
1001_20131228205700.mpg.png
1001_20131230144200.mpg
1001_20131230144200.mpg.png
1002_20121225151300.mpg
1002_20121225151300.mpg.png
1002_20121226105800.mpg
1002_20121226105800.mpg.-1.100x75.png
1002_20121226105800.mpg.png
ls: write error: Broken pipe
erdos:~ $ ls /media/JG-BACKUP/mythtv/recordings/ | head 
1001_20121224170300.mpg
1001_20121224170300.mpg.png
1001_20130611223300.mpg
1001_20130611223300.mpg.-1.100x75.png
1001_20130611223300.mpg.png
1001_20131008223200.mpg
1001_20131008223200.mpg.-1.100x75.png
1001_20131008223200.mpg.-1.160x90.png
1001_20131008223200.mpg.png
1001_20131227205700.mpg
ls: write error: Broken pipe
erdos:~ $ ls /media/JG-BACKUP/mythtv/recordings/ | head 
1001_20121224170300.mpg
1001_20121224170300.mpg.png
1001_20130611223300.mpg
1001_20130611223300.mpg.-1.100x75.png
1001_20130611223300.mpg.png
1001_20131008223200.mpg
1001_20131008223200.mpg.-1.100x75.png
1001_20131008223200.mpg.-1.160x90.png
1001_20131008223200.mpg.png
1001_20131227205700.mpg
ls: write error: Broken pipe
erdos:~ $ 

That makes no sense to me :-(  The first invocation of ls | head
succeeds, the final one fails.

> It isn't an intrinsic problem with xfce4 as I am supporting others
> that are using it without problem.  If we can determine where this
> comes into play then we can reassign the bug to the proper package as
> this isn't a bug in coreutils.  Or we could close this bug, continue
> the discussion offline until we determine the root cause, and then
> potentially submit a new bug with more targeted information.  We can
> always update the bug with the root cause once it is found to help
> others that come along later.
> 
> How is your xfce4 launched?  Are you using one of the list of xinit,
> startx, xdm, gdm, gdm3, kde, lightdm or other?

I'm launching it from gdm3 3.8.4-6; I'm running testing.

> > Bemused,
> 
> (Chuckle.)

So I get that SIGPIPE is being ignored.  The process tree is:

init -> gdm3 -> gdm-simple-slave -> gdm-session-worker -> sh ->
  xfce4-session -> xfce4-panel -> xfce4-terminal -> bash

So it's somewhere in that mix, and I've tracked it down to
xfce4-terminal (because running the ls | head commands in an xterm
instead of in xfce4-terminal works just fine).

And in xfce4-terminal, line 172 of terminal/main.c (the first line of
code executed by xfce4-terminal!) reads:

  signal (SIGPIPE, SIG_IGN);

and this is never undone.  This was introduced in xfce4-terminal
version 0.2.5.8rc2 (fixing xfce bug #2349), and we are currently at
0.6.2-4, so I'm not sure why I'm the first one to notice this
problematic behaviour.

Anyway, a proposed bug-fix is attached: the signal handler is reset
before the shell process is forked.  There is also another tiny bugfix
in this patch: since the #include <signal.h> is enclosed within an
#ifdef HAVE_SIGNAL_H clause, I've enclosed the call to signal() within
a similar clause in main.c.

   Julian
--- a/terminal/main.c
+++ b/terminal/main.c
@@ -169,7 +169,9 @@
   const gchar     *msg;
 
   /* install required signal handlers */
+#ifdef HAVE_SIGNAL_H
   signal (SIGPIPE, SIG_IGN);
+#endif
 
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -37,6 +37,9 @@
 #ifdef HAVE_TIME_H
 #include <time.h>
 #endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 
 #include <libxfce4ui/libxfce4ui.h>
 
@@ -1543,6 +1546,9 @@
           spawn_flags |= G_SPAWN_FILE_AND_ARGV_ZERO;
         }
 
+#ifdef HAVE_SIGNAL_H
+      signal (SIGPIPE, SIG_DFL);
+#endif
       if (!vte_terminal_fork_command_full (VTE_TERMINAL (screen->terminal),
                                            update ? VTE_PTY_DEFAULT : 
VTE_PTY_NO_LASTLOG | VTE_PTY_NO_UTMP | VTE_PTY_NO_WTMP,
                                            screen->working_directory, argv2, 
env,
@@ -1554,6 +1560,9 @@
                                   error, _("Failed to execute child"));
           g_error_free (error);
         }
+#ifdef HAVE_SIGNAL_H
+      signal (SIGPIPE, SIG_IGN);
+#endif
 
       g_free (argv2);
 

Reply via email to