console.c revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER START
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The contents of this file are subject to the terms of the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Common Development and Distribution License (the "License").
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You may not use this file except in compliance with the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * See the License for the specific language governing permissions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * and limitations under the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * When distributing Covered Code, include this CDDL HEADER in each
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * If applicable, add the following below this CDDL HEADER, with the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * fields enclosed by brackets "[]" replaced with your own identifying
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * information: Portions Copyright [yyyy] [name of copyright owner]
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER END
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Use is subject to license terms.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#pragma ident "%Z%%M% %I% %E% SMI"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Listen thread creates a console thread whenever there is a tcp client
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * made a conection to its port. In the console thread, if there are
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * multiple consoles in the group, client will be asked for a console selection.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * a write thread for a console is created when first client connects to a
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * selected console and console thread becomes read thread for the client.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* display domain names in the group */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) snprintf(buf, sizeof (buf), "%-20d%-30s%-25s%s",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo consp->cons_no, consp->domain_name, status, vntsd_eol);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (vntsd_write_fd(*fd, buf, strlen(buf)) != VNTSD_SUCCESS);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* output connected message to tcp client */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppowrite_connect_msg(vntsd_client_t *clientp, char *group_name,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, vntsd_eol, VNTSD_EOL_LEN)) !=
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo gettext("Connecting to console \"%s\" in group \"%s\" ...."),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, buf)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* create write thread for the console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (thr_create(NULL, 0, (thr_func_t)vntsd_write_thread,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "create write thread failed\n",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Display all domain consoles in a group. */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppolist_all_domains(vntsd_group_t *groupp, vntsd_client_t *clientp)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, vntsd_eol, VNTSD_EOL_LEN))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * TRANSLATION_NOTE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The following three strings of the form "DOMAIN .." are table
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * headers and should be all uppercase.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "%-20s%-30s%-25s",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, vntsd_line)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (vntsd_que_find(groupp->conspq, (compare_func_t)display_domain_name,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* display help */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, vntsd_eol, VNTSD_EOL_LEN))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * TRANSLATION_NOTE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The following three strings of the form ". -- ..." are help
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * messages for single character commands. Do not translate the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * character before the --.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, bufp)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, bufp)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, bufp)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * TRANSLATION_NOTE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * In the following string, "id" is a short mnemonic for
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * "identifier" and both occurrences should be translated.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo bufp = gettext("[c[c ]]{id} -- connect to console of domain {id}");
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, bufp)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* select a console to connect */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fhepposelect_cons(vntsd_group_t *groupp, int num_cons, vntsd_cons_t **consp,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* no console in this group */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* by pass selecting console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* {id} input */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo } else if (c == 'c') {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* c{id} or c {id} input */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo } else if (!isspace(c)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* get client selections */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_read_line(clientp, buf, &n)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* parse command */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (i = 0; i < n; i++) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* c{id} */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* skip space */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* c{id} or c {id} */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* get selected console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *consp = (vntsd_cons_t *)vntsd_que_find(groupp->conspq,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* during console selection, the console has been deleted */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* compare if there is a match console in the gorup */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppofind_cons_in_group(vntsd_cons_t *consp_in_group, vntsd_cons_t *consp)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* connect a client to a console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoconnect_cons(vntsd_cons_t *consp, vntsd_client_t *clientp)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* check if console is valid */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* enable daemon cmd */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* first connect to console - a writer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* open vcc */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo consp->vcc_fd = vntsd_open_vcc(consp->dev_name, consp->cons_no);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * move the client from group's no console selected queue
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * to cons queue
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo rv = vntsd_que_rm(&groupp->no_cons_clientpq, clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* writer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* create a write thread */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* write connecting message */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = write_connect_msg(clientp, consp->group->group_name,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* process input from client */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* client disconnected from the console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* remove client from console queue */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* append client to group's no console selected queue */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo rv1 = vntsd_que_append(&groupp->no_cons_clientpq, clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* clean up console since there is no client connected to it */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* close vcc port */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* force write thread to exit */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* console is waiting for client to disconnect */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* read command line input */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fhepporead_cmd(vntsd_client_t *clientp, char *prompt, char *cmd)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* disable daemon special command */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, vntsd_eol, VNTSD_EOL_LEN))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, prompt, strlen(prompt)))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_read_data(clientp, cmd)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* reset client for selecting a console in the group */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* clean up client and exit the thread */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoclient_fini(vntsd_group_t *groupp, vntsd_client_t *clientp)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* disconnct client from tcp port */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) vntsd_que_rm(&groupp->no_cons_clientpq, clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* group is waiting to be deleted */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* check client's status. exit if client quits or fatal errors */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoconsole_chk_status(vntsd_group_t *groupp, vntsd_client_t *clientp, int status)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "client status=%x num consoles=%d \n",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo thr_self(), status, clientp->status, groupp->num_cons);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) snprintf(err_msg, VNTSD_LINE_LEN, "console_chk_status client%d"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* no more console in the group */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* reason for signal? */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* no other selection available */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((clientp->status & VNTSD_CLIENT_CONS_DELETED) == 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* check if console was deleted */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* console was deleted */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* console is ok */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* same console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* get selected console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo clientp->cons = vntsd_que_pos(clientp->cons->group->conspq,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* fatal error */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* console thread */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* check if group is removed */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D1(stderr, "t@%d get_client_sel@%lld:client@%d\n", thr_self(),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* host name */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vntsd_log(VNTSD_STATUS_NO_HOST_NAME, "vntsd_console_thread()");
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "%s-vnts-%s: h,l,{id},c{id},c {id},q:",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* long prompt doesn't fit, use short one */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "vnts: h,l,{id},c{id},c {id}, q:");
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D1(stderr, "t@%d console_thread()@%lld:client@%d\n", thr_self(),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* console to connect to */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* check error and may exit */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch (cmd) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* list domain names */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* select console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* connect to console */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "connect_cons returns %d\n",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* check error and may exit */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /*NOTREACHED*/