/*
* 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
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Each group has a listen thread. It is created at the time
* of a group creation and destroyed when a group does not have
* any console associated with it.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <thread.h>
#include <assert.h>
#include <signal.h>
#include <ctype.h>
#include <syslog.h>
#include "vntsd.h"
/*
* check the state of listen thread. exit if there is an fatal error
* or the group is removed. Main thread will call free_group
* to close group socket and free group structure.
*/
static void
{
"Group:%s TCP port %lld status %x",
switch (status) {
case VNTSD_SUCCESS:
return;
case VNTSD_STATUS_ACCEPT_ERR:
return;
case VNTSD_STATUS_INTR:
/*FALLTHRU*/
case VNTSD_STATUS_NO_CONS:
default:
/* fatal error or no console in the group, remove the group. */
/*
* group is already being deleted, notify main
* thread and exit.
*/
thr_exit(0);
}
/*
* if there still is console(s) in the group,
* the console(s) could not be connected any more because of
* a fatal error. Therefore, mark the console and notify
* main thread to delete console and group.
*/
/* signal main thread to delete the group */
/* log error */
if (status != VNTSD_STATUS_NO_CONS)
thr_exit(0);
}
}
/* allocate and initialize listening socket. */
static int
{
int on;
int retries = 0;
/* allocate a socket */
if (*sockfd < 0) {
return (VNTSD_STATUS_INTR);
}
return (VNTSD_ERR_LISTEN_SOCKET);
}
#ifdef DEBUG
/* set reuse local socket address */
on = 1;
return (VNTSD_ERR_LISTEN_OPTS);
}
#endif
/* bind socket */
for (; ; ) {
/*
* After a socket is closed, the port
* is transitioned to TIME_WAIT state.
* It may take a few retries to bind
* a just released port.
*/
sizeof (addr)) < 0) {
return (VNTSD_STATUS_INTR);
}
/* port may be in TIME_WAIT state, retry */
(void) sleep(5);
/* woke up by signal? */
return (VNTSD_STATUS_INTR);
}
retries++;
continue;
}
return (VNTSD_ERR_LISTEN_BIND);
}
break;
}
return (VNTSD_STATUS_INTR);
}
return (VNTSD_ERR_LISTEN_BIND);
}
return (VNTSD_SUCCESS);
}
/* ceate console selection thread */
static int
{
int rv;
/* allocate a new client */
return (VNTSD_ERR_NO_MEM);
}
/* initialize the client */
/* append client to group */
/* check if the group is [being] removed */
return (VNTSD_STATUS_NO_CONS);
}
!= VNTSD_SUCCESS) {
return (rv);
}
/*
* allocate thr_arg from heap for console thread so
* that thr_arg is still valid after this function exits.
* console thread will free thr_arg.
*/
return (VNTSD_ERR_NO_MEM);
}
/* create console selection thread */
return (VNTSD_ERR_CREATE_CONS_THR);
}
return (VNTSD_SUCCESS);
}
/* listen thread */
void *
{
int newsockfd;
int rv;
int num_cons;
/* initialize listen socket */
for (; ; ) {
/* listen to the socket */
&clilen);
if (newsockfd <= 0) {
} else {
}
continue;
}
/* Check authorization if enabled */
"authorization failure\n", thr_self(),
continue;
}
}
if (num_cons == 0) {
continue;
}
/* a connection is established */
if (rv != VNTSD_SUCCESS) {
}
if (rv != VNTSD_SUCCESS) {
}
}
/*NOTREACHED*/
return (NULL);
}