Skip to content

Commit 7dd83b8

Browse files
committed
Call regular callback regardless of client input
Regular callback is called only if there's no input from the client during the regular interval. Fix by calling the callback when the interval expires, regardless of input from the client.
1 parent 0acad90 commit 7dd83b8

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

libcli.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ int cli_loop(struct cli_def *cli, int sockfd) {
11141114

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

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

1190+
if (cli->regular_callback) {
1191+
if (time(NULL) - cli->last_regular >= cli->timeout_tm.tv_sec) {
1192+
if (cli->regular_callback(cli) != CLI_OK) {
1193+
l = -1;
1194+
break;
1195+
}
1196+
time(&cli->last_regular);
1197+
}
1198+
}
1199+
11891200
if ((sr = cli_socket_wait(sockfd, &tm)) < 0) {
11901201
if (errno == EINTR) continue;
11911202
perror(CLI_SOCKET_WAIT_PERROR);
@@ -1194,12 +1205,6 @@ int cli_loop(struct cli_def *cli, int sockfd) {
11941205
}
11951206

11961207
if (sr == 0) {
1197-
// Timeout every second
1198-
if (cli->regular_callback && cli->regular_callback(cli) != CLI_OK) {
1199-
l = -1;
1200-
break;
1201-
}
1202-
12031208
if (cli->idle_timeout) {
12041209
if (time(NULL) - cli->last_action >= cli->idle_timeout) {
12051210
if (cli->idle_timeout_callback) {

libcli.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct cli_def {
7878
time_t idle_timeout;
7979
int (*idle_timeout_callback)(struct cli_def *);
8080
time_t last_action;
81+
time_t last_regular;
8182
int telnet_protocol;
8283
void *user_context;
8384
struct cli_optarg_pair *found_optargs;

0 commit comments

Comments
 (0)