read.c revision 1f79c0b880fa5add6fffbf5debc7996dbef5c1a3
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* read thread - Read from tcp client and write to vcc driver. There are one
* writer and multiple readers per console. The first client who connects to
* a console get write access. An error message is returned to readers if they
* attemp to input commands. Read thread accepts special daemon commands from
* all clients.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <thread.h>
#include <synch.h>
#include <signal.h>
#include <assert.h>
#include <ctype.h>
#include <syslog.h>
#include <libintl.h>
#include "vntsd.h"
#include "chars.h"
/* write_vcc() - write to vcc virtual console */
static int
{
int n;
if (n < 0) {
/* write error */
return (vntsd_cons_chk_intr(clientp));
}
return (VNTSD_STATUS_VCC_IO_ERR);
}
assert(n != 0);
return (VNTSD_SUCCESS);
}
/*
* acquire_writer() the client is going to be writer.
* insert the client to the head of the console client queue.
*/
static int
{
int rv;
/* clientp is a writer already */
return (VNTSD_SUCCESS);
}
/* current writer */
/* move client to be first in the console queue */
/* move previous writer to be the second in the queue */
if (rv != VNTSD_SUCCESS) {
return (rv);
}
/* write warning message to the writer */
gettext("Warning: Console connection forced into read-only mode")))
!= VNTSD_SUCCESS) {
return (rv);
}
return (VNTSD_SUCCESS);
}
/* interrupt handler */
int
{
return (VNTSD_STATUS_CLIENT_QUIT);
}
return (VNTSD_STATUS_RESELECT_CONS);
}
return (VNTSD_STATUS_CLIENT_QUIT);
}
return (VNTSD_STATUS_CONTINUE);
}
/* read from client */
static int
{
int rv;
for (; ; ) {
switch (rv) {
if (rv != VNTSD_SUCCESS) {
return (rv);
}
break;
case VNTSD_SUCCESS:
/*
* Based on telnet protocol, when an <eol> is entered,
* vntsd receives <0x0d,0x00>. However, console expects
* <0xd> only. We need to filter out <0x00>.
*/
break;
}
return (rv);
default:
return (rv);
}
}
}
/* vntsd_read worker */
int
{
char c;
int rv;
for (; ; ) {
/* client input */
if (rv == VNTSD_STATUS_INTR) {
}
if (rv != VNTSD_SUCCESS) {
return (rv);
}
/*
* Only keyboard inputs from first connection to a
* guest console should be accepted. Check to see if
* this client is the first connection in console
* queue
*/
/*
* Since this console connection is not the first
* connection in the console queue,
* it is operating in 'reader'
* mode, print warning and ignore the input.
*/
/* check errors and interrupts */
if (rv == VNTSD_STATUS_INTR) {
}
if (rv != VNTSD_SUCCESS) {
return (rv);
}
continue;
}
switch (rv) {
case VNTSD_STATUS_CONTINUE:
continue;
break;
case VNTSD_STATUS_INTR:
if (rv != VNTSD_SUCCESS) {
return (rv);
}
break;
case VNTSD_SUCCESS:
break;
default:
return (rv);
}
/* write to vcc */
if (rv == VNTSD_STATUS_INTR) {
}
if (rv != VNTSD_SUCCESS) {
return (rv);
}
}
/*NOTREACHED*/
return (NULL);
}