Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set env tmate_num_clients on client join/leave #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions tmate-daemon-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ static void tmate_header(struct tmate_session *session,
tmate_set_env("tmate_ssh", ssh_conn_str);
free(ssh_conn_str);

tmate_set_env("tmate_num_clients", "0");

tmate_send_client_ready();
}

Expand Down
16 changes: 16 additions & 0 deletions tmate-websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,25 @@ void tmate_websocket_exec(struct tmate_session *session, const char *command)
pack(string, command);
}

int tmate_set_num_clients()
{
int num_clients = 0;
struct client *c;
TAILQ_FOREACH(c, &clients, entry) {
++num_clients;
}
char *num_clients_str;
xasprintf(&num_clients_str, "%d", num_clients);
tmate_set_env("tmate_num_clients", num_clients_str);
free(num_clients_str);
tmate_debug("tmate_num_clients: %d", num_clients);
}

void tmate_notify_client_join(__unused struct tmate_session *session,
struct client *c)
{
tmate_info("Client joined (cid=%d)", c->id);
tmate_set_num_clients();

if (!tmate_has_websocket())
return;
Expand All @@ -241,6 +256,7 @@ void tmate_notify_client_left(__unused struct tmate_session *session,
return;

tmate_info("Client left (cid=%d)", c->id);
tmate_set_num_clients();

if (!tmate_has_websocket())
return;
Expand Down