Skip to content

Commit

Permalink
lib-program-client: Use milliseconds in idle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse committed Oct 19, 2016
1 parent 6d1ea52 commit c1b5185
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions src/lib-program-client/program-client-local.c
Expand Up @@ -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>
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib-program-client/program-client-private.h
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/lib-program-client/program-client.c
Expand Up @@ -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 (> %d 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);
}
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/lib-program-client/program-client.h
Expand Up @@ -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);
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib-program-client/test-program-client-local.c
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib-program-client/test-program-client-remote.c
Expand Up @@ -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,
};

Expand Down

0 comments on commit c1b5185

Please sign in to comment.