Mailing List archive

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

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




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.


  

The time would be better invested to find not so obvious
non reentrant /thread save funktions.


BTW:
osdteletext uses a "localtime" too...
fixing that alone did not help.


So this long list required:


--- ../org/vdr-1.3.17/channels.c        Tue Nov  2 19:07:05 2004
+++ channels.c  Sat Dec  4 16:03:49 2004
@@ -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)


--- ../org/vdr-1.3.17/keys.c    Sun Sep 14 12:07:47 2003
+++ keys.c      Sat Dec  4 16:05:34 2004
@@ -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) {


--- ../org/vdr-1.3.17/keys.c    Sun Sep 14 12:07:47 2003
+++ keys.c      Sat Dec  4 16:05:34 2004
@@ -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) {


--- ../org/vdr-1.3.17/svdrp.c   Sun Oct 31 11:09:53 2004
+++ svdrp.c     Sat Dec  4 16:17:24 2004
@@ -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);


--- ../org/vdr-1.3.17/eit.c     Sun Oct 31 13:56:24 2004
+++ eit.c       Sat Dec  4 15:45:12 2004
@@ -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();


--- ../org/vdr-1.3.17/vdr.c     Sat Nov  6 11:30:30 2004
+++ vdr.c       Sat Dec  4 15:48:44 2004
@@ -865,9 +865,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, t
rue)) {




and last but not least:
in PLUGINS/src/osdteletex:

--- txtbitmap.c.org     Sat Dec  4 13:28:04 2004
+++ txtbitmap.c Sat Dec  4 16:52:17 2004
@@ -189,7 +189,8 @@

    char zeichen[9];
    time_t t=time(0);
-   struct tm* loct=localtime(&t);
+   struct tm tm_r;
+   struct tm* loct=localtime_r(&t, &tm_r);
    sprintf(zeichen, "%02d:%02d:%02d", loct->tm_hour, loct->tm_min, loct->tm_sec);




Rainer---<=====>                         Vertraulich
             //
           //                              
         <=====>--------------ocholl, Kiel, Germany ------------





Home | Main Index | Thread Index