]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: Use milliseconds in idle timeout
authorAki Tuomi <aki.tuomi@dovecot.fi>
Sat, 15 Oct 2016 10:59:45 +0000 (13:59 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Oct 2016 13:43:30 +0000 (16:43 +0300)
src/lib-program-client/program-client-local.c
src/lib-program-client/program-client-private.h
src/lib-program-client/program-client.c
src/lib-program-client/program-client.h
src/lib-program-client/test-program-client-local.c
src/lib-program-client/test-program-client-remote.c

index eaea8afccfea1b1f9d045db6d64a078d6196f469..8be206ab329c6d5eb34c528fa521bb8c0d9697e8 100644 (file)
@@ -11,7 +11,7 @@
 #include "ostream.h"
 #include "restrict-access.h"
 #include "child-wait.h"
-
+#include "time-util.h"
 #include "program-client-private.h"
 
 #include <sys/types.h>
@@ -365,9 +365,9 @@ void program_client_local_kill(struct program_client_local *slclient)
 
                /* Timed out again */
                if (slclient->client.debug) {
-                       i_debug("program `%s' (%d) did not die after %d seconds: "
+                       i_debug("program `%s' (%d) did not die after %d milliseconds: "
                                "sending KILL signal",
-                               slclient->client.path, slclient->pid, KILL_TIMEOUT / 1000);
+                               slclient->client.path, slclient->pid, KILL_TIMEOUT);
                }
 
                /* Kill it brutally now, it should die right away */
@@ -383,9 +383,9 @@ void program_client_local_kill(struct program_client_local *slclient)
        }
 
        if (slclient->client.debug)
-               i_debug("program `%s'(%d) execution timed out after %llu seconds: "
+               i_debug("program `%s'(%d) execution timed out after %u milliseconds: "
                        "sending TERM signal", slclient->client.path, slclient->pid,
-                       (unsigned long long int)slclient->client.set.input_idle_timeout_secs);
+                       slclient->client.set.input_idle_timeout_msecs);
 
        /* send sigterm, keep on waiting */
        slclient->sent_term = TRUE;
@@ -411,7 +411,7 @@ void program_client_local_disconnect(struct program_client *pclient, bool force)
        struct program_client_local *slclient =
                (struct program_client_local *) pclient;
        pid_t pid = slclient->pid;
-       time_t runtime, timeout = 0;
+       unsigned long runtime, timeout = 0;
 
        if (slclient->exited) {
                program_client_local_exited(slclient);
@@ -435,23 +435,23 @@ void program_client_local_disconnect(struct program_client *pclient, bool force)
        }
 
        /* Calculate timeout */
-       runtime = ioloop_time - pclient->start_time;
-       if (!force && pclient->set.input_idle_timeout_secs > 0 &&
-           runtime < (time_t) pclient->set.input_idle_timeout_secs)
-               timeout = pclient->set.input_idle_timeout_secs - runtime;
+       runtime = timeval_diff_msecs(&ioloop_timeval, &pclient->start_time);
+       if (!force && pclient->set.input_idle_timeout_msecs > 0 &&
+           runtime < pclient->set.input_idle_timeout_msecs)
+               timeout = pclient->set.input_idle_timeout_msecs - runtime;
 
        if (pclient->debug) {
-               i_debug("waiting for program `%s' to finish after %llu seconds",
-                       pclient->path, (unsigned long long int) runtime);
+               i_debug("waiting for program `%s' to finish after %lu msecs",
+                       pclient->path, runtime);
        }
 
        force = force ||
-               (timeout == 0 && pclient->set.input_idle_timeout_secs > 0);
+               (timeout == 0 && pclient->set.input_idle_timeout_msecs > 0);
 
        if (!force) {
                if (timeout > 0)
                        slclient->to_kill =
-                               timeout_add_short(timeout * 1000,
+                               timeout_add_short(timeout,
                                                  program_client_local_kill,
                                                  slclient);
        } else {
index b18647c98195050f69c2b5e10ea71256dac10318..5f78acf8dce1f5476158367ebbef26e4c6654c72 100644 (file)
@@ -36,7 +36,7 @@ struct program_client {
        int fd_in, fd_out;
        struct io *io;
        struct timeout *to;
-       time_t start_time;
+       struct timeval start_time;
 
        struct istream *input, *program_input, *seekable_output;
        struct ostream *output, *program_output;
index f62de0778ea2de47e1af7617b0e7a6eafcf6362d..96c74b76e397159d4e100ee04310051cc659fefc 100644 (file)
@@ -56,15 +56,15 @@ int program_client_seekable_fd_callback(const char **path_r, void *context)
 static
 void program_client_timeout(struct program_client *pclient)
 {
-       i_error("program `%s' execution timed out (> %secs)",
-               pclient->path, pclient->set.input_idle_timeout_secs);
+       i_error("program `%s' execution timed out (> %u msecs)",
+               pclient->path, pclient->set.input_idle_timeout_msecs);
        program_client_fail(pclient, PROGRAM_CLIENT_ERROR_RUN_TIMEOUT);
 }
 
 static
 void program_client_connect_timeout(struct program_client *pclient)
 {
-       i_error("program `%s' socket connection timed out (> %d msecs)",
+       i_error("program `%s' socket connection timed out (> %u msecs)",
                pclient->path, pclient->set.client_connect_timeout_msecs);
        program_client_fail(pclient, PROGRAM_CLIENT_ERROR_CONNECT_TIMEOUT);
 }
@@ -369,13 +369,13 @@ int program_client_connected(struct program_client *pclient)
 {
        int ret = 1;
 
-       pclient->start_time = ioloop_time;
+       pclient->start_time = ioloop_timeval;
        if (pclient->to != NULL)
                timeout_remove(&pclient->to);
-       if (pclient->set.input_idle_timeout_secs != 0) {
+       if (pclient->set.input_idle_timeout_msecs != 0) {
                pclient->to =
-                       timeout_add(pclient->set.input_idle_timeout_secs *
-                                   1000, program_client_timeout, pclient);
+                       timeout_add(pclient->set.input_idle_timeout_msecs,
+                                   program_client_timeout, pclient);
        }
 
        /* run output */
index cd21faca5863fd7e92851e8f93cc60e9355014ec..1067fe0288271ec422d205e0cecb364511b70c61 100644 (file)
@@ -10,7 +10,7 @@ struct program_client;
 
 struct program_client_settings {
        unsigned int client_connect_timeout_msecs;
-       unsigned int input_idle_timeout_secs;
+       unsigned int input_idle_timeout_msecs;
        /* initialize with
           restrict_access_init(&set.restrict_set);
        */
index 474cb5aa53acd949dc8173785557090bee39ccbb..d83aae7386483abbc652ce4837d619d7044c200c 100644 (file)
@@ -22,7 +22,7 @@ static const char *pclient_test_io_string = "Lorem ipsum dolor sit amet, consect
 static
 struct program_client_settings pc_set = {
        .client_connect_timeout_msecs = 5000,
-       .input_idle_timeout_secs = 1000,
+       .input_idle_timeout_msecs = 1000,
        .debug = FALSE,
        .restrict_set = {
                .uid = (uid_t)-1,
index d897abbd0a2e48ab5d20493d0cf6c58b51f717a9..1f9a6b1c79c95d7045c398ad28b1dea5456f9911 100644 (file)
@@ -29,7 +29,7 @@ static const char *pclient_test_io_string = "Lorem ipsum dolor sit amet, consect
 static
 struct program_client_settings pc_set = {
        .client_connect_timeout_msecs = 1000,
-       .input_idle_timeout_secs = 5000,
+       .input_idle_timeout_msecs = 5000,
        .debug = TRUE,
 };