Break the message storage function into its own function, useful for

debugging.
This commit is contained in:
nicm
2017-02-09 12:09:33 +00:00
parent b7ddfb39f3
commit b1fa3e25e4
3 changed files with 37 additions and 20 deletions

View File

@ -1624,3 +1624,34 @@ server_client_push_stderr(struct client *c)
log_debug("%s: client %p, queued", __func__, c);
}
}
/* Add to client message log. */
void
server_client_add_message(struct client *c, const char *fmt, ...)
{
struct message_entry *msg, *msg1;
char *s;
va_list ap;
u_int limit;
va_start(ap, fmt);
xvasprintf(&s, fmt, ap);
va_end(ap);
log_debug("%s: message %s", c->tty.path, s);
msg = xcalloc(1, sizeof *msg);
msg->msg_time = time(NULL);
msg->msg_num = c->message_next++;
msg->msg = s;
TAILQ_INSERT_TAIL(&c->message_log, msg, entry);
limit = options_get_number(global_options, "message-limit");
TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) {
if (msg->msg_num + limit >= c->message_next)
break;
free(msg->msg);
TAILQ_REMOVE(&c->message_log, msg, entry);
free(msg);
}
}