Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: solved: segment faults from osdtelext plugin (was:Re: Re: Segment faults 43) (was: Re: Segment faults 43)



I demand that Rainer Zocholl may or may not have written...

> After replacing all obviously/known not thread save clib calls
> with their thread save counterparts osdteletext now runs!

> I would not waste any time to investigate which of those
> calls are the minimum or why the seg faults are caused in detail.
> There is no adavantage using non-thread save functions in a
> multithreaded environment. The overhead is neglectable.
[snip patch]

I've gone through and recompiled vdr and the plugins which are installed
here, based on what you've done. Patches attached (note that vdr-remote
didn't need to be patched).

-- 
| Darren Salt | d youmustbejoking,demon,co,uk | nr. Ashington,
| Debian,     | s zap,tartarus,org            | Northumberland
| RISC OS     | @                             | Toon Army
|   <URL:http://www.youmustbejoking.demon.co.uk/> (PGP 2.6, GPG keys)

All diagnostics are fatal.
diff -urNad vdr-1.3.17/channels.c /tmp/dpep.QNRMf0/vdr-1.3.17/channels.c
--- vdr-1.3.17/channels.c	2004-12-04 18:08:06.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/channels.c	2004-12-04 18:08:07.000000000 +0000
@@ -705,7 +705,8 @@
            p = apidbuf;
            char *q;
            int NumApids = 0;
