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

debugging.
pull/777/head
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);
}
}

View File

@ -562,13 +562,9 @@ status_print(struct client *c, struct winlink *wl, time_t t,
void
status_message_set(struct client *c, const char *fmt, ...)
{
struct timeval tv;
struct message_entry *msg, *msg1;
va_list ap;
int delay;
u_int limit;
limit = options_get_number(global_options, "message-limit");
struct timeval tv;
va_list ap;
int delay;
status_message_clear(c);
@ -576,19 +572,7 @@ status_message_set(struct client *c, const char *fmt, ...)
xvasprintf(&c->message_string, fmt, ap);
va_end(ap);
msg = xcalloc(1, sizeof *msg);
msg->msg_time = time(NULL);
msg->msg_num = c->message_next++;
msg->msg = xstrdup(c->message_string);
TAILQ_INSERT_TAIL(&c->message_log, msg, entry);
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);
}
server_client_add_message(c, "%s", c->message_string);
delay = options_get_number(c->session->options, "display-time");
if (delay > 0) {

2
tmux.h
View File

@ -1828,6 +1828,8 @@ void server_client_exec(struct client *, const char *);
void server_client_loop(void);
void server_client_push_stdout(struct client *);
void server_client_push_stderr(struct client *);
void printflike(2, 3) server_client_add_message(struct client *, const char *,
...);
/* server-fn.c */
void server_fill_environ(struct session *, struct environ *);