Skip to contentSkip to conversation

lib/cobalt: start helper thread with signals blocked

PATCH In review Norbert Lange 2 participants 3 messages Jun 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib/cobalt: start helper thread with signals blocked

Delivery mechanisms like sigwait and signalfd require *all* threads to block the relevant signals.
The cobalt init should not spawn a thread affecting the signal-handling.

---
 lib/cobalt/printf.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/cobalt/printf.c +5 -0
index e109deaec..33ff7f9ac 100644
@@ -20,6 +20,7 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -640,9 +641,13 @@ static void *printer_loop(void *arg)
 static void spawn_printer_thread(void)
 {
 	pthread_attr_t thattr;
+	sigset_t sset, oset;
 
 	pthread_attr_init(&thattr);
+	sigfillset(&sset);
+	pthread_sigmask(SIG_BLOCK, &sset, &oset);
 	pthread_create(&printer_thread, &thattr, printer_loop, NULL);
+	sigprocmask(SIG_SETMASK, &oset, NULL);
 }
 
 void cobalt_print_init_atfork(void)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 lib/cobalt: set name for printf thread to help debugging

---
 lib/cobalt/printf.c | 1 +
 1 file changed, 1 insertion(+)
lib/cobalt/printf.c +1 -0
index 33ff7f9ac..7426f2bda 100644
@@ -648,6 +648,7 @@ static void spawn_printer_thread(void)
 	pthread_sigmask(SIG_BLOCK, &sset, &oset);
 	pthread_create(&printer_thread, &thattr, printer_loop, NULL);
 	sigprocmask(SIG_SETMASK, &oset, NULL);
+	pthread_setname_np(printer_thread, "cobalt_printf");
 }
 
 void cobalt_print_init_atfork(void)
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 2/2] lib/cobalt: set name for printf thread to help debugging

Quoted 11 lines · Norbert Lange via Xenomai
---
  lib/cobalt/printf.c | 1 +
  1 file changed, 1 insertion(+)
lib/cobalt/printf.c +0 -0
index 33ff7f9ac..7426f2bda 100644

lib/cobalt/printf.c static void spawn_printer_thread(void) · line 654

Quoted 7 lines
lib/cobalt/printf.c +1 -0
@@ -648,6 +648,7 @@ static void spawn_printer_thread(void)
  	pthread_sigmask(SIG_BLOCK, &sset, &oset);
  	pthread_create(&printer_thread, &thattr, printer_loop, NULL);
  	sigprocmask(SIG_SETMASK, &oset, NULL);
+	pthread_setname_np(printer_thread, "cobalt_printf");
  }
 
  void cobalt_print_init_atfork(void)

Thanks, both applied.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux