From 98b06ddaf2cc89dfce31809140dfc2e19b6a0b48 Mon Sep 17 00:00:00 2001 From: Hartmut Reuter Date: Wed, 4 Apr 2001 18:21:53 +0000 Subject: [PATCH] changes-to-allow-identifying-threads-in-log-file-output-20010404 "This is an addition for MR-AFS log files where the thread name is shown. rx switches the general server threads to listeners and vice versa. To have reasonable names the listener must get back his old name when converting himself to a server thread. To not bother other programs with unresolved references I do this with two function pointers which are initialized in the main() programs for MR-AFS." ==================== This delta was composed from multiple commits as part of the CVS->Git migration. The checkin message with each commit was inconsistent. The following are the additional commit messages. ==================== use function pointers here instead of threadname --- src/rx/rx.c | 26 ++++++++++++++++++++++++-- src/rx/rx_lwp.c | 26 +++++++++++++++++++++++--- src/util/serverLog.c | 4 ++-- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/rx/rx.c b/src/rx/rx.c index 7af02f374..313a98f0e 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -95,6 +95,9 @@ extern afs_int32 afs_termState; extern afs_uint32 LWP_ThreadId(); #endif /* RXDEBUG */ +int (*registerProgram)() = 0; +int (*swapNameProgram)() = 0; + #ifdef AFS_GLOBAL_RXLOCK_KERNEL struct rx_tq_debug { afs_int32 rxi_start_aborted; /* rxi_start awoke after rxi_Send in error. */ @@ -618,7 +621,7 @@ void rxi_StartServerProcs(nExistingProcs) void rx_StartServer(donateMe) { register struct rx_service *service; - register int i; + register int i, nProcs; SPLVAR; clock_NewTime(); @@ -652,7 +655,26 @@ void rx_StartServer(donateMe) AFS_RXGUNLOCK(); USERPRI; - if (donateMe) rx_ServerProc(); /* Never returns */ + if (donateMe) { +#ifndef AFS_NT40_ENV +#ifndef KERNEL + int code; + char name[32]; +#ifdef AFS_PTHREAD_ENV + pid_t pid; + pid = pthread_self(); +#else /* AFS_PTHREAD_ENV */ + PROCESS pid; + code = LWP_CurrentProcess(&pid); +#endif /* AFS_PTHREAD_ENV */ + + sprintf(name,"srv_%d", ++nProcs); + if (registerProgram) + (*registerProgram)(pid, name); +#endif /* KERNEL */ +#endif /* AFS_NT40_ENV */ + rx_ServerProc(); /* Never returns */ + } return; } diff --git a/src/rx/rx_lwp.c b/src/rx/rx_lwp.c index f54df1a66..a5bfb4e61 100644 --- a/src/rx/rx_lwp.c +++ b/src/rx/rx_lwp.c @@ -36,6 +36,9 @@ #define MAXTHREADNAMELENGTH 64 +extern int (*registerProgram)(); +extern int (*swapNameProgram)(); + int debugSelectFailure; /* # of times select failed */ /* * Sleep on the unique wait channel provided. @@ -54,8 +57,8 @@ void rxi_Wakeup(void *addr) LWP_NoYieldSignal(addr); } -PROCESS rx_listenerPid; /* LWP process id of socket listener process */ -static void rx_ListenerProc(void *dummy); +PROCESS rx_listenerPid = 0; /* LWP process id of socket listener process */ +void rx_ListenerProc(void *dummy); /* * Delay the current thread the specified number of seconds. @@ -97,8 +100,14 @@ void rxi_StartServerProc(proc, stacksize) long (*proc)(); { PROCESS scratchPid; + static int number = 0; + char name[32]; + + sprintf(name, "srv_%d", ++number); LWP_CreateProcess(proc, stacksize, RX_PROCESS_PRIORITY, 0, "rx_ServerProc", &scratchPid); + if (registerProgram) + (*registerProgram)(scratchPid, name); } void rxi_StartListener() { @@ -106,6 +115,8 @@ void rxi_StartListener() { #define RX_LIST_STACK 24000 LWP_CreateProcess(rx_ListenerProc, RX_LIST_STACK, LWP_MAX_PRIORITY, 0, "rx_Listener", &rx_listenerPid); + if (registerProgram) + (*registerProgram)(rx_listenerPid, "listener"); } /* The main loop which listens to the net for datagrams, and handles timeouts @@ -151,7 +162,8 @@ void rxi_ListenerProc(rfds, tnop, newcallp) exit(1); } rx_listenerPid = pid; - swapthreadname(pid, "listener", &name); + if (swapNameProgram) + (*swapNameProgram)(pid, "listener", &name); for (;;) { /* Grab a new packet only if necessary (otherwise re-use the old one) */ @@ -245,6 +257,10 @@ void rxi_ListenerProc(rfds, tnop, newcallp) if (p) { rxi_FreePacket(p); } + if (swapNameProgram) { + (*swapNameProgram)(rx_listnerPid, &name, 0); + rx_listenerPid = 0; + } return; } } @@ -261,6 +277,10 @@ void rxi_ListenerProc(rfds, tnop, newcallp) if (p) { rxi_FreePacket(p); } + if (swapNameProgram) { + (*swapNameProgram)(rx_listenerPid, &name, 0); + rx_listenerPid = 0; + } return; } } diff --git a/src/util/serverLog.c b/src/util/serverLog.c index b865f500f..0cce2793e 100644 --- a/src/util/serverLog.c +++ b/src/util/serverLog.c @@ -61,7 +61,7 @@ static pthread_mutex_t serverLogMutex; #define F_OK 0 #endif -char *threadname(); +char *(*threadNameProgram)(); static int serverLogFD = -1; @@ -95,7 +95,7 @@ void FSLog (const char *format, ...) info = &timeStamp[25]; if (mrafsStyleLogs) { - name = threadname(); + name = (*threadNameProgram)(); sprintf(info, "[%s] ", name); info += strlen(info); } -- 2.39.5