From 496debf89657e8b2d09b60b8595d7046f494ad62 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 8 Jun 2010 21:28:42 +0000 Subject: [PATCH] * check for syscall.h * 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 | 2 +- citadel/modules/rssclient/serv_rssclient.c | 3 +-- citadel/modules/smtp/serv_smtp.c | 3 +-- citadel/sysdep.c | 12 +++++++++--- citadel/threads.c | 12 ++++++++---- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/citadel/configure.ac b/citadel/configure.ac index b35fdb69a..0398fcb18 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -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 diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index c69f6b4ad..39fdd7bb3 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -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 diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index 6bbe64718..7d1e26f49 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -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); diff --git a/citadel/sysdep.c b/citadel/sysdep.c index a935c410b..2625d615d 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -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; } diff --git a/citadel/threads.c b/citadel/threads.c index f6221019a..2f7475ff1 100644 --- a/citadel/threads.c +++ b/citadel/threads.c @@ -28,7 +28,11 @@ # include # endif #endif - +#ifdef HAVE_SYSCALL_H +#include +#else if HAVE_SYS_SYSCALL_H +#include +#endif #include #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++; -- 2.30.2