Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions libcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ int cli_loop(struct cli_def *cli, int sockfd) {

// Set the last action now so we don't time immediately
if (cli->idle_timeout) time(&cli->last_action);
if (cli->regular_callback) time(&cli->last_regular);

// Start off in unprivileged mode
cli_set_privilege(cli, PRIVILEGE_UNPRIVILEGED);
Expand Down Expand Up @@ -1186,6 +1187,16 @@ int cli_loop(struct cli_def *cli, int sockfd) {
cli->showprompt = 0;
}

if (cli->regular_callback) {
if (time(NULL) - cli->last_regular >= cli->timeout_tm.tv_sec) {
if (cli->regular_callback(cli) != CLI_OK) {
l = -1;
break;
}
time(&cli->last_regular);
}
}

if ((sr = cli_socket_wait(sockfd, &tm)) < 0) {
if (errno == EINTR) continue;
perror(CLI_SOCKET_WAIT_PERROR);
Expand All @@ -1194,12 +1205,6 @@ int cli_loop(struct cli_def *cli, int sockfd) {
}

if (sr == 0) {
// Timeout every second
if (cli->regular_callback && cli->regular_callback(cli) != CLI_OK) {
l = -1;
break;
}

if (cli->idle_timeout) {
if (time(NULL) - cli->last_action >= cli->idle_timeout) {
if (cli->idle_timeout_callback) {
Expand Down
1 change: 1 addition & 0 deletions libcli.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct cli_def {
time_t idle_timeout;
int (*idle_timeout_callback)(struct cli_def *);
time_t last_action;
time_t last_regular;
int telnet_protocol;
void *user_context;
struct cli_optarg_pair *found_optargs;
Expand Down