* next try to get a working new tokenizer. this seems to be working
authorWilfried Göesgens <willi@citadel.org>
Tue, 14 Aug 2007 14:26:05 +0000 (14:26 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 14 Aug 2007 14:26:05 +0000 (14:26 +0000)
* a way to have backtraces in log in citserver.

citadel/citserver.c
citadel/configure.ac
citadel/tools.c

index d74c3a0ab74c3a80003cb8c260b34ff896f2b18e..46f3834f026aeab172d34bea83930b13de0da542 100644 (file)
 # endif
 #endif
 
+#if HAVE_BACKTRACE
+#include <execinfo.h>
+#endif
+
 #include <ctype.h>
 #include <string.h>
 #include <dirent.h>
@@ -66,6 +70,28 @@ int ScheduledShutdown = 0;
 int do_defrag = 0;
 time_t server_startup_time;
 
+/**
+ * \brief print the actual stack frame.
+ */
+void cit_backtrace(void)
+{
+#ifdef HAVE_BACKTRACE
+       void *stack_frames[50];
+       size_t size, i;
+       char **strings;
+
+
+       size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
+       strings = backtrace_symbols(stack_frames, size);
+       for (i = 0; i < size; i++) {
+               if (strings != NULL)
+                       lprintf(1, "%s\n", strings[i]);
+               else
+                       lprintf(1, "%p\n", stack_frames[i]);
+       }
+       free(strings);
+#endif
+}
 /*
  * Various things that need to be initialized at startup
  */
index f735aadf6e914ca0381d79ab2b5a4aa4ffe47758..af09ef2d94cf0fece82f2cbee3541ea0b39abfad 100644 (file)
@@ -294,7 +294,7 @@ dnl Checks for libraries.
 dnl We want to test for the following in libc before checking for their
 dnl respective libraries, because some systems (like Irix) have both, and the
 dnl non-libc versions may be broken.
-AC_CHECK_FUNCS(crypt gethostbyname connect)
+AC_CHECK_FUNCS(crypt gethostbyname connect backtrace)
 
 if test "$ac_cv_func_gethostbyname" = no; then
        AC_CHECK_LIB(nsl, gethostbyname)
index 86ab798f6dc41494839f6d0915cf00cf91adfd94..7016d96b03783d547869eb5cd848a8ec27929732 100644 (file)
@@ -101,16 +101,18 @@ int num_tokens(const char *source, char tok)
        return (count);
 }
 
+//extern void cit_backtrace(void);
+
 
 /*
  * extract_token() - a string tokenizer
  * returns -1 if not found, or length of token.
- * /
+ */
 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
 {
-       const char *s;                  /* source * /
-       int len = 0;                    /* running total length of extracted string * /
-       int current_token = 0;          /* token currently being processed * /
+       const char *s;                  //* source * /
+       int len = 0;                    //* running total length of extracted string * /
+       int current_token = 0;          //* token currently being processed * /
 
        s = source;
 
@@ -118,6 +120,8 @@ long extract_token(char *dest, const char *source, int parmnum, char separator,
                return(-1);
        }
 
+//     cit_backtrace();
+//     lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
        dest[0] = 0;
 
        if (s == NULL) {
@@ -128,7 +132,9 @@ long extract_token(char *dest, const char *source, int parmnum, char separator,
                if (*s == separator) {
                        ++current_token;
                }
-               if ( (current_token == parmnum) && (len < maxlen) ) {
+               if ( (current_token == parmnum) && 
+                    (*s != separator) && 
+                    (len < maxlen) ) {
                        dest[len] = *s;
                        ++len;
                }
@@ -138,28 +144,36 @@ long extract_token(char *dest, const char *source, int parmnum, char separator,
                ++s;
        }
 
-       dest[len] = 0;
-       if (current_token < parmnum) return(-1);
+       dest[len] = '\0';
+       if (current_token < parmnum) {
+//             lprintf (CTDL_DEBUG,"test <!: %s\n", dest);
+               return(-1);
+       }
+//     lprintf (CTDL_DEBUG,"test <: %d; %s\n", len, dest);
        return(len);
 }
-*/
+//*/
+
 
 /*
  * extract_token() - a string tokenizer
- */
+ * /
 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
 {
-       char *d;                /* dest */
-       const char *s;          /* source */
+       char *d;                //* dest * /
+       const char *s;          //* source * /
        int count = 0;
        int len = 0;
 
+       
+//     cit_backtrace();
+       lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
        strcpy(dest, "");
 
-       /* Locate desired parameter */
+       //* Locate desired parameter * /
        s = source;
        while (count < parmnum) {
-               /* End of string, bail! */
+               //* End of string, bail! * /
                if (!*s) {
                        s = NULL;
                        break;
@@ -169,15 +183,19 @@ long extract_token(char *dest, const char *source, int parmnum, char separator,
                }
                s++;
        }
-       if (!s) return -1;              /* Parameter not found */
-
+       if (!s) {
+               lprintf (CTDL_DEBUG,"test <!: %s\n", dest);
+               return -1;              //* Parameter not found * /
+       }
+       
        for (d = dest; *s && *s != separator && ++len<maxlen; s++, d++) {
                *d = *s;
        }
        *d = 0;
+       lprintf (CTDL_DEBUG,"test <: %d; %s\n", len, dest);
        return 0;
 }
-
+*/
 
 
 /*