]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
changes-to-allow-identifying-threads-in-log-file-output-20010404
authorHartmut Reuter <reuter@rzg.mpg.de>
Wed, 4 Apr 2001 18:21:53 +0000 (18:21 +0000)
committerDerrick Brashear <shadow@dementia.org>
Wed, 4 Apr 2001 18:21:53 +0000 (18:21 +0000)
"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
src/rx/rx_lwp.c
src/util/serverLog.c

index 7af02f374f0055c49bd2d0cb2587a8d8dc67bc06..313a98f0e2da4df8b9a12f3cbaca6795a43265fe 100644 (file)
@@ -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;
 }
 
index f54df1a66e9999e522ac6e790421908db1aa3f63..a5bfb4e61814ee2dd304dd789aabd83b2763023d 100644 (file)
@@ -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;
                        }
                    }
index b865f500f71f0e196e40f02b6665f6b3b20fd50b..0cce2793e1a756a722f12d1f7beb4d4fc0c043da 100644 (file)
@@ -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);
     }