OSDN Git Service

sens: fix server crash after stopping the poll client
authorOctavian Purdila <octavian.purdila@intel.com>
Mon, 24 Nov 2014 13:47:27 +0000 (15:47 +0200)
committerAdriana Reus <adriana.reus@intel.com>
Wed, 3 Dec 2014 13:56:06 +0000 (15:56 +0200)
If the poll client is stopped (killed) the server will crash due to
SIGPIPE. Fix this by intercepting SIGPIPE and clearing the client file
to avoid further prints to it.

Change-Id: I588b9c098634e2eb5cec9dd003e4f9a3be188c3f
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
sens.c

diff --git a/sens.c b/sens.c
index efb5811..5be4cc0 100644 (file)
--- a/sens.c
+++ b/sens.c
@@ -9,6 +9,7 @@
 #include <dlfcn.h>
 #include <pthread.h>
 #include <errno.h>
+#include <signal.h>
 
 #include <hardware/sensors.h>
 #include <utils/Log.h>
@@ -176,8 +177,16 @@ static void run_sensors_poll_v0(void)
        }
 }
 
+static void sig_pipe(int sig)
+{
+       client = NULL;
+}
+
 static void *run_sensors_thread(void *arg __attribute((unused)))
 {
+
+       signal(SIGPIPE, sig_pipe);
+
        switch (dev->version) {
        case SENSORS_DEVICE_API_VERSION_0_1:
        default:
@@ -408,7 +417,6 @@ static int start_server(void)
                        fclose(f);
                }
 
-
                close(conn);
        }
 }