-           while ((q = strtok(p, ",")) != NULL) {
+           char * lasts=NULL;
+           while ((q = strtok_r(p, ",", &lasts)) != NULL) {
                  if (NumApids < MAXAPIDS) {
                     char *l = strchr(q, '=');
                     if (l) {
@@ -725,7 +726,8 @@
               char *p = dpidbuf;
               char *q;
               int NumDpids = 0;
-              while ((q = strtok(p, ",")) != NULL) {
+              char * lasts=NULL;
+              while ((q = strtok_r(p, ",", &lasts)) != NULL) {
                     if (NumDpids < MAXAPIDS) {
                        char *l = strchr(q, '=');
                        if (l) {
@@ -747,7 +749,8 @@
               char *p = caidbuf;
               char *q;
               int NumCaIds = 0;
-              while ((q = strtok(p, ",")) != NULL) {
+              char * lasts=NULL;
+              while ((q = strtok_r(p, ",", &lasts)) != NULL) {
                     if (NumCaIds < MAXCAIDS) {
                        caids[NumCaIds++] = strtol(q, NULL, 16) & 0xFFFF;
                        if (NumCaIds == 1 && caids[0] <= 0x00FF)
diff -urNad vdr-1.3.17/config.h /tmp/dpep.QNRMf0/vdr-1.3.17/config.h
--- vdr-1.3.17/config.h	2004-12-04 18:08:07.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/config.h	2004-12-04 18:08:07.000000000 +0000
@@ -16,6 +16,9 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#pragma GCC poison alctime ctime gmtime localtime
+#pragma GCC poison getgrgid getgrnam getpwnam getpwuid
+#pragma GCC poison rand readdir strtok
 #include "device.h"
 #include "i18n.h"
 #include "tools.h"
diff -urNad vdr-1.3.17/eit.c /tmp/dpep.QNRMf0/vdr-1.3.17/eit.c
--- vdr-1.3.17/eit.c	2004-12-04 18:08:06.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/eit.c	2004-12-04 18:08:07.000000000 +0000
@@ -244,9 +244,10 @@
   time_t loctim = time(NULL);
 
   if (abs(sattim - loctim) > 2) {
+     char timebuf[26]; /* This magic number is based on the ctime(3c) man page */
      mutex.Lock();
-     isyslog("System Time = %s (%ld)\n", ctime(&loctim), loctim);
-     isyslog("Local Time  = %s (%ld)\n", ctime(&sattim), sattim);
+     isyslog("System Time = %s (%ld)\n", ctime_r(&loctim, timebuf), loctim);
+     isyslog("Local Time  = %s (%ld)\n", ctime_r(&sattim, timebuf), sattim);
      if (stime(&sattim) < 0)
         esyslog("ERROR while setting system time: %m");
      mutex.Unlock();
diff -urNad vdr-1.3.17/keys.c /tmp/dpep.QNRMf0/vdr-1.3.17/keys.c
--- vdr-1.3.17/keys.c	2004-12-04 18:08:06.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/keys.c	2004-12-04 18:08:07.000000000 +0000
@@ -195,7 +195,8 @@
 {
   int n = 0;
   char *p;
-  while ((p = strtok(s, " \t")) != NULL) {
+  char * lasts=NULL;
+  while ((p = strtok_r(s, " \t", &lasts)) != NULL) {
         if (n < MAXKEYSINMACRO) {
            if (*p == '@') {
               if (plugin) {
diff -urNad vdr-1.3.17/plugin.c /tmp/dpep.QNRMf0/vdr-1.3.17/plugin.c
--- vdr-1.3.17/plugin.c	2004-12-04 18:08:07.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/plugin.c	2004-12-04 18:21:42.000000000 +0000
@@ -7,12 +7,12 @@
  * $Id: plugin.c 1.11 2004/05/22 11:25:22 kls Exp $
  */
 
-#include "plugin.h"
 #include <ctype.h>
 #include <dirent.h>
 #include <dlfcn.h>
 #include <stdlib.h>
 #include <time.h>
+#include "plugin.h"
 #include "config.h"
 
 #define LIBVDR_PREFIX  "libvdr-"
@@ -258,8 +258,8 @@
   if (strcmp(Args, "*") == 0) {
      DIR *d = opendir(directory);
      if (d) {
-        struct dirent *e;
-        while ((e = readdir(d)) != NULL) {
+        struct dirent *e, p;
+        while (!readdir_r(d, &p, &e) && e != NULL) {
               if (strstr(e->d_name, LIBVDR_PREFIX) == e->d_name) {
                  char *p = strstr(e->d_name, SO_INDICATOR);
                  if (p) {
diff -urNad vdr-1.3.17/recording.c /tmp/dpep.QNRMf0/vdr-1.3.17/recording.c
--- vdr-1.3.17/recording.c	2004-12-04 18:08:07.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/recording.c	2004-12-04 18:21:43.000000000 +0000
@@ -7,7 +7,6 @@
  * $Id: recording.c 1.92 2004/11/01 14:04:47 kls Exp $
  */
 
-#include "recording.h"
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -15,6 +14,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include "recording.h"
 #include "channels.h"
 #include "i18n.h"
 #include "interface.h"
@@ -631,8 +631,8 @@
 {
   DIR *d = opendir(DirName);
   if (d) {
-     struct dirent *e;
-     while ((e = readdir(d)) != NULL) {
+     struct dirent *e, p;
+     while (!readdir_r(d, &p, &e) && e != NULL) {
            if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
               char *buffer;
               asprintf(&buffer, "%s/%s", DirName, e->d_name);
diff -urNad vdr-1.3.17/svdrp.c /tmp/dpep.QNRMf0/vdr-1.3.17/svdrp.c
--- vdr-1.3.17/svdrp.c	2004-12-04 18:08:06.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/svdrp.c	2004-12-04 18:08:07.000000000 +0000
@@ -555,8 +555,9 @@
      char buf[strlen(Option) + 1];
      char *p = strcpy(buf, Option);
      const char *delim = " \t";
-     FileName = strtok(p, delim);
-     if ((p = strtok(NULL, delim)) != NULL) {
+     char * lasts=NULL;
+     FileName = strtok_r(p, delim, &lasts);
+     if ((p = strtok_r(NULL, delim, &lasts)) != NULL) {
         if (strcasecmp(p, "JPEG") == 0)
            Jpeg = true;
         else if (strcasecmp(p, "PNM") == 0)
@@ -566,7 +567,7 @@
            return;
            }
         }
-     if ((p = strtok(NULL, delim)) != NULL) {
+     if ((p = strtok_r(NULL, delim, &lasts)) != NULL) {
         if (isnumber(p))
            Quality = atoi(p);
         else {
@@ -574,14 +575,14 @@
            return;
            }
         }
-     if ((p = strtok(NULL, delim)) != NULL) {
+     if ((p = strtok_r(NULL, delim, &lasts)) != NULL) {
         if (isnumber(p))
            SizeX = atoi(p);
         else {
            Reply(501, "Illegal sizex \"%s\"", p);
            return;
            }
-        if ((p = strtok(NULL, delim)) != NULL) {
+        if ((p = strtok_r(NULL, delim, &lasts)) != NULL) {
            if (isnumber(p))
               SizeY = atoi(p);
            else {
@@ -594,7 +595,7 @@
            return;
            }
         }
-     if ((p = strtok(NULL, delim)) != NULL) {
+     if ((p = strtok_r(NULL, delim, &lasts)) != NULL) {
         Reply(501, "Unexpected parameter \"%s\"", p);
         return;
         }
@@ -609,6 +610,7 @@
 
 void cSVDRP::CmdHELP(const char *Option)
 {
+
   if (*Option) {
      const char *hp = GetHelpPage(Option);
      if (hp)
@@ -727,7 +729,8 @@
         char buf[strlen(Option) + 1];
         strcpy(buf, Option);
         const char *delim = " \t";
-        char *p = strtok(buf, delim);
+        char * lasts=NULL;
+        char *p = strtok_r(buf, delim, &lasts);
         while (p && DumpMode == dmAll) {
               if (strcasecmp(p, "NOW") == 0)
                  DumpMode = dmPresent;
@@ -735,7 +738,7 @@
                  DumpMode = dmFollowing;
               else if (strcasecmp(p, "AT") == 0) {
                  DumpMode = dmAtTime;
-                 if ((p = strtok(NULL, delim)) != NULL) {
+                 if ((p = strtok_r(NULL, delim, &lasts)) != NULL) {
                     if (isnumber(p))
                        AtTime = strtol(p, NULL, 10);
                     else {
@@ -770,7 +773,7 @@
                  Reply(501, "Unknown option: \"%s\"", p);
                  return;
                  }
-              p = strtok(NULL, delim);
+              p = strtok_r(NULL, delim, &lasts);
               }
         }
      FILE *f = fdopen(file, "w");
@@ -996,7 +999,8 @@
      time_t Start = t->StartTime();
      int Number = t->Index() + 1;
      if (!*Option) {
-        char *s = ctime(&Start);
+        char timebuf[26]; /* This magic number is based on the ctime(3c) man page */
+        char *s = ctime_r(&Start, timebuf);
         s[strlen(s) - 1] = 0; // strip trailing newline
         Reply(250, "%d %s", Number, s);
         }
@@ -1152,7 +1156,8 @@
         char buffer[BUFSIZ];
         gethostname(buffer, sizeof(buffer));
         time_t now = time(NULL);
-        Reply(220, "%s SVDRP VideoDiskRecorder %s; %s", buffer, VDRVERSION, ctime(&now));
+        char timebuf[26]; /* This magic number is based on the ctime(3c) man page */
+        Reply(220, "%s SVDRP VideoDiskRecorder %s; %s", buffer, VDRVERSION, ctime_r(&now, timebuf));
         }
      if (NewConnection)
         lastActivity = time(NULL);
diff -urNad vdr-1.3.17/themes.c /tmp/dpep.QNRMf0/vdr-1.3.17/themes.c
--- vdr-1.3.17/themes.c	2004-06-18 16:05:07.000000000 +0100
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/themes.c	2004-12-04 18:21:44.000000000 +0000
@@ -244,8 +244,8 @@
   if (themesDirectory) {
      DIR *d = opendir(themesDirectory);
      if (d) {
-        struct dirent *e;
-        while ((e = readdir(d)) != NULL) {
+        struct dirent *e, p;
+        while (!readdir_r(d, &p, &e) && e != NULL) {
               if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
                  if (strstr(e->d_name, SkinName) == e->d_name && e->d_name[strlen(SkinName)] == '-') {
                     const char *FileName = AddDirectory(themesDirectory, e->d_name);
diff -urNad vdr-1.3.17/vdr.c /tmp/dpep.QNRMf0/vdr-1.3.17/vdr.c
--- vdr-1.3.17/vdr.c	2004-12-04 18:08:07.000000000 +0000
+++ /tmp/dpep.QNRMf0/vdr-1.3.17/vdr.c	2004-12-04 18:08:07.000000000 +0000
@@ -892,9 +892,10 @@
                     free(buf);
                     }
                  if (!Next || Delta > Setup.MinEventTimeout * 60 || ForceShutdown) {
+                    char timebuf[26]; /* This magic number is based on the ctime(3c) man page */
                     ForceShutdown = false;
                     if (timer)
-                       dsyslog("next timer event at %s", ctime(&Next));
+                       dsyslog("next timer event at %s", ctime_r(&Next, timebuf));
                     if (WatchdogTimeout > 0)
                        signal(SIGALRM, SIG_IGN);
                     if (Interface->Confirm(tr("Press any key to cancel shutdown"), UserShutdown ? 5 : SHUTDOWNWAIT, true)) {
--- vdr-plugin-epgsearch-0.0.3.orig/menu_searchresults.c
+++ vdr-plugin-epgsearch-0.0.3/menu_searchresults.c
@@ -174,10 +174,10 @@
 		bTesting = true;
         if (SearchExt->mode > 0)
         { 
-		char *pstrSearchToken;
+		char *pstrSearchToken, *strptr;
         	bool bFirst=true;
 	        char *pstrSearch=strdup(searchText);
-       		pstrSearchToken=strtok(pstrSearch, " ,;|");
+       		pstrSearchToken=strtok_r(pstrSearch, " ,;|", &strptr);
         	while(pstrSearchToken) {
            		if(szTest && strstr(szTest, pstrSearchToken)) { 
               			if(SearchExt->mode==1) { // means AND
@@ -195,7 +195,7 @@
                  			bFirst=false;
               			}
            		}
-          		pstrSearchToken=strtok(NULL, " ,;|");
+          		pstrSearchToken=strtok_r(NULL, " ,;|", &strptr);
 		}
 		free(pstrSearch);
 
@@ -207,7 +207,8 @@
         if (SearchExt->useTime)
         {
 		time_t tEvent = p->StartTime();
-		struct tm tmEvent = *localtime(&tEvent);
+		struct tm tmEvent;
+		localtime_r(&tEvent, &tmEvent);
 		int eventStart = tmEvent.tm_hour*100 + tmEvent.tm_min;	
 		int eventStart2 = tmEvent.tm_hour*100 + tmEvent.tm_min + 2400;	
 		if ((eventStart < searchStart || eventStart > searchStop) &&
diff -urNad vdr-plugin-subtitles-0.3.6/subfilter.c /tmp/dpep.Ma32qy/vdr-plugin-subtitles-0.3.6/subfilter.c
--- vdr-plugin-subtitles-0.3.6/subfilter.c	2004-10-19 17:19:33.000000000 +0100
+++ /tmp/dpep.Ma32qy/vdr-plugin-subtitles-0.3.6/subfilter.c	2004-12-04 21:41:41.000000000 +0000
@@ -211,9 +211,9 @@
 	}
 	else
 	{
-	    char *streamstr;
+	    char *streamstr, *tok;
 	    char *p = streamsbuf;
-	    while ((streamstr = strtok(p, ",")) != NULL)
+	    while ((streamstr = strtok_r(p, ",", &tok)) != NULL)
 	    {
 		tSubtitleStream stream = tSubtitleStream::FromString(streamstr);
 		if (stream.languageIndex != -1)
diff -urNad vdr-plugin-xine-0.6.0/xineLib.c /tmp/dpep.V9DYZ2/vdr-plugin-xine-0.6.0/xineLib.c
--- vdr-plugin-xine-0.6.0/xineLib.c	2004-12-04 21:52:39.000000000 +0000
+++ /tmp/dpep.V9DYZ2/vdr-plugin-xine-0.6.0/xineLib.c	2004-12-04 21:53:28.000000000 +0000
@@ -1,11 +1,4 @@
 
-#include <vdr/plugin.h>
-
-#include "xineLib.h"
-#include "xineOsd.h"
-#include "xineSettings.h"
-
-
 #include <assert.h>
 #include <signal.h>
 #include <math.h>
@@ -24,9 +17,14 @@
 #include <xine.h>
 #include <xine/xineutils.h>
 
+#include <string>
 
+#include "xineLib.h"
+#include "xineOsd.h"
+#include "xineSettings.h"
+
+#include <vdr/plugin.h>
 
-#include <string>
 using namespace std;
 
 

Home | Main Index | Thread Index