Changeset: 71afbb0f091d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=71afbb0f091d
Modified Files:
        tools/merovingian/daemon/argvcmds.c
        tools/merovingian/daemon/controlrunner.c
        tools/merovingian/daemon/discoveryrunner.c
Branch: Jun2016
Log Message:

Exit quicker when stopped, and wait for it.
monetdbd stop XXX sends a signal to another, running monetdbd.  This
latter one should stop more quickly, and the former should wait for
the latter to stop.


diffs (74 lines):

diff --git a/tools/merovingian/daemon/argvcmds.c 
b/tools/merovingian/daemon/argvcmds.c
--- a/tools/merovingian/daemon/argvcmds.c
+++ b/tools/merovingian/daemon/argvcmds.c
@@ -448,6 +448,8 @@ command_stop(confkeyval *ckv, int argc, 
        FILE *pfile = NULL;
        char buf[8];
        pid_t daemon;
+       struct timeval tv;
+       int i;
 
        if (argc != 2) {
                command_help(2, &argv[-1]);
@@ -499,5 +501,14 @@ command_stop(confkeyval *ckv, int argc, 
                return(1);
        }
 
+       /* wait up to 5 seconds for monetdbd to actually stop */
+       for (i = 0; i < 10; i++) {
+               tv.tv_sec = 0;
+               tv.tv_usec = 500;
+               select(0, NULL, NULL, NULL, &tv);
+               if (kill(daemon, 0) == -1)
+                       break;
+       }
+
        return(0);
 }
diff --git a/tools/merovingian/daemon/controlrunner.c 
b/tools/merovingian/daemon/controlrunner.c
--- a/tools/merovingian/daemon/controlrunner.c
+++ b/tools/merovingian/daemon/controlrunner.c
@@ -962,7 +962,7 @@ controlRunner(void *d)
                FD_SET(usock, &fds);
 
                /* Wait up to 5 seconds. */
-               tv.tv_sec = 5;
+               tv.tv_sec = 1;
                tv.tv_usec = 0;
                retval = select(usock + 1, &fds, NULL, NULL, &tv);
                if (retval == 0) {
diff --git a/tools/merovingian/daemon/discoveryrunner.c 
b/tools/merovingian/daemon/discoveryrunner.c
--- a/tools/merovingian/daemon/discoveryrunner.c
+++ b/tools/merovingian/daemon/discoveryrunner.c
@@ -392,12 +392,18 @@ discoveryRunner(void *d)
                pthread_mutex_unlock(&_mero_remotedb_lock);
 
                peer_addr_len = sizeof(struct sockaddr_storage);
-               FD_ZERO(&fds);
-               FD_SET(sock, &fds);
                /* Wait up to 5 seconds. */
-               tv.tv_sec = 5;
-               tv.tv_usec = 0;
-               nread = select(sock + 1, &fds, NULL, NULL, &tv);
+               for (s = 0; s < 5; s++) {
+                       FD_ZERO(&fds);
+                       FD_SET(sock, &fds);
+                       tv.tv_sec = 1;
+                       tv.tv_usec = 0;
+                       nread = select(sock + 1, &fds, NULL, NULL, &tv);
+                       if (nread != 0)
+                               break;
+                       if (!_mero_keep_listening)
+                               goto breakout;
+               }
                if (nread <= 0) {  /* assume only failure is EINTR */
                        /* nothing interesting has happened */
                        buf[0] = '\0';
@@ -493,6 +499,7 @@ discoveryRunner(void *d)
                                        "%s:%s: '%s'\n", host, service, buf);
                }
        }
+  breakout:
 
        /* now notify of our soon to be absence ;) */
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to