]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvh thread: print the deadlock text also to stderr
authorJaroslav Kysela <perex@perex.cz>
Wed, 28 Nov 2018 11:41:49 +0000 (12:41 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 28 Nov 2018 11:42:10 +0000 (12:42 +0100)
src/tvh_thread.c

index 11ca776daeeb45e86076e35d7a3d4c32438e47e1..24982cca1b85aa3428516d6cee9c5e7c6cfd62a6 100644 (file)
@@ -9,6 +9,7 @@
 #include <signal.h>
 
 #include "settings.h"
+#include "htsbuf.h"
 
 #ifdef PLATFORM_LINUX
 #include <sys/prctl.h>
@@ -384,12 +385,23 @@ static void tvh_thread_mutex_deadlock(tvh_mutex_t *mutex)
   int fd = hts_settings_open_file(HTS_SETTINGS_OPEN_WRITE | HTS_SETTINGS_OPEN_DIRECT, "mutex-deadlock.txt");
   if (fd < 0) fd = fileno(stderr);
   int sid = mutex->mutex.__data.__owner; /* unportable */
-  char name[256];
+  char name[256], *s;
+  htsbuf_queue_t q;
+  size_t l;
+
   thread_get_name(mutex->thread, name, sizeof(name));
-  FILE *f = fdopen(fd, "w");
-  fprintf(f, "Thread %i: %s\n", sid, name);
-  fprintf(f, "  locked in: %s:%i\n", mutex->filename, mutex->lineno);
-  fclose(f);
+
+  htsbuf_queue_init(&q, 0);
+  htsbuf_qprintf(&q, "Thread %i: %s\n", sid, name);
+  htsbuf_qprintf(&q, "  locked in: %s:%i\n", mutex->filename, mutex->lineno);
+
+  s = htsbuf_to_string(&q);
+  l = s ? strlen(s) : 0;
+  if (l > 0) {
+    tvh_write(fd, s, l);
+    tvh_write(STDERR_FILENO, s, l);
+  }
+
   abort();
 }
 #endif