Make ccapiserver exit if its receiveloop thread terminates for any reason
authorTom Yu <tlyu@mit.edu>
Mon, 12 Dec 2011 20:44:30 +0000 (20:44 +0000)
committerTom Yu <tlyu@mit.edu>
Mon, 12 Dec 2011 20:44:30 +0000 (20:44 +0000)
This happens, for example, when the rpc endpoint is already registered
by another ccapiserver process.  There's no reason to leave a zombie
process running that can't receive messages.

ticket: 7050

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25540 dc483132-0cff-0310-8789-dd5450dbe970

src/ccapi/common/win/win-utils.h
src/ccapi/server/win/ccs_os_server.cpp

index 6469a61e8b88ea5dc0cb17afd991275d62060a27..41cab24dcdffae9f0dd07181214de1ed0ba68881 100644 (file)
@@ -42,7 +42,8 @@ static enum ccapiMsgType {
     CCMSG_REQUEST_REPLY,
     CCMSG_DISCONNECT,
     CCMSG_LISTEN,
-    CCMSG_PING
+    CCMSG_PING,
+    CCMSG_QUIT
     };
 
 char*                   clientEndpoint(const char* UUID);
index 811090ba5164b66ad70440b2f36fdbc9b7ab4e58..9a45e72c0c7c4cae7930fffb03ae81e90a1b833a 100644 (file)
@@ -199,6 +199,7 @@ cc_int32 ccs_os_server_listen_loop (int argc, const char *argv[]) {
 
     ParseOpts::Opts opts         = { 0 };
     ParseOpts       PO;
+    BOOL            bQuit = FALSE;
 
     opts.cMinCalls  = 1;
     opts.cMaxCalls  = 20;
@@ -230,7 +231,7 @@ cc_int32 ccs_os_server_listen_loop (int argc, const char *argv[]) {
     threadStatus    = _beginthread(receiveLoop, 0, (void*)&rpcargs);
 
     /* We handle the queue entries here.  Work loop: */
-    while (TRUE) {
+    while (!bQuit) {
         worklist_wait();
         while (!worklist_isEmpty()) {
             k5_ipc_stream    buf             = NULL;
@@ -243,6 +244,10 @@ cc_int32 ccs_os_server_listen_loop (int argc, const char *argv[]) {
             ccs_pipe_t     pipe2            = NULL;
 
             if (worklist_remove(&rpcmsg, &pipe, &buf, &serverStartTime)) {
+                if (rpcmsg == CCMSG_QUIT) {
+                    bQuit = TRUE;
+                    break;
+                    }
                 uuid = ccs_win_pipe_getUuid(pipe);
 #if 0
                 cci_debug_printf("%s: processing WorkItem msg:%ld pipeUUID:<%s> pipeHandle:0x%X SST:%ld",
@@ -462,6 +467,8 @@ void    receiveLoop(void* rpcargs) {
             free_alloc_p(&endpoint);
         }
 
+    // tell main thread to shutdown since it won't receive any more messages
+    worklist_add(CCMSG_QUIT, NULL, NULL, 0);
     _endthread();
     }   // End receiveLoop