Exemplo n.º 1
0
void
tty_close(struct tty *tty)
{
	if (tty->log_fd != -1) {
		close(tty->log_fd);
		tty->log_fd = -1;
	}

	evtimer_del(&tty->key_timer);
	tty_stop_tty(tty);

	if (tty->flags & TTY_OPENED) {
		bufferevent_free(tty->event);

		tty_term_free(tty->term);
		tty_keys_free(tty);

		tty->flags &= ~TTY_OPENED;
	}

	if (tty->fd != -1) {
		close(tty->fd);
		tty->fd = -1;
	}
}
Exemplo n.º 2
0
int
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_target_data	*data = self->data;
	struct client		*c;

	if ((c = cmd_find_client(ctx, data->target)) == NULL)
		return (-1);

	tty_stop_tty(&c->tty);
	c->flags |= CLIENT_SUSPENDED;
	server_write_client(c, MSG_SUSPEND, NULL, 0);

	return (0);
}
Exemplo n.º 3
0
int
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
		return (-1);

	tty_stop_tty(&c->tty);
	c->flags |= CLIENT_SUSPENDED;
	server_write_client(c, MSG_SUSPEND, NULL, 0);

	return (0);
}
Exemplo n.º 4
0
enum cmd_retval
cmd_suspend_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
		return (CMD_RETURN_ERROR);

	tty_stop_tty(&c->tty);
	c->flags |= CLIENT_SUSPENDED;
	server_write_client(c, MSG_SUSPEND, NULL, 0);

	return (CMD_RETURN_NORMAL);
}
Exemplo n.º 5
0
void
tty_close(struct tty *tty, int no_stop)
{
	if (tty->fd == -1)
		return;

	if (tty->log_fd != -1) {
		close(tty->log_fd);
		tty->log_fd = -1;
	}

	if (!no_stop)
		tty_stop_tty(tty);

	tty_term_free(tty->term);
	tty_keys_free(tty);

	close(tty->fd);
	tty->fd = -1;

	buffer_destroy(tty->in);
	buffer_destroy(tty->out);
}
Exemplo n.º 6
0
enum cmd_retval
cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args	*args = self->args;
	struct client	*c, *cloop;
	struct session	*s;
	enum msgtype	 msgtype;
	u_int 		 i;

	if (self->entry == &cmd_suspend_client_entry) {
		if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
			return (CMD_RETURN_ERROR);
		tty_stop_tty(&c->tty);
		c->flags |= CLIENT_SUSPENDED;
		server_write_client(c, MSG_SUSPEND, NULL, 0);
		return (CMD_RETURN_NORMAL);
	}

	if (args_has(args, 'P'))
		msgtype = MSG_DETACHKILL;
	else
		msgtype = MSG_DETACH;

	if (args_has(args, 's')) {
		s = cmd_find_session(cmdq, args_get(args, 's'), 0);
		if (s == NULL)
			return (CMD_RETURN_ERROR);

		for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
			cloop = ARRAY_ITEM(&clients, i);
			if (cloop == NULL || cloop->session != s)
				continue;
			server_write_client(cloop, msgtype,
			    cloop->session->name,
			    strlen(cloop->session->name) + 1);
		}
		return (CMD_RETURN_STOP);
	}

	c = cmd_find_client(cmdq, args_get(args, 't'), 0);
	if (c == NULL)
		return (CMD_RETURN_ERROR);

	if (args_has(args, 'a')) {
		for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
			cloop = ARRAY_ITEM(&clients, i);
			if (cloop == NULL || cloop->session == NULL)
				continue;
			if (cloop == c)
				continue;
			server_write_client(cloop, msgtype,
			    cloop->session->name,
			    strlen(cloop->session->name) + 1);
		}
		return (CMD_RETURN_NORMAL);
	}

	server_write_client(c, msgtype, c->session->name,
	    strlen(c->session->name) + 1);
	return (CMD_RETURN_STOP);
}