* check for syscall.h
authorWilfried Göesgens <willi@citadel.org>
Tue, 8 Jun 2010 21:28:42 +0000 (21:28 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 8 Jun 2010 21:28:42 +0000 (21:28 +0000)
* use SYS_gettid to retrieve our LWPID when running in linux; this way we can find out whats loading top
* don't use masterCC's logbuffer

citadel/configure.ac
citadel/modules/rssclient/serv_rssclient.c
citadel/modules/smtp/serv_smtp.c
citadel/sysdep.c
citadel/threads.c

index b35fdb69a75b60a1afdfca3bfb1f6716360b62f7..0398fcb18f4f99c9fa1073aa1729bd257d6acbb5 100644 (file)
@@ -796,7 +796,7 @@ dnl
 dnl TODO: for the DB header checks, we should check whether the headers
 dnl define db_env_create, somehow
 dnl
-AC_CHECK_HEADERS(curses.h dl.h fcntl.h limits.h malloc.h termios.h sys/ioctl.h sys/select.h sys/stat.h sys/time.h sys/prctl.h syslog.h unistd.h utmp.h utmpx.h paths.h db.h db4/db.h pthread.h netinet/in.h arpa/nameser.h arpa/nameser_compat.h)
+AC_CHECK_HEADERS(curses.h dl.h fcntl.h limits.h malloc.h termios.h sys/ioctl.h sys/select.h sys/stat.h sys/time.h sys/prctl.h syslog.h unistd.h utmp.h utmpx.h paths.h db.h db4/db.h pthread.h netinet/in.h arpa/nameser.h arpa/nameser_compat.h syscall.h sys/syscall.h)
 
 dnl
 dnl need to check if this is actually compilable, sometimes there are
index c69f6b4ad44f36340033c1b7e1c97480780335bb..39fdd7bb39d91d1436f1c332e8ed3f4a13757d68 100644 (file)
@@ -292,6 +292,7 @@ void rss_save_item(rsscollection *rssc) {
        recp = (struct recptypes *) malloc(sizeof(struct recptypes));
        if (recp == NULL) return;
        memset(recp, 0, sizeof(struct recptypes));
+       memset(&ut, 0, sizeof(struct UseTable));
        recp->recp_room = strdup(ri->roomlist);
        recp->num_room = num_tokens(ri->roomlist, '|');
        recp->recptypes_magic = RECPTYPES_MAGIC;
@@ -873,8 +874,6 @@ void *rssclient_scan(void *args) {
        CtdlFillSystemContext(&rssclientCC, "rssclient");
        citthread_setspecific(MyConKey, (void *)&rssclientCC );
 
-       CtdlThreadAllocTSD();
-
        /*
         * This is a simple concurrency check to make sure only one rssclient run
         * is done at a time.  We could do this with a mutex, but since we
index 6bbe6471889c84e42f71f78d084602f0f8f049da..7d1e26f49df302ed3d87319bdf61b491c9202e58 100644 (file)
@@ -1743,9 +1743,8 @@ void *smtp_do_queue(void *arg) {
        struct CitContext smtp_queue_CC;
 
        CtdlFillSystemContext(&smtp_queue_CC, "SMTP Send");
-       CtdlLogPrintf(CTDL_INFO, "SMTP client: processing outbound queue\n");
-
        citthread_setspecific(MyConKey, (void *)&smtp_queue_CC );
+       CtdlLogPrintf(CTDL_INFO, "SMTP client: processing outbound queue\n");
 
        if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
                CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
index a935c410b00cb38125697616b80fa8fc21467ab9..2625d615d2fd5ab38c9a6beaae2ec53084a53d29 100644 (file)
@@ -130,7 +130,7 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                        node = cTSD->self;
                if ((node != NULL) && (node->reltid != 0))
                {
-                       lwpid = node->pid + node->reltid;
+                       lwpid = node->reltid;
                }
 
                gettimeofday(&tv, NULL);
@@ -138,7 +138,7 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                unixtime = tv.tv_sec;
                localtime_r(&unixtime, &tim);
 
-               if (CCC != NULL)
+               if ((CCC != NULL) && (CCC != &masterCC))
                        lBuf = CCC->lBuf;
                else 
                        lBuf = NewStrBuf();
@@ -161,7 +161,7 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                        }
                        vsnprintf(buf2, SIZ, format, arg_ptr);   
 
-                       fprintf(stderr, "%s%s", buf, buf2);
+                       fprintf(stderr, ":%s%s", buf, buf2);
                }
                else {
                        StrBufPrintf(lBuf,
@@ -1362,6 +1362,10 @@ void *select_on_master (void *arg)
        int m;
        int i;
        int retval;
+       struct CitContext select_on_master_CC;
+
+       CtdlFillSystemContext(&select_on_master_CC, "select_on_master");
+       citthread_setspecific(MyConKey, (void *)&select_on_master_CC);
 
        while (!CtdlThreadCheckStop()) {
                /* Initialize the fdset. */
@@ -1465,6 +1469,8 @@ void *select_on_master (void *arg)
                        }
                }
        }
+       CtdlClearSystemContext();
+
        return NULL;
 }
 
index f6221019a9e95377935d181d87defa955ad85150..2f7475ff12129741d78f582b71e1ea5a1a5e19f2 100644 (file)
 #  include <time.h>
 # endif
 #endif
-
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h> 
+#else if HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
 #include <libcitadel.h>
 
 #include "threads.h"
@@ -58,7 +62,6 @@
  * remove the need for the calls to eCrashRegisterThread and friends
  */
 
-static int next_tid = 3;                        /* offset LWPID to PID */
 static int num_threads = 0;                    /* Current number of threads */
 static int num_workers = 0;                    /* Current number of worker threads */
 long statcount = 0;            /* are we doing a stats check? */
@@ -840,6 +843,9 @@ static void *ctdl_internal_thread_func (void *arg)
        #endif
        
        // Tell the world we are here
+#ifdef HAVE_SYSCALL_H
+       this_thread->reltid = syscall(SYS_gettid);
+#endif
        CtdlLogPrintf(CTDL_NOTICE, "Created a new thread \"%s\" (0x%08lx).\n",
                this_thread->name, this_thread->tid);
        
@@ -990,8 +996,6 @@ CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thre
                free(this_thread);
                return NULL;
        }
-       this_thread->reltid = next_tid;
-       next_tid++;
        num_threads++;  // Increase the count of threads in the system.
        if(this_thread->flags & CTDLTHREAD_WORKER)
                num_workers++;