kfw fixes: ccapiserver only quits after all clients detach
authorTom Yu <tlyu@mit.edu>
Mon, 12 Dec 2011 20:46:00 +0000 (20:46 +0000)
committerTom Yu <tlyu@mit.edu>
Mon, 12 Dec 2011 20:46:00 +0000 (20:46 +0000)
Not sure if this is really a good idea or not...

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>
ticket: 7050

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

src/ccapi/server/ccs_server.c
src/ccapi/server/ccs_server.h
src/ccapi/server/win/ccs_os_server.cpp

index aeff7235ac4b8eee908624903a133988ae206aea..1fc8d2c5e37f282d47b87398624fb128475203a2 100644 (file)
@@ -399,3 +399,10 @@ cc_int32 ccs_server_send_reply (ccs_pipe_t     in_reply_pipe,
 
     return cci_check_error (err);
 }
+
+/* ------------------------------------------------------------------------ */
+
+cc_uint64 ccs_server_client_count ()
+{
+    return ccs_client_array_count (g_client_array);
+}
index 4d17099d014d71ec19673918a7ee5b61502a6b7f..e920ad9395dfee57f8079569d9c6f80564ad42ca 100644 (file)
@@ -48,4 +48,6 @@ cc_int32 ccs_server_send_reply (ccs_pipe_t     in_reply_pipe,
                                 cc_int32       in_reply_err,
                                 k5_ipc_stream   in_reply_data);
 
+cc_uint64 ccs_server_client_count ();
+
 #endif /* CCS_SERVER_H */
index 9a45e72c0c7c4cae7930fffb03ae81e90a1b833a..f84239491dac005a1ea5865a1f74cc3547535ee0 100644 (file)
@@ -199,7 +199,7 @@ cc_int32 ccs_os_server_listen_loop (int argc, const char *argv[]) {
 
     ParseOpts::Opts opts         = { 0 };
     ParseOpts       PO;
-    BOOL            bQuit = FALSE;
+    BOOL            bQuitIfNoClients = FALSE;
 
     opts.cMinCalls  = 1;
     opts.cMaxCalls  = 20;
@@ -231,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 (!bQuit) {
+    while (ccs_server_client_count() > 0 || !bQuitIfNoClients) {
         worklist_wait();
         while (!worklist_isEmpty()) {
             k5_ipc_stream    buf             = NULL;
@@ -244,10 +244,6 @@ 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",
@@ -290,6 +286,9 @@ cc_int32 ccs_os_server_listen_loop (int argc, const char *argv[]) {
                             err = krb5int_ipc_stream_write(stream, "This is a test of the emergency broadcasting system", 52);
                             err = ccs_os_server_send_reply(pipe, stream);
                             break;
+                        case CCMSG_QUIT:
+                            bQuitIfNoClients = TRUE;
+                            break;
                         default:
                             cci_debug_printf("Huh?  Received invalid message type %ld from UUID:<%s>",
                                 rpcmsg, uuid);