[PATCH] Avoid having a dead Plymouth cause clients to get SIGPIPE'd

Soren Hansen soren at linux2go.dk
Mon Feb 21 04:14:35 PST 2011


If Plymouth dies for some reason, clients will get SIGPIPE'd next time
they try to talk to it. Address this by passing MSG_NOSIGNAL to send
and leave it to standard errno handling to deal with the error.

Since ply_write is used for non-socket communication as well, first
attempt to use send(2), then fall back to write(2).

Signed-off-by: Soren Hansen <soren at linux2go.dk>
---
 configure.ac           |    2 ++
 src/libply/ply-utils.c |   19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2209df1..02bd2e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -280,6 +280,8 @@ AC_DEFINE_UNQUOTED(BOOT_TTY, "$BOOT_TTY", [TTY to use in boot mode])
 AC_ARG_WITH(shutdown-tty, AS_HELP_STRING([--with-shutdown-tty=<tty>],[Default TTY to use in shutdown mode (by default tty63)]),SHUTDOWN_TTY=${withval},SHUTDOWN_TTY=/dev/tty63)
 AC_DEFINE_UNQUOTED(SHUTDOWN_TTY, "$SHUTDOWN_TTY", [TTY to use in shutdown mode])
 
+AC_CHECK_DECLS([MSG_NOSIGNAL], [], [], [[ #include <sys/socket.h> ]])
+
 # Turn on the additional warnings last, so -Werror doesn't affect other tests.
 
 AC_DEFUN([PLYMOUTH_CC_TRY_FLAG], [
diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c
index 5b06e49..bd03e61 100644
--- a/src/libply/ply-utils.c
+++ b/src/libply/ply-utils.c
@@ -306,6 +306,7 @@ ply_write (int         fd,
 {
   size_t bytes_left_to_write;
   size_t total_bytes_written = 0;
+  int is_a_socket = 1;
 
   assert (fd >= 0);
 
@@ -315,15 +316,27 @@ ply_write (int         fd,
     {
       ssize_t bytes_written = 0;
 
-      bytes_written = write (fd,
-                             ((uint8_t *) buffer) + total_bytes_written,
-                             bytes_left_to_write);
+      if (is_a_socket)
+        bytes_written = send  (fd,
+                               ((uint8_t *) buffer) + total_bytes_written,
+                               bytes_left_to_write,
+                               0
+#if HAVE_DECL_MSG_NOSIGNAL
+                               |MSG_NOSIGNAL
+#endif
+                               );
+      else
+        bytes_written = write (fd,
+                               ((uint8_t *) buffer) + total_bytes_written,
+                               bytes_left_to_write);
 
       if (bytes_written > 0)
         {
           total_bytes_written += bytes_written;
           bytes_left_to_write -= bytes_written;
         }
+      else if ((errno == ENOTSOCK))
+        is_a_socket = 0;
       else if ((errno != EINTR))
         break;
     }
-- 
1.7.2.3



More information about the plymouth mailing list