summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-04 23:47:25 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-04 23:47:25 +0900
commitaeeda1f77d1b21b15e916852baac06bb530618e2 (patch)
tree014f6af9fbda76d82101982880e2e36570b505aa
parentf72c47586743225756583e0961441e13bc7e0007 (diff)
efl - threads and signals - make efl work on "insane" os's with signals
so. on linux signals are delivered to the main process thread/loop. thats' where signal handlers are set up and always run. this is sane. it's predicatble. but of course this is not the same in bsd land. there "just send the signal to any old thread and call the signal handler there" seems to tbe the order of the day. this explains why wer are losing sigchld signals in edje_cc - it's heavily threaded and bsd is just randombly picking a thread to call it on. this fixes that. in theory. i hope. i can't test, but putting it in to share @fix
-rw-r--r--README7
-rw-r--r--src/bin/evas/evas_cserve2_slaves.c17
-rw-r--r--src/lib/eina/eina_debug_monitor.c17
-rw-r--r--src/lib/eina/eina_thread.c17
-rw-r--r--src/modules/emotion/xine/emotion_xine.c19
5 files changed, 70 insertions, 7 deletions
diff --git a/README b/README
index 30d5de6..4956591 100644
--- a/README
+++ b/README
@@ -32,12 +32,7 @@ PLATFORMS
32EFL is primarily developerd on Linux (GNU/Linux) and should work on 32EFL is primarily developerd on Linux (GNU/Linux) and should work on
33most distributions as long as dependencies are provided. It has been 33most distributions as long as dependencies are provided. It has been
34compiled and run also on Windows (using MINGW32 - please see 34compiled and run also on Windows (using MINGW32 - please see
35http://www.winbuilds.org ), Mac OS X, FreeBSD and NetBSD. Due to 35http://www.winbuilds.org ), Mac OS X, FreeBSD and NetBSD.
36serious bugs in OpenBSD, EFL cannot be compiled or used there. Please
37see:
38
39https://www.mail-archive.com/search?l=misc@openbsd.org&q=subject:%22SIGCHLD+and+libpthread.so%22&o=newest&f=1
40
41 36
42COMPONENTS 37COMPONENTS
43---------- 38----------
diff --git a/src/bin/evas/evas_cserve2_slaves.c b/src/bin/evas/evas_cserve2_slaves.c
index 3958046..f790357 100644
--- a/src/bin/evas/evas_cserve2_slaves.c
+++ b/src/bin/evas/evas_cserve2_slaves.c
@@ -507,6 +507,7 @@ cserve2_slave_thread_run(Slave_Thread_Cb thread_cb, void *thread_data, Slave_Rea
507 pthread_t tid; 507 pthread_t tid;
508 int child[2], parent[2]; 508 int child[2], parent[2];
509 int flags; 509 int flags;
510 sigset_t oldset, newset;
510 511
511 s = calloc(1, sizeof(Slave_Thread)); 512 s = calloc(1, sizeof(Slave_Thread));
512 if (!s) 513 if (!s)
@@ -550,8 +551,23 @@ cserve2_slave_thread_run(Slave_Thread_Cb thread_cb, void *thread_data, Slave_Rea
550 sd->cb = thread_cb; 551 sd->cb = thread_cb;
551 sd->cb_data = thread_data; 552 sd->cb_data = thread_data;
552 553
554 sigemptyset(&newset);
555 sigaddset(&newset, SIGPIPE);
556 sigaddset(&newset, SIGALRM);
557 sigaddset(&newset, SIGCHLD);
558 sigaddset(&newset, SIGUSR1);
559 sigaddset(&newset, SIGUSR2);
560 sigaddset(&newset, SIGHUP);
561 sigaddset(&newset, SIGQUIT);
562 sigaddset(&newset, SIGINT);
563 sigaddset(&newset, SIGTERM);
564#ifdef SIGPWR
565 sigaddset(&newset, SIGPWR);
566#endif
567 sigprocmask(SIG_BLOCK, &newset, &oldset);
553 if (pthread_create(&tid, &slave_thread_attr, _slave_thread_cb, sd)) 568 if (pthread_create(&tid, &slave_thread_attr, _slave_thread_cb, sd))
554 { 569 {
570 sigprocmask(SIG_SETMASK, &oldset, NULL);
555 ERR("Could not start slave thread."); 571 ERR("Could not start slave thread.");
556 free(s); 572 free(s);
557 free(sd); 573 free(sd);
@@ -561,6 +577,7 @@ cserve2_slave_thread_run(Slave_Thread_Cb thread_cb, void *thread_data, Slave_Rea
561 close(parent[1]); 577 close(parent[1]);
562 return NULL; 578 return NULL;
563 } 579 }
580 sigprocmask(SIG_SETMASK, &oldset, NULL);
564 581
565 s->tid = tid; 582 s->tid = tid;
566 s->tdata = sd; 583 s->tdata = sd;
diff --git a/src/lib/eina/eina_debug_monitor.c b/src/lib/eina/eina_debug_monitor.c
index d11f0e5..18bd87e 100644
--- a/src/lib/eina/eina_debug_monitor.c
+++ b/src/lib/eina/eina_debug_monitor.c
@@ -20,6 +20,7 @@
20#include "eina_types.h" 20#include "eina_types.h"
21#include "eina_evlog.h" 21#include "eina_evlog.h"
22#include "eina_util.h" 22#include "eina_util.h"
23#include <signal.h>
23 24
24#ifdef EINA_HAVE_DEBUG 25#ifdef EINA_HAVE_DEBUG
25 26
@@ -355,11 +356,27 @@ void
355_eina_debug_monitor_thread_start(void) 356_eina_debug_monitor_thread_start(void)
356{ 357{
357 int err; 358 int err;
359 sigset_t oldset, newset;
358 360
359 // if it's already running - we're good. 361 // if it's already running - we're good.
360 if (_monitor_thread_runs) return; 362 if (_monitor_thread_runs) return;
361 // create debug monitor thread 363 // create debug monitor thread
364 sigemptyset(&newset);
365 sigaddset(&newset, SIGPIPE);
366 sigaddset(&newset, SIGALRM);
367 sigaddset(&newset, SIGCHLD);
368 sigaddset(&newset, SIGUSR1);
369 sigaddset(&newset, SIGUSR2);
370 sigaddset(&newset, SIGHUP);
371 sigaddset(&newset, SIGQUIT);
372 sigaddset(&newset, SIGINT);
373 sigaddset(&newset, SIGTERM);
374#ifdef SIGPWR
375 sigaddset(&newset, SIGPWR);
376#endif
377 sigprocmask(SIG_BLOCK, &newset, &oldset);
362 err = pthread_create(&_monitor_thread, NULL, _eina_debug_monitor, NULL); 378 err = pthread_create(&_monitor_thread, NULL, _eina_debug_monitor, NULL);
379 sigprocmask(SIG_SETMASK, &oldset, NULL);
363 if (err != 0) 380 if (err != 0)
364 { 381 {
365 fprintf(stderr, "EINA DEBUG ERROR: Can't create debug thread!\n"); 382 fprintf(stderr, "EINA DEBUG ERROR: Can't create debug thread!\n");
diff --git a/src/lib/eina/eina_thread.c b/src/lib/eina/eina_thread.c
index 37f66fd..a56bf80 100644
--- a/src/lib/eina/eina_thread.c
+++ b/src/lib/eina/eina_thread.c
@@ -34,6 +34,7 @@
34 34
35#include <pthread.h> 35#include <pthread.h>
36#include <errno.h> 36#include <errno.h>
37#include <signal.h>
37 38
38#if defined(EINA_HAVE_PTHREAD_AFFINITY) || defined(EINA_HAVE_PTHREAD_SETNAME) 39#if defined(EINA_HAVE_PTHREAD_AFFINITY) || defined(EINA_HAVE_PTHREAD_SETNAME)
39#ifndef __linux__ 40#ifndef __linux__
@@ -57,6 +58,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
57{ 58{
58 int err; 59 int err;
59 pthread_attr_t attr; 60 pthread_attr_t attr;
61 sigset_t oldset, newset;
60 62
61 pthread_attr_init(&attr); 63 pthread_attr_init(&attr);
62 if (affinity >= 0) 64 if (affinity >= 0)
@@ -74,7 +76,22 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
74 } 76 }
75 77
76 /* setup initial locks */ 78 /* setup initial locks */
79 sigemptyset(&newset);
80 sigaddset(&newset, SIGPIPE);
81 sigaddset(&newset, SIGALRM);
82 sigaddset(&newset, SIGCHLD);
83 sigaddset(&newset, SIGUSR1);
84 sigaddset(&newset, SIGUSR2);
85 sigaddset(&newset, SIGHUP);
86 sigaddset(&newset, SIGQUIT);
87 sigaddset(&newset, SIGINT);
88 sigaddset(&newset, SIGTERM);
89#ifdef SIGPWR
90 sigaddset(&newset, SIGPWR);
91#endif
92 sigprocmask(SIG_BLOCK, &newset, &oldset);
77 err = pthread_create((pthread_t *)t, &attr, func, data); 93 err = pthread_create((pthread_t *)t, &attr, func, data);
94 sigprocmask(SIG_SETMASK, &oldset, NULL);
78 pthread_attr_destroy(&attr); 95 pthread_attr_destroy(&attr);
79 96
80 if (err == 0) return EINA_TRUE; 97 if (err == 0) return EINA_TRUE;
diff --git a/src/modules/emotion/xine/emotion_xine.c b/src/modules/emotion/xine/emotion_xine.c
index 6ff6de1..0e55b3a 100644
--- a/src/modules/emotion/xine/emotion_xine.c
+++ b/src/modules/emotion/xine/emotion_xine.c
@@ -5,6 +5,7 @@
5#include <Eina.h> 5#include <Eina.h>
6#include <Evas.h> 6#include <Evas.h>
7#include <Ecore.h> 7#include <Ecore.h>
8#include <signal.h>
8 9
9#include "emotion_modules.h" 10#include "emotion_modules.h"
10#include "emotion_xine.h" 11#include "emotion_xine.h"
@@ -322,6 +323,7 @@ em_add(const Emotion_Engine *api EINA_UNUSED,
322{ 323{
323 Emotion_Xine_Video *ev; 324 Emotion_Xine_Video *ev;
324 int fds[2]; 325 int fds[2];
326 sigset_t oldset, newset;
325 327
326 ev = calloc(1, sizeof(Emotion_Xine_Video)); 328 ev = calloc(1, sizeof(Emotion_Xine_Video));
327 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL); 329 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
@@ -366,9 +368,24 @@ em_add(const Emotion_Engine *api EINA_UNUSED,
366 368
367 pthread_cond_init(&(ev->get_pos_len_cond), NULL); 369 pthread_cond_init(&(ev->get_pos_len_cond), NULL);
368 pthread_mutex_init(&(ev->get_pos_len_mutex), NULL); 370 pthread_mutex_init(&(ev->get_pos_len_mutex), NULL);
371 sigemptyset(&newset);
372 sigaddset(&newset, SIGPIPE);
373 sigaddset(&newset, SIGALRM);
374 sigaddset(&newset, SIGCHLD);
375 sigaddset(&newset, SIGUSR1);
376 sigaddset(&newset, SIGUSR2);
377 sigaddset(&newset, SIGHUP);
378 sigaddset(&newset, SIGQUIT);
379 sigaddset(&newset, SIGINT);
380 sigaddset(&newset, SIGTERM);
381#ifdef SIGPWR
382 sigaddset(&newset, SIGPWR);
383#endif
384 sigprocmask(SIG_BLOCK, &newset, &oldset);
369 pthread_create(&ev->get_pos_len_th, NULL, _em_get_pos_len_th, ev); 385 pthread_create(&ev->get_pos_len_th, NULL, _em_get_pos_len_th, ev);
370
371 pthread_create(&ev->slave_th, NULL, _em_slave, ev); 386 pthread_create(&ev->slave_th, NULL, _em_slave, ev);
387 sigprocmask(SIG_SETMASK, &oldset, NULL);
388
372 pthread_detach(ev->slave_th); 389 pthread_detach(ev->slave_th);
373 _em_slave_event(ev, 1, NULL); 390 _em_slave_event(ev, 1, NULL);
374 391