Control: tags -1 + patch

Ian Jackson writes ("Re: [Pkg-xfce-devel] Bug#823460: lightdm: SIGPIPE ignored 
in session"):
> Do you want me to send you a patch ?

The patch is straightforward.  See attached.

Also a fixed version of the glibc patch which gets the checking for
signals other than PIPE right.

Regards,
Ian.

diff --git a/debian/changelog b/debian/changelog
index df6c1aa..551697f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+lightdm (1.18.1-1+iwj1) UNRELEASED; urgency=medium
+
+  * Reset SIGPIPE in session_child_run.  Closes:#823460.
+  * Reset SIGPIPE in process_start (affects the X server, for example).
+
+ -- Ian Jackson <ijack...@chiark.greenend.org.uk>  Sun, 08 May 2016 17:50:01 
+0100
+
 lightdm (1.18.1-1) unstable; urgency=medium
 
   * New upstream bugfix release.
diff --git a/src/process.c b/src/process.c
index d9b7eb9..dbe86c8 100644
--- a/src/process.c
+++ b/src/process.c
@@ -213,6 +213,8 @@ process_start (Process *process, gboolean block)
     pid = fork ();
     if (pid == 0)
     {
+        signal(SIGPIPE, SIG_DFL); /* Undo glib2.0's SIG_IGN */
+
         /* Do custom setup */
         if (process->priv->run_func)
             process->priv->run_func (process, process->priv->run_func_data);
diff --git a/src/session-child.c b/src/session-child.c
index f3a5e1b..981cfb7 100644
--- a/src/session-child.c
+++ b/src/session-child.c
@@ -676,6 +676,8 @@ session_child_run (int argc, char **argv)
     child_pid = fork ();
     if (child_pid == 0)
     {
+        signal(SIGPIPE, SIG_DFL); /* Undo glib2.0's SIG_IGN */
+
         /* Make this process its own session */
         if (setsid () < 0)
             _exit (errno);
diff --git a/csu/init-first.c b/csu/init-first.c
index b3bacdd..adc2785 100644
--- a/csu/init-first.c
+++ b/csu/init-first.c
@@ -39,6 +39,92 @@ int __libc_argc attribute_hidden;
 char **__libc_argv attribute_hidden;
 
 
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+
+static void
+__libc_check_sigpipe (const char *argv0)
+{
+  static const int sigs[] = { SIGPIPE, SIGTERM, SIGALRM, 9 };
+  const int *sigp;
+  int sig;
+  struct sigaction sa;
+  sigset_t mask;
+  int r;
+  const char *oddity;
+
+  sig = 0;
+  r = sigprocmask(SIG_UNBLOCK, 0, &mask);
+  if (r) { oddity = strerror(errno); goto bad; }
+
+  for (sigp = sigs; (sig = *sigp); sigp++) {
+    r = sigaction(sig, 0, &sa);
+    if (r) { oddity = strerror(errno); goto bad; }
+    if (sa.sa_handler == SIG_IGN) { oddity = "SIG_IGN"; goto bad; }
+    if (sigismember(&mask, sig)) { oddity = "blocked"; goto bad; }
+  }
+  return;
+
+ bad:;
+  int logfd = -1;
+  FILE *logf = 0;
+
+  logfd = open("/var/log/exec-sigignblock.log", O_APPEND|O_WRONLY);
+  if (logfd < 0)
+    if (errno == ENOENT || errno == EACCES || errno == EPERM)
+      return;
+
+  logf = fdopen(logfd, "a");
+  if (!logf) goto fail;
+  logfd = -1; /* eaten by fdopen */
+
+  unsigned long ourpid = getpid();
+  unsigned long ppid = getppid();
+  char parentbuf[100];
+
+  snprintf(parentbuf, sizeof(parentbuf), "/proc/%lu/exe", ppid);
+  r = readlink(parentbuf, parentbuf, sizeof(parentbuf)-1);
+  if (r < 0) {
+    const char *m = strerror(errno);
+    strncpy(parentbuf, m, sizeof(parentbuf)-1);
+    parentbuf[sizeof(parentbuf)-1] = 0;
+  } else if (r == 0) {
+    strcpy(parentbuf, "\"\"");
+  } else {
+    parentbuf[r] = 0;
+  }
+
+  time_t now;
+  now = time(NULL);
+  if (now == (time_t)-1) { errno = EIO; goto fail; }
+
+  struct tm *gmt = gmtime(&now);
+  if (!gmt) goto fail;
+
+  r = fprintf(logf, "%04d-%02d-%02d %02d:%02d:%02d UTC:"
+             "%s[%lu] execd oddly (parent %s[%lu]): %s: %s\n",
+             gmt->tm_year+1900, gmt->tm_mon, gmt->tm_mday,
+             gmt->tm_hour, gmt->tm_min, gmt->tm_sec,
+             argv0, ourpid,
+             parentbuf, ppid,
+             sig ? strsignal(sig) : "sigprocmask", oddity);
+  if (r < 0) goto fail;
+
+  r = fclose(logf);
+  logf = 0;
+  if (r) goto fail;
+
+  return;
+
+ fail:
+  perror("__libc_check_sigpipe report oddity");
+  if (logf) fclose(logf);
+  if (logfd>=0) close(logfd);
+  return;
+}
+
 void
 __libc_init_first (int argc, char **argv, char **envp)
 {
@@ -96,6 +182,8 @@ _init (int argc, char **argv, char **envp)
 #if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
   __libc_global_ctors ();
 #endif
+
+  __libc_check_sigpipe (argv[0]);
 }
 
 /* This function is defined here so that if this file ever gets into
diff --git a/debian/changelog b/debian/changelog
index f552f26..33a6254 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+glibc (2.22-7+iwj) UNRELEASED; urgency=medium
+
+  * SIGPIPE tracking
+
+ -- Ian Jackson <ijack...@chiark.greenend.org.uk>  Sun, 08 May 2016 12:43:46 
+0100
+
 glibc (2.22-7) unstable; urgency=medium
 
   [ Samuel Thibault ]
diff --git a/debian/shlibs-add-udebs b/debian/shlibs-add-udebs
old mode 100644
new mode 100755

Reply via email to